Skip to content

Commit

Permalink
Merge pull request #703 from projecthydra/byebye_shoulds
Browse files Browse the repository at this point in the history
Convert specs to RSpec 3.1.7 syntax with Transpec. Fixes #702
  • Loading branch information
jcoyne committed Oct 31, 2014
2 parents c2c8467 + ecac643 commit af12dc4
Show file tree
Hide file tree
Showing 103 changed files with 1,011 additions and 988 deletions.
12 changes: 6 additions & 6 deletions spec/controllers/authorities_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe AuthoritiesController do
describe AuthoritiesController, :type => :controller do
describe "#query" do
it "should return an array of hashes" do
mock_hits = [{label: "English", uri: "http://example.org/eng"},
Expand All @@ -9,12 +9,12 @@
{label: "Edgar", uri: "http://example.org/edga"},
{label: "Eddie", uri: "http://example.org/edd"},
{label: "Economics", uri: "http://example.org/eco"}]
LocalAuthority.should_receive(:entries_by_term).and_return(mock_hits)
expect(LocalAuthority).to receive(:entries_by_term).and_return(mock_hits)
xhr :get, :query, model: "generic_files", term: "subject", q: "E"
response.should be_success
JSON.parse(response.body).count.should == 6
JSON.parse(response.body)[0]["label"].should == "English"
JSON.parse(response.body)[0]["uri"].should == "http://example.org/eng"
expect(response).to be_success
expect(JSON.parse(response.body).count).to eq(6)
expect(JSON.parse(response.body)[0]["label"]).to eq("English")
expect(JSON.parse(response.body)[0]["uri"]).to eq("http://example.org/eng")
end
end
end
58 changes: 29 additions & 29 deletions spec/controllers/batch_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'spec_helper'

describe BatchController do
describe BatchController, :type => :controller do
before do
controller.stub(:has_access?).and_return(true)
allow(controller).to receive(:has_access?).and_return(true)
@user = FactoryGirl.find_or_create(:jill)
sign_in @user
User.any_instance.stub(:groups).and_return([])
controller.stub(:clear_session_user) ## Don't clear out the authenticated session
allow_any_instance_of(User).to receive(:groups).and_return([])
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
end
after do
@user.delete
Expand Down Expand Up @@ -35,82 +35,82 @@
it "should enqueue a batch update job" do
params = {'generic_file' => {'read_groups_string' => '', 'read_users_string' => 'archivist1, archivist2', 'tag' => ['']}, 'id' => @batch.pid, 'controller' => 'batch', 'action' => 'update'}
s1 = double('one')
BatchUpdateJob.should_receive(:new).with(@user.user_key, params).and_return(s1)
Sufia.queue.should_receive(:push).with(s1).once
expect(BatchUpdateJob).to receive(:new).with(@user.user_key, params).and_return(s1)
expect(Sufia.queue).to receive(:push).with(s1).once
post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "", "read_users_string" => "archivist1, archivist2", "tag" => [""]}
end
it "should show flash messages" do
post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "","read_users_string" => "archivist1, archivist2", "tag" => [""]}
response.should redirect_to @routes.url_helpers.dashboard_files_path
flash[:notice].should_not be_nil
flash[:notice].should_not be_empty
flash[:notice].should include("Your files are being processed")
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
expect(flash[:notice]).not_to be_nil
expect(flash[:notice]).not_to be_empty
expect(flash[:notice]).to include("Your files are being processed")
end

describe "when user has edit permissions on a file" do
it "should set the groups" do
post :update, id: @batch.pid, "generic_file"=>{"permissions"=>{"group"=>{"public"=>"1", "registered"=>"2"}}}
@file.reload.read_groups.should == []
@file.reload.edit_groups.should == []
response.should redirect_to @routes.url_helpers.dashboard_files_path
expect(@file.reload.read_groups).to eq([])
expect(@file.reload.edit_groups).to eq([])
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
end

