introduce organizations
This commit is contained in:
parent
bf54487a19
commit
8edf896d86
21 changed files with 345 additions and 4 deletions
14
spec/controllers/admin/organizations_controller_spec.rb
Normal file
14
spec/controllers/admin/organizations_controller_spec.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::OrganizationsController do
|
||||
let(:admin) { create(:admin) }
|
||||
|
||||
describe 'GET #index' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
get :index
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('index') }
|
||||
end
|
||||
end
|
||||
104
spec/controllers/organizations_controller_spec.rb
Normal file
104
spec/controllers/organizations_controller_spec.rb
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe OrganizationsController do
|
||||
let!(:organization) { create(:organization) }
|
||||
let!(:admin) { create(:admin, is_admin: true) }
|
||||
|
||||
describe 'GET #new' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
get :new
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('new') }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
get :index
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('index') }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
context 'with valid attributes' do
|
||||
it 'creates new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
end
|
||||
expected.to change { Organization.count }.by(1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully created')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid attributes' do
|
||||
it 'does not create new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
end
|
||||
expected.to_not change { Organization.count }
|
||||
end
|
||||
|
||||
it 'redirects to new' do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(new_organization_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
it 'saves and redirects to index when the attributes are valid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: 'changed name')
|
||||
|
||||
expect(organization.name).to eq('changed name')
|
||||
expect(flash).to eq('Organization successfully updated')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
|
||||
it 'redirects to edit when attributes are invalid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(edit_organization_path(organization))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
context 'for a valid organization' do
|
||||
it 'should successfully destroy a resource' do
|
||||
expected = expect do
|
||||
delete :destroy, id: organization.id
|
||||
end
|
||||
expected.to change { Organization.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
delete :destroy, id: organization.id
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully destroyed')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@ FactoryGirl.define do
|
|||
end_hour 20
|
||||
registration_limit 0
|
||||
description { Faker::Hipster.paragraph }
|
||||
|
||||
organization
|
||||
after(:create) do |conference|
|
||||
Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)')
|
||||
Role.where(name: 'cfp', resource: conference).first_or_create(description: 'For the members of the CfP team')
|
||||
|
|
|
|||
13
spec/factories/organizations.rb
Normal file
13
spec/factories/organizations.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
FactoryGirl.define do
|
||||
factory :organization do
|
||||
name { Faker::Company.name }
|
||||
description { Faker::Lorem.paragraph }
|
||||
|
||||
# after(:create) do |organization|
|
||||
# File.open("spec/support/logos/#{1 + rand(13)}.png") do |file|
|
||||
# organization.picture = file
|
||||
# end
|
||||
# organization.save!
|
||||
# end
|
||||
end
|
||||
end
|
||||
19
spec/models/organization_spec.rb
Normal file
19
spec/models/organization_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Organization do
|
||||
let(:organization) { create(:organization) }
|
||||
|
||||
describe 'validation' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:organization)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a name' do
|
||||
should validate_presence_of(:name)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'associations' do
|
||||
it { should have_many(:conferences).dependent(:destroy) }
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue