mending failing tests

This commit is contained in:
shlok007 2017-06-14 21:59:58 +05:30
parent ad3d6f2f95
commit 8839a928ed
5 changed files with 16 additions and 20 deletions

View file

@ -72,14 +72,11 @@ module Admin
def new def new
@conference = Conference.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 end
def create def create
@conference = Conference.new(conference_params) @conference = Conference.new(conference_params)
@conference.organization = Organization.find_or_create_by(name: 'organization')
if @conference.save if @conference.save
# user that creates the conference becomes organizer of that conference # user that creates the conference becomes organizer of that conference
current_user.add_role :organizer, @conference current_user.add_role :organizer, @conference

View file

@ -152,7 +152,7 @@ class Ability
org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id)
can :manage, Organization, id: org_ids_for_organization_admin 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 can :manage, Conference, organization_id: org_ids_for_organization_admin
conf_ids_for_organization_admin = [] conf_ids_for_organization_admin = []
org_ids_for_organization_admin.each do |org_id| org_ids_for_organization_admin.each do |org_id|

View file

@ -6,7 +6,6 @@
input_html: { required: 'required' } 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'", = 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 + '/' 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.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 :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' } = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' }

View file

@ -3,8 +3,8 @@ require 'spec_helper'
describe Admin::ConferencesController do describe Admin::ConferencesController do
# It is necessary to use bang version of let to build roles before user # It is necessary to use bang version of let to build roles before user
let(:organization) { create(:organization) } let!(:organization) { create(:organization, name: 'organization') }
let(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } 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!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) }
let(:organization_admin) { create(:user, role_ids: organization_admin_role.id) } 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 it 'saves the conference to the database' do
expected = expect do expected = expect do
post :create, conference: post :create, conference:
attributes_for(:conference, short_title: 'dps15', organization: organization) attributes_for(:conference, short_title: 'dps15', organization_id: organization.id)
end end
expected.to change { Conference.count }.by 1 expected.to change { Conference.count }.by 1
end end
it 'redirects to conference#show' do it 'redirects to conference#show' do
post :create, conference: 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( expect(response).to redirect_to admin_conference_path(
assigns[:conference].short_title) assigns[:conference].short_title)
@ -174,14 +174,14 @@ describe Admin::ConferencesController do
it 'does not save the conference to the database' do it 'does not save the conference to the database' do
expected = expect do expected = expect do
post :create, conference: post :create, conference:
attributes_for(:conference, short_title: nil, organization: organization) attributes_for(:conference, short_title: nil, organization_id: organization.id)
end end
expected.to_not change { Conference.count } expected.to_not change { Conference.count }
end end
it 're-renders the new template' do it 're-renders the new template' do
post :create, conference: 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 expect(response).to be_success
end end
end end
@ -191,14 +191,14 @@ describe Admin::ConferencesController do
conference conference
expected = expect do expected = expect do
post :create, conference: 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 end
expected.to_not change { Conference.count } expected.to_not change { Conference.count }
end end
it 're-renders the new template' do it 're-renders the new template' do
conference 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 expect(response).to be_success
end end
end end
@ -240,7 +240,7 @@ describe Admin::ConferencesController do
describe 'POST #create' do describe 'POST #create' do
it 'requires organizer privileges' do it 'requires organizer privileges' do
post :create, conference: attributes_for(:conference, post :create, conference: attributes_for(:conference,
short_title: 'ExCon') short_title: 'ExCon', organization_id: organization.id)
expect(response).to redirect_to(send(path)) expect(response).to redirect_to(send(path))
if message if message
expect(flash[:alert]).to match(/#{message}/) expect(flash[:alert]).to match(/#{message}/)

View file

@ -16,7 +16,7 @@ describe Admin::OrganizationsController do
end end
it 'redirects to root' do 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) expect(response).to redirect_to(root_path)
end end
end end
@ -27,7 +27,7 @@ describe Admin::OrganizationsController do
end end
it 'redirects to root' do 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) expect(response).to redirect_to(root_path)
end end
end end
@ -43,7 +43,7 @@ describe Admin::OrganizationsController do
it 'redirects to root' do it 'redirects to root' do
post :create, organization: attributes_for(:organization) 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) expect(response).to redirect_to(root_path)
end end
end end
@ -55,7 +55,7 @@ describe Admin::OrganizationsController do
organization.reload organization.reload
expect(organization.name).to eq(old_name) 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) expect(response).to redirect_to(root_path)
end end
end end
@ -72,7 +72,7 @@ describe Admin::OrganizationsController do
it 'redirects to root' do it 'redirects to root' do
delete :destroy, id: organization.id 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) expect(response).to redirect_to(root_path)
end end
end end