diff --git a/app/controllers/api/nonprofits_controller.rb b/app/controllers/api/nonprofits_controller.rb index 58a7a9d4..5b48dfc6 100644 --- a/app/controllers/api/nonprofits_controller.rb +++ b/app/controllers/api/nonprofits_controller.rb @@ -99,7 +99,7 @@ class Api::NonprofitsController < ApplicationController end 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 diff --git a/spec/controllers/campaigns_spec.rb b/spec/controllers/campaigns_spec.rb index f68b17f3..14ff9127 100644 --- a/spec/controllers/campaigns_spec.rb +++ b/spec/controllers/campaigns_spec.rb @@ -85,7 +85,7 @@ describe CampaignsController, type: :controller do name: 'simplename', total_raised: 0, 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) end end diff --git a/spec/factories/nonprofits.rb b/spec/factories/nonprofits.rb index 7995f1ac..6b812c91 100644 --- a/spec/factories/nonprofits.rb +++ b/spec/factories/nonprofits.rb @@ -9,7 +9,7 @@ FactoryBot.define do state_code { 'NM' } zip_code { 55_555 } email { 'nmj@gmail.com' } - slug { 'new_mexican_equality' } + slug { 'new-mexico-equality' } state_code_slug { 'nm'} city_slug { 'albuquerque'} register_np_only { true } @@ -23,7 +23,7 @@ FactoryBot.define do zip_code { 54915 } email { 'contact@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'} city_slug { 'appleton'} register_np_only { true } diff --git a/spec/models/nonprofit_spec.rb b/spec/models/nonprofit_spec.rb index 98cfd286..54849d11 100644 --- a/spec/models/nonprofit_spec.rb +++ b/spec/models/nonprofit_spec.rb @@ -49,6 +49,10 @@ RSpec.describe Nonprofit, type: :model do let(:nonprofit) { Nonprofit.new()} 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_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(:nonprofit_admin_role) do role = user.roles.build(host: nonprofit, name: 'nonprofit_admin') @@ -57,7 +61,7 @@ RSpec.describe Nonprofit, type: :model do end 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 expect(nonprofit.errors['name'].first).to match /.*blank.*/ end @@ -79,9 +83,18 @@ RSpec.describe Nonprofit, type: :model do end 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.*/ 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