it "should set the users with read access" do
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1, archivist2", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.read_users.should == ['archivist1', 'archivist2']
expect(file.read_users).to eq(['archivist1', 'archivist2'])

response.should redirect_to @routes.url_helpers.dashboard_files_path
expect(response).to redirect_to @routes.url_helpers.dashboard_files_path
end
it "should set the groups with read access" do
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.read_groups.should == ['group1', 'group2']
expect(file.read_groups).to eq(['group1', 'group2'])
end
it "should set public read access" do
post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.read_groups.should == ['public']
expect(file.read_groups).to eq(['public'])
end
it "should set public read access and groups at the same time" do
post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.read_groups.should == ['group1', 'group2', 'public']
expect(file.read_groups).to eq(['group1', 'group2', 'public'])
end
it "should set public discover access and groups at the same time" do
post :update, id: @batch.pid, "permission"=>{"group"=>{"public"=>"none"}}, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.read_groups.should == ['group1', 'group2']
file.discover_groups.should == []
expect(file.read_groups).to eq(['group1', 'group2'])
expect(file.discover_groups).to eq([])
end
it "should set metadata like title" do
post :update, id: @batch.pid, "generic_file"=>{"tag"=>["footag", "bartag"]}, "title"=>{@file.pid=>["New Title"]}
file = GenericFile.find(@file.pid)
file.title.should == ["New Title"]
file.tag.should == ["footag", "bartag"]
expect(file.title).to eq(["New Title"])
expect(file.tag).to eq(["footag", "bartag"])
end
it "should not set any tags" do
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1", "tag"=>[""]}
file = GenericFile.find(@file.pid)
file.tag.should be_empty
expect(file.tag).to be_empty
end
end
describe "when user does not have edit permissions on a file" do
it "should not modify the object" do
file = GenericFile.find(@file2.pid)
file.title = ["Original Title"]
file.read_groups.should == []
expect(file.read_groups).to eq([])
file.save
post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}, "title"=>{@file2.pid=>["Title Wont Change"]}
file = GenericFile.find(@file2.pid)
file.title.should == ["Original Title"]
file.read_groups.should == []
expect(file.title).to eq(["Original Title"])
expect(file.read_groups).to eq([])
end
end
end
describe "#edit" do
before do
User.any_instance.stub(:display_name).and_return("Jill Z. User")
allow_any_instance_of(User).to receive(:display_name).and_return("Jill Z. User")
@b1 = Batch.new
@b1.save
@file = GenericFile.new(batch: @b1, label: 'f1')
Expand All @@ -127,8 +127,8 @@
end
it "should default creator" do
get :edit, id: @b1.id
assigns[:generic_file].creator[0].should == @user.display_name
assigns[:generic_file].title[0].should == 'f1'
expect(assigns[:generic_file].creator[0]).to eq(@user.display_name)
expect(assigns[:generic_file].title[0]).to eq('f1')
end
end
end
14 changes: 7 additions & 7 deletions spec/controllers/batch_edits_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'spec_helper'

describe BatchEditsController do
describe BatchEditsController, :type => :controller do
before do
controller.stub(:has_access?).and_return(true)
allow(controller).to receive(:has_access?).and_return(true)
@user = FactoryGirl.find_or_create(:jill)
sign_in @user
User.any_instance.stub(:groups).and_return([])
controller.stub(:clear_session_user) ## Don't clear out the authenticated session
allow_any_instance_of(User).to receive(:groups).and_return([])
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
request.env["HTTP_REFERER"] = 'test.host/original_page'
end

Expand All @@ -26,9 +26,9 @@
end
it "should be successful" do
get :edit
response.should be_successful
assigns[:terms].should == [:creator, :contributor, :description, :tag, :rights, :publisher,
:date_created, :subject, :language, :identifier, :based_near, :related_url]
expect(response).to be_successful
expect(assigns[:terms]).to eq([:creator, :contributor, :description, :tag, :rights, :publisher,
:date_created, :subject, :language, :identifier, :based_near, :related_url])
expect(assigns[:show_file].creator).to eq ["Fred", "Wilma"]
expect(assigns[:show_file].publisher).to eq ["Rand McNally"]
expect(assigns[:show_file].language).to eq ["en"]
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe CatalogController do
describe CatalogController, :type => :controller do
routes { Rails.application.class.routes }

