spec/controllers/curate/collections_controller_spec.rb in curate-0.5.4 vs spec/controllers/curate/collections_controller_spec.rb in curate-0.5.5
- old
+ new
@@ -1,9 +1,8 @@
require 'spec_helper'
describe Curate::CollectionsController do
- before(:all) { Collection.destroy_all }
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "#new" do
it 'renders the form' do
@@ -49,22 +48,26 @@
it "adds the new collection to the user's profile" do
account = FactoryGirl.create(:account, user: user)
user.profile.members.should == []
expect {
- post :create, collection: { title: 'test title', description: 'test desc'}, add_to_profile: 'true'
- }.to change{Collection.count}.by(1)
+ expect {
+ post :create, collection: { title: 'test title', description: 'test desc'}, add_to_profile: 'true'
+ }.to change{ProfileSection.count}.by(1)
+ }.to_not change{Collection.count}
reloaded_profile.members.should == [assigns(:collection)]
end
- it "graceful recovery if no profile exists" do
+ it "gracefully recovery if no profile exists" do
user.profile.should be_nil
expect {
- post :create, collection: { title: 'test title', description: 'test desc'}, add_to_profile: 'true'
- }.to change{Collection.count}.by(1)
- expect(response).to redirect_to collections_path
+ expect {
+ post :create, collection: { title: 'test title', description: 'test desc'}, add_to_profile: 'true'
+ }.to change{ProfileSection.count}.by(1)
+ }.to_not change{Collection.count}
+ expect(response).to redirect_to person_path(user.person)
end
end
describe "without access" do
describe "#update" do
@@ -141,10 +144,15 @@
end
end
describe "#add_member failure" do
it "prints fail message" do
- Collection.any_instance.should_receive(:save).and_return(false)
+ ActiveFedora::Base.stub(:find).and_call_original # Need to do this for cleanup
+ ActiveFedora::Base.stub(:find).with(collection.pid, anything).and_return(collection)
+ ActiveFedora::Base.stub(:find).with(work.pid, anything).and_return(work)
+
+ collection.stub(:save).and_return(false)
+
put :add_member, collectible_id: work.pid, collection_id: collection.pid
expect(flash[:error]).to eq 'Unable to add item to collection.'
expect(response).to redirect_to(catalog_index_path)
end
end