-
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
4da0c1c
commit 7a7478e
Showing
4 changed files
with
82 additions
and
14 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
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,85 @@ | ||
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 | ||
@fund_attrs = attributes_for :fund, phone: phone | ||
@phone = Faker::PhoneNumber.cell_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_path(@fund), params: { fund: @fund_attrs } | ||
@fund.reload | ||
refute_equal phone, @fund.phone | ||
assert_redirected_to root_path | ||
end | ||
end | ||
|
||
it 'should update the fund record' do | ||
patch fund_path(@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_path(@fund), params: { fund: @fund_attrs } | ||
@fund.reload | ||
refute_equal phone, @fund.phone | ||
assert_response :success | ||
end | ||
end | ||
|
||
# xtest "should show fund" do | ||
# get fund_url(@fund) | ||
# assert_response :success | ||
# end | ||
|
||
# xtest "should get edit" do | ||
# get edit_fund_url(@fund) | ||
# assert_response :success | ||
# end | ||
|
||
# xtest "should update fund" do | ||
# patch fund_url(@fund), params: { fund: { site_domain: 'foobar.baz' } } | ||
# assert_redirected_to fund_url(@fund) | ||
# end | ||
end |