From 8839a928ed83a0fca8b90f9c5a6871f9c7bc946e Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 14 Jun 2017 21:59:58 +0530 Subject: [PATCH] mending failing tests --- .../admin/conferences_controller.rb | 5 +---- app/models/ability.rb | 2 +- app/views/admin/conferences/new.html.haml | 1 - .../admin/conferences_controller_spec.rb | 18 +++++++++--------- .../admin/organizations_controller_spec.rb | 10 +++++----- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index bf1dfdb5..f8c9ea19 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -72,14 +72,11 @@ module Admin def new @conference = Conference.new - @organizations = {} - Organization.all.each do |organization| - @organizations.store(organization.name, organization.id) if can? :create, Conference.new(organization: organization) - end end def create @conference = Conference.new(conference_params) + @conference.organization = Organization.find_or_create_by(name: 'organization') if @conference.save # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference diff --git a/app/models/ability.rb b/app/models/ability.rb index 6e560a63..37090a49 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -152,7 +152,7 @@ class Ability org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) can :manage, Organization, id: org_ids_for_organization_admin - can [:new], Conference + can :new, Conference can :manage, Conference, organization_id: org_ids_for_organization_admin conf_ids_for_organization_admin = [] org_ids_for_organization_admin.each do |org_id| diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 0d2eb4b3..014758de 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -6,7 +6,6 @@ input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }, prepend: conferences_url + '/' - = f.input :organization, as: :select, collection: @organizations = f.inputs 'Scheduling' do = f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' } diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index d6133c65..009e40ba 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe Admin::ConferencesController do # It is necessary to use bang version of let to build roles before user - let(:organization) { create(:organization) } - let(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } + let!(:organization) { create(:organization, name: 'organization') } + let!(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } let(:organization_admin) { create(:user, role_ids: organization_admin_role.id) } @@ -143,14 +143,14 @@ describe Admin::ConferencesController do it 'saves the conference to the database' do expected = expect do post :create, conference: - attributes_for(:conference, short_title: 'dps15', organization: organization) + attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) end expected.to change { Conference.count }.by 1 end it 'redirects to conference#show' do post :create, conference: - attributes_for(:conference, short_title: 'dps15', organization: organization) + attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) expect(response).to redirect_to admin_conference_path( assigns[:conference].short_title) @@ -174,14 +174,14 @@ describe Admin::ConferencesController do it 'does not save the conference to the database' do expected = expect do post :create, conference: - attributes_for(:conference, short_title: nil, organization: organization) + attributes_for(:conference, short_title: nil, organization_id: organization.id) end expected.to_not change { Conference.count } end it 're-renders the new template' do post :create, conference: - attributes_for(:conference, short_title: nil, organization: organization) + attributes_for(:conference, short_title: nil, organization_id: organization.id) expect(response).to be_success end end @@ -191,14 +191,14 @@ describe Admin::ConferencesController do conference expected = expect do post :create, conference: - attributes_for(:conference, short_title: conference.short_title, organization: organization) + attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) end expected.to_not change { Conference.count } end it 're-renders the new template' do conference - post :create, conference: attributes_for(:conference, short_title: conference.short_title, organization: organization) + post :create, conference: attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) expect(response).to be_success end end @@ -240,7 +240,7 @@ describe Admin::ConferencesController do describe 'POST #create' do it 'requires organizer privileges' do post :create, conference: attributes_for(:conference, - short_title: 'ExCon') + short_title: 'ExCon', organization_id: organization.id) expect(response).to redirect_to(send(path)) if message expect(flash[:alert]).to match(/#{message}/) diff --git a/spec/controllers/admin/organizations_controller_spec.rb b/spec/controllers/admin/organizations_controller_spec.rb index a4afc994..abe5005b 100644 --- a/spec/controllers/admin/organizations_controller_spec.rb +++ b/spec/controllers/admin/organizations_controller_spec.rb @@ -16,7 +16,7 @@ describe Admin::OrganizationsController do end it 'redirects to root' do - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -27,7 +27,7 @@ describe Admin::OrganizationsController do end it 'redirects to root' do - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -43,7 +43,7 @@ describe Admin::OrganizationsController do it 'redirects to root' do post :create, organization: attributes_for(:organization) - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -55,7 +55,7 @@ describe Admin::OrganizationsController do organization.reload expect(organization.name).to eq(old_name) - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -72,7 +72,7 @@ describe Admin::OrganizationsController do it 'redirects to root' do delete :destroy, id: organization.id - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end