Skip to content

Commit

Permalink
update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Hicks committed Apr 13, 2023
1 parent 7b55dc9 commit 79b588e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/views/funds/_fund_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<%= f.text_field :full_name %>
<%= f.text_field :site_domain %>
<%= f.text_field :phone,
pattern: "[0-9]{10}|[0-9]{3}\.[0-9]{3}\.[0-9]{4}|[0-9]{3}[-][0-9]{3}[-][0-9]{4}" %>
pattern: "[0-9]{10}|[0-9]{3}\-[0-9]{3}\-[0-9]{4}|[0-9]{3}[-][0-9]{3}[-][0-9]{4}" %>
<%= f.submit label, class: 'btn btn-primary btn-lg' %>
</div>

Expand Down
70 changes: 58 additions & 12 deletions test/controllers/funds_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
require "test_helper"

class FundsControllerTest < ActionDispatch::IntegrationTest
setup do
@fund = funds(:one)
before do
@user = create :user, role: :admin
sign_in @user
@fund = create :fund
end

# TODO: may need to use current_tenant
test "should show fund" do
get fund_url(@fund)
assert_response :success
describe 'show' do
it 'should render if admin' do
get fund_url(@fund)
assert_response :success
end

it 'should render json' do
get fund_url(@fund), xhr: true
assert_response :success
end
end

test "should get edit" do
get edit_fund_url(@fund)
assert_response :success
describe 'edit' do
it 'should redirect if not admin' do
User.roles.keys.reject { |role| role == 'admin' }.each do |role|
@user.update role: role
get edit_fund_url(@fund)
assert_redirected_to root_path
end
end

it 'should render' do
@user.update role: :admin
get edit_fund_url(@fund)
assert_response :success
end
end

test "should update fund" do
patch fund_url(@fund), params: { fund: { } }
assert_redirected_to fund_url(@fund)
describe 'update' do
before do
@phone = '555-555-5555'
@fund_attrs = { phone: @phone }
end

it 'should redirect if not admin' do
User.roles.keys.reject { |role| role == 'admin' }.each do |role|
@user.update role: role
patch fund_url(@fund), params: { fund: @fund_attrs }
assert_not_equal @phone, @fund.phone
assert_redirected_to root_path
end
end

it 'should update the fund record' do
patch fund_url(@fund), params: { fund: @fund_attrs }
@fund.reload
assert_equal @phone, @fund.phone
assert_redirected_to fund_url(@fund)
end

it 'should not update the fund record if the payload is bad' do
@fund_attrs[:name] = nil

patch fund_url(@fund), params: { fund: @fund_attrs }
@fund.reload
assert_not_equal @phone, @fund.phone
assert_response :unprocessable_entity
end
end
end
45 changes: 16 additions & 29 deletions test/system/funds_test.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
require "application_system_test_case"
require 'application_system_test_case'

class FundsTest < ApplicationSystemTestCase
setup do
@fund = funds(:one)
before do
create :line
@user = create :user, role: :admin
log_in_as @user
@fund = Fund.first
end

test "visiting the index" do
visit funds_url
assert_selector "h1", text: "Funds"
end

test "should create fund" do
visit funds_url
click_on "New fund"

click_on "Create Fund"

assert_text "Fund was successfully created"
click_on "Back"
end

test "should update Fund" do
test 'visiting the fund' do
visit fund_url(@fund)
click_on "Edit this fund", match: :first

click_on "Update Fund"

assert_text "Fund was successfully updated"
click_on "Back"
puts @fund.as_json
assert_selector 'h1', text: @fund.name
end

test "should destroy Fund" do
test 'updating the fund' do
visit fund_url(@fund)
click_on "Destroy this fund", match: :first

assert_text "Fund was successfully destroyed"
click_on 'Edit', match: :first
fill_in 'Phone', with: '555-555-5555'
click_away_from_field
wait_for_ajax
click_on 'Save changes'
assert_text 'Successfully updated fund details.'
end
end

0 comments on commit 79b588e

Please sign in to comment.