Merge pull request #1261 from shlok007/resources
Ability to track resources
This commit is contained in:
commit
f42e4adc45
17 changed files with 265 additions and 2 deletions
8
spec/factories/resource.rb
Normal file
8
spec/factories/resource.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
FactoryGirl.define do
|
||||
factory :resource do
|
||||
name { 'Resource' }
|
||||
quantity { 10 }
|
||||
used { 5 }
|
||||
conference
|
||||
end
|
||||
end
|
||||
47
spec/features/resource_spec.rb
Normal file
47
spec/features/resource_spec.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature Resource do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:admin) { create(:admin) }
|
||||
let!(:resource) { create(:resource, conference: conference) }
|
||||
|
||||
context 'as an admin' do
|
||||
before(:each) do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
scenario 'create a new resource' do
|
||||
visit admin_conference_resources_path(conference.short_title)
|
||||
click_link 'Add Resource'
|
||||
|
||||
fill_in 'resource_name', with: 'shirts'
|
||||
fill_in 'resource_description', with: 'what you love to wear!'
|
||||
fill_in 'resource_quantity', with: 10
|
||||
|
||||
click_button 'Create Resource'
|
||||
|
||||
expect(Resource.count).to eq(2)
|
||||
expect(flash).to eq('Resource successfully created.')
|
||||
end
|
||||
|
||||
scenario 'edit an existing resource' do
|
||||
visit admin_conference_resources_path(conference.short_title)
|
||||
click_link('Edit', edit_admin_conference_resource_path(conference.short_title, resource.id))
|
||||
|
||||
fill_in 'resource_name', with: 'changed_name'
|
||||
|
||||
click_button 'Update Resource'
|
||||
resource.reload
|
||||
|
||||
expect(flash).to eq('Resource successfully updated.')
|
||||
expect(resource.name).to eq('changed_name')
|
||||
end
|
||||
|
||||
scenario 'destroy a resource' do
|
||||
visit admin_conference_resources_path(conference.short_title)
|
||||
click_link('Delete', href: admin_conference_resource_path(conference.short_title, resource.id))
|
||||
|
||||
expect(flash).to eq('Resource successfully destroyed.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -29,7 +29,7 @@ describe 'User' do
|
|||
|
||||
let(:commercial_event_confirmed) { create(:commercial, commercialable: event_confirmed) }
|
||||
let(:commercial_event_unconfirmed) { create(:commercial, commercialable: event_unconfirmed) }
|
||||
|
||||
let(:resource) { create(:resource, conference: my_conference)}
|
||||
let(:registration) { create(:registration) }
|
||||
|
||||
let(:program_with_cfp) { create(:program, cfp: create(:cfp)) }
|
||||
|
|
@ -235,6 +235,8 @@ describe 'User' do
|
|||
it{ should be_able_to(:index, my_event.comment_threads.first) }
|
||||
it{ should_not be_able_to(:index, other_event.comment_threads.first) }
|
||||
|
||||
it{ should be_able_to(:manage, resource)}
|
||||
|
||||
%w(organizer cfp info_desk volunteers_coordinator).each do |role|
|
||||
it{ should be_able_to(:toggle_user, Role.find_by(name: role, resource: my_conference)) }
|
||||
it{ should be_able_to(:edit, Role.find_by(name: role, resource: my_conference)) }
|
||||
|
|
@ -304,6 +306,11 @@ describe 'User' do
|
|||
it{ should be_able_to(:index, my_event.comment_threads.first) }
|
||||
it{ should_not be_able_to(:index, other_event.comment_threads.first) }
|
||||
|
||||
it{ should_not be_able_to(:manage, resource)}
|
||||
it{ should be_able_to(:index, resource)}
|
||||
it{ should be_able_to(:show, resource)}
|
||||
it{ should be_able_to(:update, resource)}
|
||||
|
||||
it_behaves_like 'user with any role'
|
||||
it_behaves_like 'user with non-organizer role', 'cfp'
|
||||
end
|
||||
|
|
@ -366,6 +373,11 @@ describe 'User' do
|
|||
it{ should_not be_able_to(:index, my_event.comment_threads.first) }
|
||||
it{ should_not be_able_to(:index, other_event.comment_threads.first) }
|
||||
|
||||
it{ should_not be_able_to(:manage, resource)}
|
||||
it{ should be_able_to(:index, resource)}
|
||||
it{ should be_able_to(:show, resource)}
|
||||
it{ should be_able_to(:update, resource)}
|
||||
|
||||
it_behaves_like 'user with any role'
|
||||
it_behaves_like 'user with non-organizer role', 'info_desk'
|
||||
end
|
||||
|
|
@ -427,6 +439,12 @@ describe 'User' do
|
|||
it{ should_not be_able_to(:manage, other_event.commercials.first) }
|
||||
it{ should_not be_able_to(:index, my_event.comment_threads.first) }
|
||||
it{ should_not be_able_to(:index, other_event.comment_threads.first) }
|
||||
|
||||
it{ should_not be_able_to(:manage, resource)}
|
||||
it{ should be_able_to(:index, resource)}
|
||||
it{ should be_able_to(:show, resource)}
|
||||
it{ should be_able_to(:update, resource)}
|
||||
|
||||
it 'should be_able to :manage Vposition'
|
||||
it 'should be_able to :manage Vday'
|
||||
|
||||
|
|
|
|||
15
spec/models/resource_spec.rb
Normal file
15
spec/models/resource_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Resource do
|
||||
let(:conference) { create(:conference) }
|
||||
let(:resource) { create :resource }
|
||||
|
||||
it 'has a valid factory' do
|
||||
expect(build(:resource)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid with used greater than quantity' do
|
||||
resource.used = resource.quantity + 1
|
||||
expect(resource.valid?).to eq false
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue