|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 |
| -describe BatchController do |
| 3 | +describe BatchController, :type => :controller do |
4 | 4 | before do
|
5 |
| - controller.stub(:has_access?).and_return(true) |
| 5 | + allow(controller).to receive(:has_access?).and_return(true) |
6 | 6 | @user = FactoryGirl.find_or_create(:jill)
|
7 | 7 | sign_in @user
|
8 |
| - User.any_instance.stub(:groups).and_return([]) |
9 |
| - controller.stub(:clear_session_user) ## Don't clear out the authenticated session |
| 8 | + allow_any_instance_of(User).to receive(:groups).and_return([]) |
| 9 | + allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session |
10 | 10 | end
|
11 | 11 | after do
|
12 | 12 | @user.delete
|
|
35 | 35 | it "should enqueue a batch update job" do
|
36 | 36 | params = {'generic_file' => {'read_groups_string' => '', 'read_users_string' => 'archivist1, archivist2', 'tag' => ['']}, 'id' => @batch.pid, 'controller' => 'batch', 'action' => 'update'}
|
37 | 37 | s1 = double('one')
|
38 |
| - BatchUpdateJob.should_receive(:new).with(@user.user_key, params).and_return(s1) |
39 |
| - Sufia.queue.should_receive(:push).with(s1).once |
| 38 | + expect(BatchUpdateJob).to receive(:new).with(@user.user_key, params).and_return(s1) |
| 39 | + expect(Sufia.queue).to receive(:push).with(s1).once |
40 | 40 | post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "", "read_users_string" => "archivist1, archivist2", "tag" => [""]}
|
41 | 41 | end
|
42 | 42 | it "should show flash messages" do
|
43 | 43 | post :update, id: @batch.pid, "generic_file" => {"read_groups_string" => "","read_users_string" => "archivist1, archivist2", "tag" => [""]}
|
44 |
| - response.should redirect_to @routes.url_helpers.dashboard_files_path |
45 |
| - flash[:notice].should_not be_nil |
46 |
| - flash[:notice].should_not be_empty |
47 |
| - flash[:notice].should include("Your files are being processed") |
| 44 | + expect(response).to redirect_to @routes.url_helpers.dashboard_files_path |
| 45 | + expect(flash[:notice]).not_to be_nil |
| 46 | + expect(flash[:notice]).not_to be_empty |
| 47 | + expect(flash[:notice]).to include("Your files are being processed") |
48 | 48 | end
|
49 | 49 |
|
50 | 50 | describe "when user has edit permissions on a file" do
|
51 | 51 | it "should set the groups" do
|
52 | 52 | post :update, id: @batch.pid, "generic_file"=>{"permissions"=>{"group"=>{"public"=>"1", "registered"=>"2"}}}
|
53 |
| - @file.reload.read_groups.should == [] |
54 |
| - @file.reload.edit_groups.should == [] |
55 |
| - response.should redirect_to @routes.url_helpers.dashboard_files_path |
| 53 | + expect(@file.reload.read_groups).to eq([]) |
| 54 | + expect(@file.reload.edit_groups).to eq([]) |
| 55 | + expect(response).to redirect_to @routes.url_helpers.dashboard_files_path |
56 | 56 | end
|
57 | 57 |
|
58 | 58 | it "should set the users with read access" do
|
59 | 59 | post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1, archivist2", "tag"=>[""]}
|
60 | 60 | file = GenericFile.find(@file.pid)
|
61 |
| - file.read_users.should == ['archivist1', 'archivist2'] |
| 61 | + expect(file.read_users).to eq(['archivist1', 'archivist2']) |
62 | 62 |
|
63 |
| - response.should redirect_to @routes.url_helpers.dashboard_files_path |
| 63 | + expect(response).to redirect_to @routes.url_helpers.dashboard_files_path |
64 | 64 | end
|
65 | 65 | it "should set the groups with read access" do
|
66 | 66 | post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
|
67 | 67 | file = GenericFile.find(@file.pid)
|
68 |
| - file.read_groups.should == ['group1', 'group2'] |
| 68 | + expect(file.read_groups).to eq(['group1', 'group2']) |
69 | 69 | end
|
70 | 70 | it "should set public read access" do
|
71 | 71 | post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"", "tag"=>[""]}
|
72 | 72 | file = GenericFile.find(@file.pid)
|
73 |
| - file.read_groups.should == ['public'] |
| 73 | + expect(file.read_groups).to eq(['public']) |
74 | 74 | end
|
75 | 75 | it "should set public read access and groups at the same time" do
|
76 | 76 | post :update, id: @batch.pid, "visibility"=>"open", "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
|
77 | 77 | file = GenericFile.find(@file.pid)
|
78 |
| - file.read_groups.should == ['group1', 'group2', 'public'] |
| 78 | + expect(file.read_groups).to eq(['group1', 'group2', 'public']) |
79 | 79 | end
|
80 | 80 | it "should set public discover access and groups at the same time" do
|
81 | 81 | post :update, id: @batch.pid, "permission"=>{"group"=>{"public"=>"none"}}, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}
|
82 | 82 | file = GenericFile.find(@file.pid)
|
83 |
| - file.read_groups.should == ['group1', 'group2'] |
84 |
| - file.discover_groups.should == [] |
| 83 | + expect(file.read_groups).to eq(['group1', 'group2']) |
| 84 | + expect(file.discover_groups).to eq([]) |
85 | 85 | end
|
86 | 86 | it "should set metadata like title" do
|
87 | 87 | post :update, id: @batch.pid, "generic_file"=>{"tag"=>["footag", "bartag"]}, "title"=>{@file.pid=>["New Title"]}
|
88 | 88 | file = GenericFile.find(@file.pid)
|
89 |
| - file.title.should == ["New Title"] |
90 |
| - file.tag.should == ["footag", "bartag"] |
| 89 | + expect(file.title).to eq(["New Title"]) |
| 90 | + expect(file.tag).to eq(["footag", "bartag"]) |
91 | 91 | end
|
92 | 92 | it "should not set any tags" do
|
93 | 93 | post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"", "read_users_string"=>"archivist1", "tag"=>[""]}
|
94 | 94 | file = GenericFile.find(@file.pid)
|
95 |
| - file.tag.should be_empty |
| 95 | + expect(file.tag).to be_empty |
96 | 96 | end
|
97 | 97 | end
|
98 | 98 | describe "when user does not have edit permissions on a file" do
|
99 | 99 | it "should not modify the object" do
|
100 | 100 | file = GenericFile.find(@file2.pid)
|
101 | 101 | file.title = ["Original Title"]
|
102 |
| - file.read_groups.should == [] |
| 102 | + expect(file.read_groups).to eq([]) |
103 | 103 | file.save
|
104 | 104 | post :update, id: @batch.pid, "generic_file"=>{"read_groups_string"=>"group1, group2", "read_users_string"=>"", "tag"=>[""]}, "title"=>{@file2.pid=>["Title Wont Change"]}
|
105 | 105 | file = GenericFile.find(@file2.pid)
|
106 |
| - file.title.should == ["Original Title"] |
107 |
| - file.read_groups.should == [] |
| 106 | + expect(file.title).to eq(["Original Title"]) |
| 107 | + expect(file.read_groups).to eq([]) |
108 | 108 | end
|
109 | 109 | end
|
110 | 110 | end
|
111 | 111 | describe "#edit" do
|
112 | 112 | before do
|
113 |
| - User.any_instance.stub(:display_name).and_return("Jill Z. User") |
| 113 | + allow_any_instance_of(User).to receive(:display_name).and_return("Jill Z. User") |
114 | 114 | @b1 = Batch.new
|
115 | 115 | @b1.save
|
116 | 116 | @file = GenericFile.new(batch: @b1, label: 'f1')
|
|
127 | 127 | end
|
128 | 128 | it "should default creator" do
|
129 | 129 | get :edit, id: @b1.id
|
130 |
| - assigns[:generic_file].creator[0].should == @user.display_name |
131 |
| - assigns[:generic_file].title[0].should == 'f1' |
| 130 | + expect(assigns[:generic_file].creator[0]).to eq(@user.display_name) |
| 131 | + expect(assigns[:generic_file].title[0]).to eq('f1') |
132 | 132 | end
|
133 | 133 | end
|
134 | 134 | end
|
0 commit comments