-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cameron Hicks
committed
Apr 13, 2023
1 parent
7b55dc9
commit 79b588e
Showing
3 changed files
with
75 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |