Rename some sample nonprofits to make certain tests easier
This commit is contained in:
parent
4d8e5207b9
commit
b19cb9ddc8
4 changed files with 19 additions and 6 deletions
|
@ -99,7 +99,7 @@ class Api::NonprofitsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_params
|
def clean_params
|
||||||
params.permit(nonprofit: [:name, :zip_code, :state_code, :city], user: [:name, :email, :password])
|
params.permit(:name, :zip_code, :state_code, :city, :user)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe CampaignsController, type: :controller do
|
||||||
name: 'simplename',
|
name: 'simplename',
|
||||||
total_raised: 0,
|
total_raised: 0,
|
||||||
goal_amount: 444,
|
goal_amount: 444,
|
||||||
url: "/nm/albuquerque/new_mexican_equality/campaigns/slug_#{campaign.id}"
|
url: "/nm/albuquerque/new-mexico-equality/campaigns/slug_#{campaign.id}"
|
||||||
}]}.with_indifferent_access)
|
}]}.with_indifferent_access)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ FactoryBot.define do
|
||||||
state_code { 'NM' }
|
state_code { 'NM' }
|
||||||
zip_code { 55_555 }
|
zip_code { 55_555 }
|
||||||
email { 'nmj@gmail.com' }
|
email { 'nmj@gmail.com' }
|
||||||
slug { 'new_mexican_equality' }
|
slug { 'new-mexico-equality' }
|
||||||
state_code_slug { 'nm'}
|
state_code_slug { 'nm'}
|
||||||
city_slug { 'albuquerque'}
|
city_slug { 'albuquerque'}
|
||||||
register_np_only { true }
|
register_np_only { true }
|
||||||
|
@ -23,7 +23,7 @@ FactoryBot.define do
|
||||||
zip_code { 54915 }
|
zip_code { 54915 }
|
||||||
email { 'contact@endpovertyinthefoxvalleyinc.org' }
|
email { 'contact@endpovertyinthefoxvalleyinc.org' }
|
||||||
website {'https://endpovertyinthefoxvalleyinc.org'}
|
website {'https://endpovertyinthefoxvalleyinc.org'}
|
||||||
slug { 'end_poverty_in_the_fox_valley_inc' }
|
slug { 'end-poverty-in-the-fox-valley-inc' }
|
||||||
state_code_slug { 'wi'}
|
state_code_slug { 'wi'}
|
||||||
city_slug { 'appleton'}
|
city_slug { 'appleton'}
|
||||||
register_np_only { true }
|
register_np_only { true }
|
||||||
|
|
|
@ -49,6 +49,10 @@ RSpec.describe Nonprofit, type: :model do
|
||||||
let(:nonprofit) { Nonprofit.new()}
|
let(:nonprofit) { Nonprofit.new()}
|
||||||
let(:nonprofit_with_invalid_user) { Nonprofit.new(user_id: 3333)}
|
let(:nonprofit_with_invalid_user) { Nonprofit.new(user_id: 3333)}
|
||||||
let(:nonprofit_with_user_who_already_admin) {nonprofit_admin_role; Nonprofit.new(user_id: user.id)}
|
let(:nonprofit_with_user_who_already_admin) {nonprofit_admin_role; Nonprofit.new(user_id: user.id)}
|
||||||
|
|
||||||
|
let(:nonprofit_with_same_name) { Nonprofit.new({name: "New Mexico Equality", state_code: nm_justice.state_code, city: nm_justice.city, user_id: user.id})}
|
||||||
|
let(:nonprofit_with_same_name_but_different_state) { Nonprofit.new({name: "New Mexico Equality", state_code: 'mn', city: nm_justice.city, user_id: user.id })}
|
||||||
|
|
||||||
let(:user) { create(:user)}
|
let(:user) { create(:user)}
|
||||||
let(:nonprofit_admin_role) do
|
let(:nonprofit_admin_role) do
|
||||||
role = user.roles.build(host: nonprofit, name: 'nonprofit_admin')
|
role = user.roles.build(host: nonprofit, name: 'nonprofit_admin')
|
||||||
|
@ -57,7 +61,7 @@ RSpec.describe Nonprofit, type: :model do
|
||||||
end
|
end
|
||||||
let(:nm_justice) {create(:nm_justice)}
|
let(:nm_justice) {create(:nm_justice)}
|
||||||
|
|
||||||
before(:each) { nonprofit.valid?; nonprofit_with_invalid_user.valid?; nonprofit_with_user_who_already_admin.valid?}
|
before(:each) { nonprofit.valid?; nonprofit_with_invalid_user.valid?; nonprofit_with_user_who_already_admin.valid?; nonprofit_with_same_name.valid?; nonprofit_with_same_name_but_different_state.valid?}
|
||||||
it 'has an error for no name' do
|
it 'has an error for no name' do
|
||||||
expect(nonprofit.errors['name'].first).to match /.*blank.*/
|
expect(nonprofit.errors['name'].first).to match /.*blank.*/
|
||||||
end
|
end
|
||||||
|
@ -79,9 +83,18 @@ RSpec.describe Nonprofit, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'rejects a user who is already an admin' do
|
it 'rejects a user who is already an admin' do
|
||||||
byebug
|
|
||||||
expect(nonprofit_with_user_who_already_admin.errors['user_id'].first).to match /.*admin.*/
|
expect(nonprofit_with_user_who_already_admin.errors['user_id'].first).to match /.*admin.*/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'accepts and corrects a slug when it tries to save' do
|
||||||
|
expect(nonprofit_with_same_name.errors['slug']).to be_empty
|
||||||
|
expect(nonprofit_with_same_name.slug).to eq "#{nm_justice.slug}-00"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does nothing to a slug when it tries to save' do
|
||||||
|
expect(nonprofit_with_same_name_but_different_state.errors['slug']).to be_empty
|
||||||
|
expect(nonprofit_with_same_name_but_different_state.slug).to eq "#{nm_justice.slug}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue