Skip to content

Commit

Permalink
adds minimally functional page for assistant instructions (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
robacarp authored Jan 11, 2024
1 parent 273b00c commit f750820
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 8 deletions.
21 changes: 21 additions & 0 deletions app/controllers/assistants/instructions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Assistants::InstructionsController < ApplicationController
before_action :set_assistant

def edit
end

def update
@assistant.update!(assistant_params)
redirect_to @assistant, notice: "Instructions have been saved."
end

private

def set_assistant
@assistant = Assistant.find(params[:assistant_id])
end

def assistant_params
params.require(:assistant).permit(:instructions)
end
end
Empty file removed app/controllers/concerns/.keep
Empty file.
7 changes: 7 additions & 0 deletions app/views/assistants/instructions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Your assistant <%= @assistant.name %> has the following instructions:

<%= form_for @assistant, url: assistant_instructions_path(@assistant) do |f| %>
<%= f.text_area :instructions, rows: 10, class: "w-auto mx-20" %>
<br>
<%= f.submit "Update", class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" %>
<% end %>
3 changes: 0 additions & 3 deletions app/views/assistants/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<%= render @assistant %>

Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<%= content_for :head %>
</head>
<body>
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>
<%= yield %>
</body>
</html>
2 changes: 1 addition & 1 deletion app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2 class='text-3xl font-semibold text-black/90'>Welcome back</h2>
<%= form_with(url: login_path, method: :post, class: "flex flex-col space-y-4 w-80") do |f| %>
<%= f.email_field :email, id: "email", autofocus: true, placeholder: "Email address", class: "border border-gray-400 rounded text-black p-3"%>
<%= f.password_field :password, id: "email", autofocus: true, placeholder: "Password", class: "border border-gray-400 rounded text-black p-3"%>
<%= f.password_field :password, id: "password", autofocus: true, placeholder: "Password", class: "border border-gray-400 rounded text-black p-3"%>
<%= f.submit "Continue", class: 'bg-teal-600 hover:bg-teal-700 rounded-sm font-light text-white p-4 px-4 text-center' %>
<span class='text-sm text-center'>Don't have an account ? <a href="/register" class='text-teal-600'>Sign up</a></span>
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@

# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

plugin :solid_queue
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Rails.application.routes.draw do
resources :assistants
resources :assistants do
get :instructions, to: "assistants/instructions#edit"
patch :instructions, to: "assistants/instructions#update"
end

resources :conversations
resources :messages
resources :documents
Expand Down
10 changes: 10 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]

fixtures :all

def login_as(user, password = "secret")
visit login_path
fill_in "email", with: user.person.email
fill_in "password", with: password
click_on "Continue"
assert_text "Successfully logged in."
end
end
Empty file removed test/controllers/.keep
Empty file.
22 changes: 22 additions & 0 deletions test/controllers/assistants/instructions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "test_helper"

class Assistants::InstructionsControllerTest < ActionDispatch::IntegrationTest
setup do
@assistant = assistants(:samantha)
login_as assistants(:samantha).user
end

test "it shows the instructions" do
get assistant_instructions_url(@assistant)
assert_response :success
end

test "it updates the instructions" do
new_instructions = "New instructions"
patch assistant_instructions_url(@assistant), params: {assistant: {instructions: new_instructions }}
assert_redirected_to assistant_url(@assistant)

@assistant.reload
assert_equal new_instructions, @assistant.instructions
end
end
2 changes: 2 additions & 0 deletions test/fixtures/chats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chat_with_samantha:
user: keith
3 changes: 3 additions & 0 deletions test/fixtures/notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
note_from_samantha:
chat: chat_with_samantha
content: Hi, how are you?
Empty file removed test/models/.keep
Empty file.
7 changes: 6 additions & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserTest < ActiveSupport::TestCase
person = Person.new(email: "[email protected]", personable: user)
assert_raises(ActiveRecord::RecordInvalid) { person.save! }
end
j

test "should not save user without password confirmation" do
user = User.new(password: "password")
person = Person.new(email: "[email protected]", personable: user)
Expand All @@ -22,4 +22,9 @@ class UserTest < ActiveSupport::TestCase
person = Person.new(email: "[email protected]", personable: user)
assert person.save!
end

test "it can validate a password" do
user = users(:keith)
assert user.authenticate("secret")
end
end
17 changes: 17 additions & 0 deletions test/system/assistants/instructions_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "application_system_test_case"

class AssistantsInstructionsTest < ApplicationSystemTestCase
setup do
@assistant = assistants(:samantha)
end

test "should update Assistant" do
login_as @assistant.user
visit assistant_instructions_url(@assistant)

fill_in "assistant[instructions]", with: "Updated Instructions"
click_on "Update"

assert_text "Instructions have been saved."
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class ActionDispatch::IntegrationTest
def response
JSON.parse(@response.body, object_class: OpenStruct)&.data
end

def login_as(user)
post login_path, params: { email: user.person.email, password: "secret" }
assert_redirected_to dashboard_path
end
end

module ActiveSupport
Expand Down

0 comments on commit f750820

Please sign in to comment.