let(:user) { @user }
Expand Down Expand Up @@ -38,19 +38,19 @@
get :index, q: 'full_textfull_text'
expect(response).to be_success
expect(response).to render_template('catalog/index')
assigns(:document_list).count.should eql(1)
assigns(:document_list).map(&:id).should == [@gf2.id]
expect(assigns(:document_list).count).to eql(1)
expect(assigns(:document_list).map(&:id)).to eq([@gf2.id])
end
end

describe "term search" do
it "should find records" do
get :index, q: "pdf", owner: 'all'
expect(response).to be_success
response.should render_template('catalog/index')
assigns(:document_list).map(&:id).should == [@gf1.id]
assigns(:document_list).count.should eql(1)
assigns(:document_list).first['desc_metadata__title_tesim'].should == ['Test Document PDF']
expect(response).to render_template('catalog/index')
expect(assigns(:document_list).map(&:id)).to eq([@gf1.id])
expect(assigns(:document_list).count).to eql(1)
expect(assigns(:document_list).first['desc_metadata__title_tesim']).to eq(['Test Document PDF'])
end
end

Expand All @@ -61,8 +61,8 @@
end
it "should find facet files" do
expect(response).to be_success
response.should render_template('catalog/index')
assigns(:document_list).count.should eql(1)
expect(response).to render_template('catalog/index')
expect(assigns(:document_list).count).to eql(1)
end
end

Expand Down
56 changes: 28 additions & 28 deletions spec/controllers/collections_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'

describe CollectionsController do
describe CollectionsController, :type => :controller do
before(:each) { @routes = Hydra::Collections::Engine.routes }
before do
controller.stub(:has_access?).and_return(true)
User.any_instance.stub(:groups).and_return([])
allow(controller).to receive(:has_access?).and_return(true)
allow_any_instance_of(User).to receive(:groups).and_return([])
end

let(:user) { FactoryGirl.create(:user) }
Expand All @@ -22,7 +22,7 @@

it 'should assign @collection' do
get :new
assigns(:collection).should be_kind_of(Collection)
expect(assigns(:collection)).to be_kind_of(Collection)
end
end

Expand All @@ -32,10 +32,10 @@
end

it "should create a Collection" do
controller.should_receive(:has_access?).and_return(true)
expect(controller).to receive(:has_access?).and_return(true)
old_count = Collection.count
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
Collection.count.should == old_count+1
expect(Collection.count).to eq(old_count+1)
end
it "should create a Collection with files I can access" do
@asset1 = GenericFile.new(title: ["First of the Assets"])
Expand All @@ -47,15 +47,15 @@
@asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:'abc')
@asset3.apply_depositor_metadata('abc')
@asset3.save
controller.should_receive(:has_access?).and_return(true)
expect(controller).to receive(:has_access?).and_return(true)
old_count = Collection.count
post :create, collection: { title: "My own Collection", description: "The Description\r\n\r\nand more" },
batch_document_ids: [@asset1.id, @asset2.id, @asset3.id]
Collection.count.should == old_count+1
expect(Collection.count).to eq(old_count+1)
collection = assigns(:collection)
collection.members.should include (@asset1)
collection.members.should include (@asset2)
collection.members.to_a.should_not include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
expect(collection.members).to include (@asset1)
expect(collection.members).to include (@asset2)
expect(collection.members.to_a).not_to include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
@asset1.destroy
@asset2.destroy
@asset3.destroy
Expand All @@ -67,13 +67,13 @@
@asset1.save
post :create, batch_document_ids: [@asset1.id],
collection: { title: "My Secong Collection ", description: "The Description\r\n\r\nand more" }
assigns[:collection].members.should == [@asset1]
expect(assigns[:collection].members).to eq([@asset1])
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
asset_results["response"]["numFound"].should == 1
expect(asset_results["response"]["numFound"]).to eq(1)
doc = asset_results["response"]["docs"].first
doc["id"].should == @asset1.id
expect(doc["id"]).to eq(@asset1.id)
afterupdate = GenericFile.find(@asset1.pid)
doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
end

end
Expand Down Expand Up @@ -103,21 +103,21 @@

it "should set collection on members" do
put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids: [@asset3.pid, @asset1.pid, @asset2.pid]
response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.noid)
assigns[:collection].members.map{|m| m.pid}.sort.should == [@asset2, @asset3, @asset1].map {|m| m.pid}.sort
expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.noid)
expect(assigns[:collection].members.map{|m| m.pid}.sort).to eq([@asset2, @asset3, @asset1].map {|m| m.pid}.sort)
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
asset_results["response"]["numFound"].should == 1
expect(asset_results["response"]["numFound"]).to eq(1)
doc = asset_results["response"]["docs"].first
doc["id"].should == @asset2.id
expect(doc["id"]).to eq(@asset2.id)
afterupdate = GenericFile.find(@asset2.pid)
doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids: [@asset2]
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
asset_results["response"]["numFound"].should == 1
expect(asset_results["response"]["numFound"]).to eq(1)
doc = asset_results["response"]["docs"].first
doc["id"].should == @asset2.pid
expect(doc["id"]).to eq(@asset2.pid)
afterupdate = GenericFile.find(@asset2.pid)
doc[Solrizer.solr_name(:collection)].should be_nil
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
end
end

Expand All @@ -141,8 +141,8 @@
@collection.apply_depositor_metadata(user.user_key)
@collection.members = [@asset1,@asset2,@asset3]
@collection.save!
controller.stub(:authorize!).and_return(true)
controller.stub(:apply_gated_search)
allow(controller).to receive(:authorize!).and_return(true)
allow(controller).to receive(:apply_gated_search)
end
context "when signed in" do
before do
Expand All @@ -152,7 +152,7 @@
it "should return the collection and its members" do
get :show, id: @collection.id
expect(response).to be_successful
assigns[:collection].title.should == @collection.title
expect(assigns[:collection].title).to eq(@collection.title)
ids = assigns[:member_docs].map(&:id)
expect(ids).to include @asset1.pid, @asset2.pid, @asset3.pid
expect(ids).to_not include @asset4.pid
Expand All @@ -165,7 +165,7 @@
context "not signed in" do
it "should not show me files in the collection" do
get :show, id: @collection.id
assigns[:member_docs].count.should == 0
expect(assigns[:member_docs].count).to eq(0)
end
end
end
Expand All @@ -179,7 +179,7 @@
end
it "should not show flash" do
get :edit, id: @collection.id
flash[:notice].should be_nil
expect(flash[:notice]).to be_nil
end
end
end
6 changes: 3 additions & 3 deletions spec/controllers/content_blocks_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe ContentBlocksController do
describe ContentBlocksController, :type => :controller do
describe "#update" do
let(:content_block) { FactoryGirl.create(:content_block) }
before { request.env["HTTP_REFERER"] = "whence_i_came" }
Expand All @@ -14,10 +14,10 @@

context "when logged in" do
let(:user) { FactoryGirl.create(:user) }
before { controller.stub(current_user: user) }
before { allow(controller).to receive_messages(current_user: user) }

context "as a user in the admin group" do
before { user.should_receive(:groups).and_return( ['admin', 'registered']) }
before { expect(user).to receive(:groups).and_return( ['admin', 'registered']) }

it "should save" do
patch :update, id: content_block, content_block: { value: 'foo' }
Expand Down
Loading

0 comments on commit af12dc4

Please sign in to comment.