diff --git a/spec/controllers/admin/admin_controller_spec.rb b/spec/controllers/admin/admin_controller_spec.rb index e26da8259..21206230f 100644 --- a/spec/controllers/admin/admin_controller_spec.rb +++ b/spec/controllers/admin/admin_controller_spec.rb @@ -5,13 +5,13 @@ describe Admin::AdminController do context 'index' do it 'needs you to be logged in' do - lambda { xhr :get, :index }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :get, :index }.to raise_error(Discourse::NotLoggedIn) end it "raises an error if you aren't an admin" do user = log_in xhr :get, :index - response.should be_forbidden + expect(response).to be_forbidden end end diff --git a/spec/controllers/admin/api_controller_spec.rb b/spec/controllers/admin/api_controller_spec.rb index 1349f2279..f940ddea5 100644 --- a/spec/controllers/admin/api_controller_spec.rb +++ b/spec/controllers/admin/api_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::ApiController do it "is a subclass of AdminController" do - (Admin::ApiController < Admin::AdminController).should == true + expect(Admin::ApiController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -11,7 +11,7 @@ describe Admin::ApiController do context '.index' do it "succeeds" do xhr :get, :index - response.should be_success + expect(response).to be_success end end @@ -20,8 +20,8 @@ describe Admin::ApiController do it "returns 404 when there is no key" do xhr :put, :regenerate_key, id: 1234 - response.should_not be_success - response.status.should == 404 + expect(response).not_to be_success + expect(response.status).to eq(404) end it "delegates to the api key's `regenerate!` method" do @@ -35,8 +35,8 @@ describe Admin::ApiController do it "returns 404 when there is no key" do xhr :delete, :revoke_key, id: 1234 - response.should_not be_success - response.status.should == 404 + expect(response).not_to be_success + expect(response.status).to eq(404) end it "delegates to the api key's `regenerate!` method" do @@ -47,9 +47,9 @@ describe Admin::ApiController do context '.create_master_key' do it "creates a record" do - lambda { + expect { xhr :post, :create_master_key - }.should change(ApiKey, :count).by(1) + }.to change(ApiKey, :count).by(1) end end diff --git a/spec/controllers/admin/backups_controller_spec.rb b/spec/controllers/admin/backups_controller_spec.rb index c5cca050b..4faeef1ea 100644 --- a/spec/controllers/admin/backups_controller_spec.rb +++ b/spec/controllers/admin/backups_controller_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" describe Admin::BackupsController do it "is a subclass of AdminController" do - (Admin::BackupsController < Admin::AdminController).should == true + expect(Admin::BackupsController < Admin::AdminController).to eq(true) end let(:backup_filename) { "2014-02-10-065935.tar.gz" } @@ -28,7 +28,7 @@ describe Admin::BackupsController do xhr :get, :index, format: :html - response.should be_success + expect(response).to be_success end end @@ -40,11 +40,11 @@ describe Admin::BackupsController do xhr :get, :index, format: :json - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json[0]["filename"].should == "backup1" - json[1]["filename"].should == "backup2" + expect(json[0]["filename"]).to eq("backup1") + expect(json[1]["filename"]).to eq("backup2") end end @@ -58,7 +58,7 @@ describe Admin::BackupsController do xhr :get, :status - response.should be_success + expect(response).to be_success end end @@ -70,7 +70,7 @@ describe Admin::BackupsController do xhr :post, :create, { with_uploads: false } - response.should be_success + expect(response).to be_success end end @@ -82,7 +82,7 @@ describe Admin::BackupsController do xhr :delete, :cancel - response.should be_success + expect(response).to be_success end end @@ -99,8 +99,8 @@ describe Admin::BackupsController do get :show, id: backup_filename - response.headers['Content-Length'].should == 5 - response.headers['Content-Disposition'].should =~ /attachment; filename/ + expect(response.headers['Content-Length']).to eq(5) + expect(response.headers['Content-Disposition']).to match(/attachment; filename/) end it "returns 404 when the backup does not exist" do @@ -108,7 +108,7 @@ describe Admin::BackupsController do get :show, id: backup_filename - response.should be_not_found + expect(response).to be_not_found end end @@ -121,14 +121,14 @@ describe Admin::BackupsController do Backup.expects(:[]).with(backup_filename).returns(b) b.expects(:remove) xhr :delete, :destroy, id: backup_filename - response.should be_success + expect(response).to be_success end it "doesn't remove the backup if not found" do Backup.expects(:[]).with(backup_filename).returns(nil) b.expects(:remove).never xhr :delete, :destroy, id: backup_filename - response.should_not be_success + expect(response).not_to be_success end end @@ -144,7 +144,7 @@ describe Admin::BackupsController do xhr :get, :logs, format: :html - response.should be_success + expect(response).to be_success end end @@ -155,7 +155,7 @@ describe Admin::BackupsController do xhr :post, :restore, id: backup_filename - response.should be_success + expect(response).to be_success end end @@ -167,7 +167,7 @@ describe Admin::BackupsController do xhr :get, :rollback - response.should be_success + expect(response).to be_success end end @@ -179,7 +179,7 @@ describe Admin::BackupsController do xhr :put, :readonly, enable: true - response.should be_success + expect(response).to be_success end it "disables readonly mode" do @@ -187,7 +187,7 @@ describe Admin::BackupsController do xhr :put, :readonly, enable: false - response.should be_success + expect(response).to be_success end end diff --git a/spec/controllers/admin/badges_controller_spec.rb b/spec/controllers/admin/badges_controller_spec.rb index e5102cafb..94e9c763e 100644 --- a/spec/controllers/admin/badges_controller_spec.rb +++ b/spec/controllers/admin/badges_controller_spec.rb @@ -9,7 +9,7 @@ describe Admin::BadgesController do context 'index' do it 'returns badge index' do xhr :get, :index - response.should be_success + expect(response).to be_success end end @@ -30,46 +30,46 @@ describe Admin::BadgesController do groupings2 = BadgeGrouping.all.order(:position).to_a - groupings2.map{|g| g.name}.should == names - (groupings.map(&:id) - groupings2.map{|g| g.id}).compact.should be_blank + expect(groupings2.map{|g| g.name}).to eq(names) + expect((groupings.map(&:id) - groupings2.map{|g| g.id}).compact).to be_blank - ::JSON.parse(response.body)["badge_groupings"].length.should == groupings2.length + expect(::JSON.parse(response.body)["badge_groupings"].length).to eq(groupings2.length) end end context '.badge_types' do it 'returns success' do xhr :get, :badge_types - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :badge_types - ::JSON.parse(response.body)["badge_types"].should be_present + expect(::JSON.parse(response.body)["badge_types"]).to be_present end end context '.destroy' do it 'returns success' do xhr :delete, :destroy, id: badge.id - response.should be_success + expect(response).to be_success end it 'deletes the badge' do xhr :delete, :destroy, id: badge.id - Badge.where(id: badge.id).count.should eq(0) + expect(Badge.where(id: badge.id).count).to eq(0) end end context '.update' do it 'returns success' do xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: false, enabled: true - response.should be_success + expect(response).to be_success end it 'updates the badge' do xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: true, enabled: true - badge.reload.name.should eq('123456') + expect(badge.reload.name).to eq('123456') end end end diff --git a/spec/controllers/admin/color_schemes_controller_spec.rb b/spec/controllers/admin/color_schemes_controller_spec.rb index 9654d17bf..cebda7572 100644 --- a/spec/controllers/admin/color_schemes_controller_spec.rb +++ b/spec/controllers/admin/color_schemes_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Admin::ColorSchemesController do it "is a subclass of AdminController" do - (described_class < Admin::AdminController).should == true + expect(described_class < Admin::AdminController).to eq(true) end context "while logged in as an admin" do @@ -20,33 +20,33 @@ describe Admin::ColorSchemesController do describe "index" do it "returns success" do xhr :get, :index - response.should be_success + expect(response).to be_success end it "returns JSON" do Fabricate(:color_scheme) xhr :get, :index - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end describe "create" do it "returns success" do xhr :post, :create, valid_params - response.should be_success + expect(response).to be_success end it "returns JSON" do xhr :post, :create, valid_params - ::JSON.parse(response.body)['id'].should be_present + expect(::JSON.parse(response.body)['id']).to be_present end it "returns failure with invalid params" do params = valid_params params[:color_scheme][:colors][0][:hex] = 'cool color please' xhr :post, :create, valid_params - response.should_not be_success - ::JSON.parse(response.body)['errors'].should be_present + expect(response).not_to be_success + expect(::JSON.parse(response.body)['errors']).to be_present end end @@ -56,13 +56,13 @@ describe Admin::ColorSchemesController do it "returns success" do ColorSchemeRevisor.expects(:revise).returns(existing) xhr :put, :update, valid_params.merge(id: existing.id) - response.should be_success + expect(response).to be_success end it "returns JSON" do ColorSchemeRevisor.expects(:revise).returns(existing) xhr :put, :update, valid_params.merge(id: existing.id) - ::JSON.parse(response.body)['id'].should be_present + expect(::JSON.parse(response.body)['id']).to be_present end it "returns failure with invalid params" do @@ -71,8 +71,8 @@ describe Admin::ColorSchemesController do params[:color_scheme][:colors][0][:name] = color_scheme.colors.first.name params[:color_scheme][:colors][0][:hex] = 'cool color please' xhr :put, :update, params - response.should_not be_success - ::JSON.parse(response.body)['errors'].should be_present + expect(response).not_to be_success + expect(::JSON.parse(response.body)['errors']).to be_present end end @@ -83,7 +83,7 @@ describe Admin::ColorSchemesController do expect { xhr :delete, :destroy, id: existing.id }.to change { ColorScheme.count }.by(-1) - response.should be_success + expect(response).to be_success end end end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 97cb8727d..c501fe4c7 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -8,7 +8,7 @@ describe Admin::DashboardController do end it "is a subclass of AdminController" do - (Admin::DashboardController < Admin::AdminController).should == true + expect(Admin::DashboardController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -17,7 +17,7 @@ describe Admin::DashboardController do context '.index' do it 'should be successful' do xhr :get, :index - response.should be_successful + expect(response).to be_successful end context 'version checking is enabled' do @@ -28,7 +28,7 @@ describe Admin::DashboardController do it 'returns discourse version info' do xhr :get, :index json = JSON.parse(response.body) - json['version_check'].should be_present + expect(json['version_check']).to be_present end end @@ -40,7 +40,7 @@ describe Admin::DashboardController do it 'does not return discourse version info' do xhr :get, :index json = JSON.parse(response.body) - json['version_check'].should_not be_present + expect(json['version_check']).not_to be_present end end end @@ -49,7 +49,7 @@ describe Admin::DashboardController do it 'should be successful' do AdminDashboardData.stubs(:fetch_problems).returns([]) xhr :get, :problems - response.should be_successful + expect(response).to be_successful end context 'when there are no problems' do @@ -60,7 +60,7 @@ describe Admin::DashboardController do it 'returns an empty array' do xhr :get, :problems json = JSON.parse(response.body) - json['problems'].size.should == 0 + expect(json['problems'].size).to eq(0) end end @@ -72,9 +72,9 @@ describe Admin::DashboardController do it 'returns an array of strings' do xhr :get, :problems json = JSON.parse(response.body) - json['problems'].size.should == 2 - json['problems'][0].should be_a(String) - json['problems'][1].should be_a(String) + expect(json['problems'].size).to eq(2) + expect(json['problems'][0]).to be_a(String) + expect(json['problems'][1]).to be_a(String) end end end diff --git a/spec/controllers/admin/email_controller_spec.rb b/spec/controllers/admin/email_controller_spec.rb index 1c914714a..2820cb154 100644 --- a/spec/controllers/admin/email_controller_spec.rb +++ b/spec/controllers/admin/email_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::EmailController do it "is a subclass of AdminController" do - (Admin::EmailController < Admin::AdminController).should == true + expect(Admin::EmailController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -33,7 +33,7 @@ describe Admin::EmailController do end subject { response } - it { should be_success } + it { is_expected.to be_success } end context '.skipped' do @@ -42,12 +42,12 @@ describe Admin::EmailController do end subject { response } - it { should be_success } + it { is_expected.to be_success } end context '.test' do it 'raises an error without the email parameter' do - lambda { xhr :post, :test }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :test }.to raise_error(ActionController::ParameterMissing) end context 'with an email address' do @@ -62,7 +62,7 @@ describe Admin::EmailController do context '.preview_digest' do it 'raises an error without the last_seen_at parameter' do - lambda { xhr :get, :preview_digest }.should raise_error(ActionController::ParameterMissing) + expect { xhr :get, :preview_digest }.to raise_error(ActionController::ParameterMissing) end it "previews the digest" do diff --git a/spec/controllers/admin/emojis_controller_spec.rb b/spec/controllers/admin/emojis_controller_spec.rb index 9aa79c44d..dd0e68b85 100644 --- a/spec/controllers/admin/emojis_controller_spec.rb +++ b/spec/controllers/admin/emojis_controller_spec.rb @@ -10,7 +10,7 @@ describe Admin::EmojisController do end it "is a subclass of AdminController" do - (Admin::EmojisController < Admin::AdminController).should == true + expect(Admin::EmojisController < Admin::AdminController).to eq(true) end context "when logged in" do @@ -20,10 +20,10 @@ describe Admin::EmojisController do it "returns a list of custom emojis" do Emoji.expects(:custom).returns([custom_emoji]) xhr :get, :index - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json[0]['name'].should == custom_emoji.name - json[0]['url'].should == custom_emoji.url + expect(json[0]['name']).to eq(custom_emoji.name) + expect(json[0]['url']).to eq(custom_emoji.url) end end @@ -34,7 +34,7 @@ describe Admin::EmojisController do context 'name already exist' do it "throws an error" do xhr :post, :create, { name: "hello", file: "" } - response.should_not be_success + expect(response).not_to be_success end end @@ -42,7 +42,7 @@ describe Admin::EmojisController do it "throws an error" do Emoji.expects(:create_for).returns(nil) xhr :post, :create, { name: "garbage", file: "" } - response.should_not be_success + expect(response).not_to be_success end end @@ -57,10 +57,10 @@ describe Admin::EmojisController do it "creates a custom emoji" do Emoji.expects(:create_for).returns(custom_emoji2) xhr :post, :create, { name: "hello2", file: ""} - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['name'].should == custom_emoji2.name - json['url'].should == custom_emoji2.url + expect(json['name']).to eq(custom_emoji2.name) + expect(json['url']).to eq(custom_emoji2.url) end end @@ -71,7 +71,7 @@ describe Admin::EmojisController do custom_emoji.expects(:remove) Emoji.expects(:custom).returns([custom_emoji]) xhr :delete, :destroy, id: "hello" - response.should be_success + expect(response).to be_success end end end diff --git a/spec/controllers/admin/flags_controller_spec.rb b/spec/controllers/admin/flags_controller_spec.rb index 766523e26..60ab32114 100644 --- a/spec/controllers/admin/flags_controller_spec.rb +++ b/spec/controllers/admin/flags_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::FlagsController do it "is a subclass of AdminController" do - (Admin::FlagsController < Admin::AdminController).should == true + expect(Admin::FlagsController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -16,8 +16,8 @@ describe Admin::FlagsController do xhr :get, :index data = ::JSON.parse(response.body) - data["users"].should == [] - data["posts"].should == [] + expect(data["users"]).to eq([]) + expect(data["posts"]).to eq([]) end it 'returns a valid json payload when some thing is flagged' do diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 5983c985d..45be241b0 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -7,7 +7,7 @@ describe Admin::GroupsController do end it "is a subclass of AdminController" do - (Admin::GroupsController < Admin::AdminController).should == true + expect(Admin::GroupsController < Admin::AdminController).to eq(true) end context ".index" do @@ -18,15 +18,15 @@ describe Admin::GroupsController do group.save xhr :get, :index - response.status.should == 200 - ::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }.should == [{ + expect(response.status).to eq(200) + expect(::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }).to eq([{ "id"=>group.id, "name"=>group.name, "user_count"=>1, "automatic"=>false, "alias_level"=>0, "visible"=>true - }] + }]) end end @@ -36,12 +36,12 @@ describe Admin::GroupsController do it "strip spaces on the group name" do xhr :post, :create, name: " bob " - response.status.should == 200 + expect(response.status).to eq(200) groups = Group.where(name: "bob").to_a - groups.count.should == 1 - groups[0].name.should == "bob" + expect(groups.count).to eq(1) + expect(groups[0].name).to eq("bob") end end @@ -50,11 +50,11 @@ describe Admin::GroupsController do it "ignore name change on automatic group" do xhr :put, :update, id: 1, name: "WAT", visible: "true" - response.should be_success + expect(response).to be_success group = Group.find(1) - group.name.should_not == "WAT" - group.visible.should == true + expect(group.name).not_to eq("WAT") + expect(group.visible).to eq(true) end end @@ -64,15 +64,15 @@ describe Admin::GroupsController do it "returns a 422 if the group is automatic" do group = Fabricate(:group, automatic: true) xhr :delete, :destroy, id: group.id - response.status.should == 422 - Group.where(id: group.id).count.should == 1 + expect(response.status).to eq(422) + expect(Group.where(id: group.id).count).to eq(1) end it "is able to destroy a non-automatic group" do group = Fabricate(:group) xhr :delete, :destroy, id: group.id - response.status.should == 200 - Group.where(id: group.id).count.should == 0 + expect(response.status).to eq(200) + expect(Group.where(id: group.id).count).to eq(0) end end @@ -83,7 +83,7 @@ describe Admin::GroupsController do Group.expects(:refresh_automatic_groups!).returns(true) xhr :post, :refresh_automatic_groups - response.status.should == 200 + expect(response.status).to eq(200) end end @@ -92,7 +92,7 @@ describe Admin::GroupsController do it "cannot add members to automatic groups" do xhr :put, :add_members, group_id: 1, usernames: "l77t" - response.status.should == 422 + expect(response.status).to eq(422) end it "is able to add several members to a group" do @@ -102,9 +102,9 @@ describe Admin::GroupsController do xhr :put, :add_members, group_id: group.id, usernames: [user1.username, user2.username].join(",") - response.should be_success + expect(response).to be_success group.reload - group.users.count.should == 2 + expect(group.users.count).to eq(2) end end @@ -113,7 +113,7 @@ describe Admin::GroupsController do it "cannot remove members from automatic groups" do xhr :put, :remove_member, group_id: 1, user_id: 42 - response.status.should == 422 + expect(response.status).to eq(422) end it "is able to remove a member" do @@ -124,9 +124,9 @@ describe Admin::GroupsController do xhr :delete, :remove_member, group_id: group.id, user_id: user.id - response.should be_success + expect(response).to be_success group.reload - group.users.count.should == 0 + expect(group.users.count).to eq(0) end end diff --git a/spec/controllers/admin/impersonate_controller_spec.rb b/spec/controllers/admin/impersonate_controller_spec.rb index 841e72ff3..5130551ef 100644 --- a/spec/controllers/admin/impersonate_controller_spec.rb +++ b/spec/controllers/admin/impersonate_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::ImpersonateController do it "is a subclass of AdminController" do - (Admin::ImpersonateController < Admin::AdminController).should == true + expect(Admin::ImpersonateController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -13,25 +13,25 @@ describe Admin::ImpersonateController do context 'index' do it 'returns success' do xhr :get, :index - response.should be_success + expect(response).to be_success end end context 'create' do it 'requires a username_or_email parameter' do - -> { xhr :put, :create }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :create }.to raise_error(ActionController::ParameterMissing) end it 'returns 404 when that user does not exist' do xhr :post, :create, username_or_email: 'hedonismbot' - response.status.should == 404 + expect(response.status).to eq(404) end it "raises an invalid access error if the user can't be impersonated" do Guardian.any_instance.expects(:can_impersonate?).with(user).returns(false) xhr :post, :create, username_or_email: user.email - response.should be_forbidden + expect(response).to be_forbidden end context 'success' do @@ -43,17 +43,17 @@ describe Admin::ImpersonateController do it "changes the current user session id" do xhr :post, :create, username_or_email: user.username - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end it "returns success" do xhr :post, :create, username_or_email: user.email - response.should be_success + expect(response).to be_success end it "also works with an email address" do xhr :post, :create, username_or_email: user.email - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb index 5a3cf0ab0..b57ae429a 100644 --- a/spec/controllers/admin/reports_controller_spec.rb +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::ReportsController do it "is a subclass of AdminController" do - (Admin::ReportsController < Admin::AdminController).should == true + expect(Admin::ReportsController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -23,7 +23,7 @@ describe Admin::ReportsController do it "returns 404" do xhr :get, :show, type: invalid_id - response.status.should == 404 + expect(response.status).to eq(404) end end @@ -36,7 +36,7 @@ describe Admin::ReportsController do end it "renders the report as JSON" do - response.status.should == 404 + expect(response.status).to eq(404) end end @@ -47,11 +47,11 @@ describe Admin::ReportsController do end it "renders the report as JSON" do - response.should be_success + expect(response).to be_success end it "renders the report as JSON" do - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end diff --git a/spec/controllers/admin/screened_emails_controller_spec.rb b/spec/controllers/admin/screened_emails_controller_spec.rb index a68661f87..f05b80ce7 100644 --- a/spec/controllers/admin/screened_emails_controller_spec.rb +++ b/spec/controllers/admin/screened_emails_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Admin::ScreenedEmailsController do it "is a subclass of AdminController" do - (Admin::ScreenedEmailsController < Admin::AdminController).should == true + expect(Admin::ScreenedEmailsController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -13,10 +13,10 @@ describe Admin::ScreenedEmailsController do end subject { response } - it { should be_success } + it { is_expected.to be_success } it 'returns JSON' do - ::JSON.parse(subject.body).should be_a(Array) + expect(::JSON.parse(subject.body)).to be_a(Array) end end end diff --git a/spec/controllers/admin/screened_ip_addresses_controller_spec.rb b/spec/controllers/admin/screened_ip_addresses_controller_spec.rb index 528134c9d..dd106862d 100644 --- a/spec/controllers/admin/screened_ip_addresses_controller_spec.rb +++ b/spec/controllers/admin/screened_ip_addresses_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::ScreenedIpAddressesController do it "is a subclass of AdminController" do - (Admin::ScreenedIpAddressesController < Admin::AdminController).should == true + expect(Admin::ScreenedIpAddressesController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -12,8 +12,8 @@ describe Admin::ScreenedIpAddressesController do it 'returns JSON' do xhr :get, :index - response.should be_success - JSON.parse(response.body).should be_a(Array) + expect(response).to be_success + expect(JSON.parse(response.body)).to be_a(Array) end end @@ -32,11 +32,11 @@ describe Admin::ScreenedIpAddressesController do SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(3) xhr :post, :roll_up - response.should be_success + expect(response).to be_success subnet = ScreenedIpAddress.where(ip_address: "1.2.3.0/24").first - subnet.should be_present - subnet.match_count.should == 3 + expect(subnet).to be_present + expect(subnet.match_count).to eq(3) end it "rolls up 1.2.*.* entries" do @@ -52,11 +52,11 @@ describe Admin::ScreenedIpAddressesController do SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(5) xhr :post, :roll_up - response.should be_success + expect(response).to be_success subnet = ScreenedIpAddress.where(ip_address: "1.2.0.0/16").first - subnet.should be_present - subnet.match_count.should == 6 + expect(subnet).to be_present + expect(subnet.match_count).to eq(6) end end diff --git a/spec/controllers/admin/screened_urls_controller_spec.rb b/spec/controllers/admin/screened_urls_controller_spec.rb index 0966ee95d..8d9fce01f 100644 --- a/spec/controllers/admin/screened_urls_controller_spec.rb +++ b/spec/controllers/admin/screened_urls_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Admin::ScreenedUrlsController do it "is a subclass of AdminController" do - (Admin::ScreenedUrlsController < Admin::AdminController).should == true + expect(Admin::ScreenedUrlsController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -13,10 +13,10 @@ describe Admin::ScreenedUrlsController do end subject { response } - it { should be_success } + it { is_expected.to be_success } it 'returns JSON' do - ::JSON.parse(subject.body).should be_a(Array) + expect(::JSON.parse(subject.body)).to be_a(Array) end end end diff --git a/spec/controllers/admin/site_customizations_controller_spec.rb b/spec/controllers/admin/site_customizations_controller_spec.rb index 944c1e374..f8b598b9f 100644 --- a/spec/controllers/admin/site_customizations_controller_spec.rb +++ b/spec/controllers/admin/site_customizations_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::SiteCustomizationsController do it "is a subclass of AdminController" do - (Admin::UsersController < Admin::AdminController).should == true + expect(Admin::UsersController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -15,24 +15,24 @@ describe Admin::SiteCustomizationsController do it 'returns success' do SiteCustomization.create!(name: 'my name', user_id: Fabricate(:user).id, header: "my awesome header", stylesheet: "my awesome css") xhr :get, :index - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :index - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end context ' .create' do it 'returns success' do xhr :post, :create, site_customization: {name: 'my test name'} - response.should be_success + expect(response).to be_success end it 'returns json' do xhr :post, :create, site_customization: {name: 'my test name'} - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end it 'logs the change' do diff --git a/spec/controllers/admin/site_settings_controller_spec.rb b/spec/controllers/admin/site_settings_controller_spec.rb index 030e27c9b..702598c8f 100644 --- a/spec/controllers/admin/site_settings_controller_spec.rb +++ b/spec/controllers/admin/site_settings_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::SiteSettingsController do it "is a subclass of AdminController" do - (Admin::SiteSettingsController < Admin::AdminController).should == true + expect(Admin::SiteSettingsController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -14,12 +14,12 @@ describe Admin::SiteSettingsController do context 'index' do it 'returns success' do xhr :get, :index - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :index - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end diff --git a/spec/controllers/admin/site_text_controller_spec.rb b/spec/controllers/admin/site_text_controller_spec.rb index d6eb57b91..615710564 100644 --- a/spec/controllers/admin/site_text_controller_spec.rb +++ b/spec/controllers/admin/site_text_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::SiteTextController do it "is a subclass of AdminController" do - (Admin::SiteTextController < Admin::AdminController).should == true + expect(Admin::SiteTextController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -16,12 +16,12 @@ describe Admin::SiteTextController do it 'returns success' do xhr :get, :show, id: text_type - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :show, id: text_type - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end end diff --git a/spec/controllers/admin/site_text_types_controller_spec.rb b/spec/controllers/admin/site_text_types_controller_spec.rb index eb1c349e0..d2431f60c 100644 --- a/spec/controllers/admin/site_text_types_controller_spec.rb +++ b/spec/controllers/admin/site_text_types_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::SiteTextTypesController do it "is a subclass of AdminController" do - (Admin::SiteTextTypesController < Admin::AdminController).should == true + expect(Admin::SiteTextTypesController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -14,12 +14,12 @@ describe Admin::SiteTextTypesController do context ' .index' do it 'returns success' do xhr :get, :index - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :index - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end end end diff --git a/spec/controllers/admin/staff_action_logs_controller_spec.rb b/spec/controllers/admin/staff_action_logs_controller_spec.rb index 8decc8b6a..8f638a33d 100644 --- a/spec/controllers/admin/staff_action_logs_controller_spec.rb +++ b/spec/controllers/admin/staff_action_logs_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Admin::StaffActionLogsController do it "is a subclass of AdminController" do - (Admin::StaffActionLogsController < Admin::AdminController).should == true + expect(Admin::StaffActionLogsController < Admin::AdminController).to eq(true) end let!(:user) { log_in(:admin) } @@ -13,10 +13,10 @@ describe Admin::StaffActionLogsController do end subject { response } - it { should be_success } + it { is_expected.to be_success } it 'returns JSON' do - ::JSON.parse(subject.body).should be_a(Array) + expect(::JSON.parse(subject.body)).to be_a(Array) end end end diff --git a/spec/controllers/admin/user_fields_controller_spec.rb b/spec/controllers/admin/user_fields_controller_spec.rb index 1d882821e..6b173cb91 100644 --- a/spec/controllers/admin/user_fields_controller_spec.rb +++ b/spec/controllers/admin/user_fields_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Admin::UserFieldsController do it "is a subclass of AdminController" do - (Admin::UserFieldsController < Admin::AdminController).should == true + expect(Admin::UserFieldsController < Admin::AdminController).to eq(true) end context "when logged in" do @@ -11,10 +11,10 @@ describe Admin::UserFieldsController do context '.create' do it "creates a user field" do - -> { + expect { xhr :post, :create, {user_field: {name: 'hello', description: 'hello desc', field_type: 'text'} } - response.should be_success - }.should change(UserField, :count).by(1) + expect(response).to be_success + }.to change(UserField, :count).by(1) end end @@ -23,9 +23,9 @@ describe Admin::UserFieldsController do it "returns a list of user fields" do xhr :get, :index - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['user_fields'].should be_present + expect(json['user_fields']).to be_present end end @@ -33,10 +33,10 @@ describe Admin::UserFieldsController do let!(:user_field) { Fabricate(:user_field) } it "deletes the user field" do - -> { + expect { xhr :delete, :destroy, id: user_field.id - response.should be_success - }.should change(UserField, :count).by(-1) + expect(response).to be_success + }.to change(UserField, :count).by(-1) end end @@ -45,10 +45,10 @@ describe Admin::UserFieldsController do it "updates the user field" do xhr :put, :update, id: user_field.id, user_field: {name: 'fraggle', field_type: 'confirm', description: 'muppet'} - response.should be_success + expect(response).to be_success user_field.reload - user_field.name.should == 'fraggle' - user_field.field_type.should == 'confirm' + expect(user_field.name).to eq('fraggle') + expect(user_field.field_type).to eq('confirm') end end end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 5ad68e9bb..97434b324 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -4,7 +4,7 @@ require_dependency 'single_sign_on' describe Admin::UsersController do it 'is a subclass of AdminController' do - (Admin::UsersController < Admin::AdminController).should == true + expect(Admin::UsersController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -15,12 +15,12 @@ describe Admin::UsersController do context '.index' do it 'returns success' do xhr :get, :index - response.should be_success + expect(response).to be_success end it 'returns JSON' do xhr :get, :index - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end context 'when showing emails' do @@ -29,17 +29,17 @@ describe Admin::UsersController do xhr :get, :index, show_emails: "true" data = ::JSON.parse(response.body) data.each do |user| - user["email"].should be_present + expect(user["email"]).to be_present end end it "logs only 1 enty" do - UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 0 + expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(0) xhr :get, :index, show_emails: "true" data = ::JSON.parse(response.body) - UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 1 + expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(1) end end @@ -49,14 +49,14 @@ describe Admin::UsersController do context 'an existing user' do it 'returns success' do xhr :get, :show, id: @user.username - response.should be_success + expect(response).to be_success end end context 'an existing user' do it 'returns success' do xhr :get, :show, id: 'foobar' - response.should_not be_success + expect(response).not_to be_success end end end @@ -111,7 +111,7 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false) xhr :put, :approve, user_id: evil_trout.id - response.should be_forbidden + expect(response).to be_forbidden end it 'calls approve' do @@ -129,13 +129,13 @@ describe Admin::UsersController do it 'raises an error unless the user can revoke access' do Guardian.any_instance.expects(:can_revoke_admin?).with(@another_admin).returns(false) xhr :put, :revoke_admin, user_id: @another_admin.id - response.should be_forbidden + expect(response).to be_forbidden end it 'updates the admin flag' do xhr :put, :revoke_admin, user_id: @another_admin.id @another_admin.reload - @another_admin.should_not be_admin + expect(@another_admin).not_to be_admin end end @@ -147,18 +147,18 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_grant_admin?).with(@another_user).returns(false) xhr :put, :grant_admin, user_id: @another_user.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 404 if the username doesn't exist" do xhr :put, :grant_admin, user_id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end it 'updates the admin flag' do xhr :put, :grant_admin, user_id: @another_user.id @another_user.reload - @another_user.should be_admin + expect(@another_user).to be_admin end end @@ -170,18 +170,18 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_change_primary_group?).with(@another_user).returns(false) xhr :put, :primary_group, user_id: @another_user.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 404 if the user doesn't exist" do xhr :put, :primary_group, user_id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end it "changes the user's primary group" do xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: 2 @another_user.reload - @another_user.primary_group_id.should == 2 + expect(@another_user.primary_group_id).to eq(2) end end @@ -193,20 +193,20 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_change_trust_level?).with(@another_user).returns(false) xhr :put, :trust_level, user_id: @another_user.id - response.should_not be_success + expect(response).not_to be_success end it "returns a 404 if the username doesn't exist" do xhr :put, :trust_level, user_id: 123123 - response.should_not be_success + expect(response).not_to be_success end it "upgrades the user's trust level" do StaffActionLogger.any_instance.expects(:log_trust_level_change).with(@another_user, @another_user.trust_level, 2).once xhr :put, :trust_level, user_id: @another_user.id, level: 2 @another_user.reload - @another_user.trust_level.should == 2 - response.should be_success + expect(@another_user.trust_level).to eq(2) + expect(response).to be_success end it "raises no error when demoting a user below their current trust level (locks trust level)" do @@ -217,9 +217,9 @@ describe Admin::UsersController do stat.save! @another_user.update_attributes(trust_level: TrustLevel[1]) xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel[0] - response.should be_success + expect(response).to be_success @another_user.reload - @another_user.trust_level_locked.should == true + expect(@another_user.trust_level_locked).to eq(true) end end @@ -231,13 +231,13 @@ describe Admin::UsersController do it 'raises an error unless the user can revoke access' do Guardian.any_instance.expects(:can_revoke_moderation?).with(@moderator).returns(false) xhr :put, :revoke_moderation, user_id: @moderator.id - response.should be_forbidden + expect(response).to be_forbidden end it 'updates the moderator flag' do xhr :put, :revoke_moderation, user_id: @moderator.id @moderator.reload - @moderator.moderator.should_not == true + expect(@moderator.moderator).not_to eq(true) end end @@ -249,18 +249,18 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_grant_moderation?).with(@another_user).returns(false) xhr :put, :grant_moderation, user_id: @another_user.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 404 if the username doesn't exist" do xhr :put, :grant_moderation, user_id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end it 'updates the moderator flag' do xhr :put, :grant_moderation, user_id: @another_user.id @another_user.reload - @another_user.moderator.should == true + expect(@another_user.moderator).to eq(true) end end @@ -283,10 +283,10 @@ describe Admin::UsersController do Guardian.any_instance.stubs(:can_delete_user?).returns(true) UserDestroyer.any_instance.stubs(:destroy).returns(true) xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].to_i.should == 2 - json['failed'].to_i.should == 0 + expect(json['success'].to_i).to eq(2) + expect(json['failed'].to_i).to eq(0) end context 'failures' do @@ -298,19 +298,19 @@ describe Admin::UsersController do UserDestroyer.any_instance.stubs(:destroy).with(reject_me, anything).returns(false) UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true) xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].to_i.should == 1 - json['failed'].to_i.should == 1 + expect(json['success'].to_i).to eq(1) + expect(json['failed'].to_i).to eq(1) end it 'reports failure due to a user still having posts' do UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError) xhr :delete, :reject_bulk, users: [reject_me.id] - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].to_i.should == 0 - json['failed'].to_i.should == 1 + expect(json['success'].to_i).to eq(0) + expect(json['failed'].to_i).to eq(1) end end end @@ -323,12 +323,12 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_delete_user?).with(@delete_me).returns(false) xhr :delete, :destroy, id: @delete_me.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 403 if the user doesn't exist" do xhr :delete, :destroy, id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end context "user has post" do @@ -343,13 +343,13 @@ describe Admin::UsersController do it "returns an error" do xhr :delete, :destroy, id: @delete_me.id - response.should be_forbidden + expect(response).to be_forbidden end it "doesn't return an error if delete_posts == true" do UserDestroyer.any_instance.expects(:destroy).with(@user, has_entry('delete_posts' => true)).returns(true) xhr :delete, :destroy, id: @delete_me.id, delete_posts: true - response.should be_success + expect(response).to be_success end end @@ -367,9 +367,9 @@ describe Admin::UsersController do it "returns success" do xhr :put, :activate, user_id: @reg_user.id - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].should == "OK" + expect(json['success']).to eq("OK") end end @@ -380,14 +380,14 @@ describe Admin::UsersController do it "returns success" do xhr :put, :log_out, user_id: @reg_user.id - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].should == "OK" + expect(json['success']).to eq("OK") end it "returns 404 when user_id does not exist" do xhr :put, :log_out, user_id: 123123 - response.should_not be_success + expect(response).not_to be_success end end @@ -400,12 +400,12 @@ describe Admin::UsersController do Guardian.any_instance.expects(:can_block_user?).with(@reg_user).returns(false) UserBlocker.expects(:block).never xhr :put, :block, user_id: @reg_user.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 403 if the user doesn't exist" do xhr :put, :block, user_id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end it "punishes the user for spamming" do @@ -422,12 +422,12 @@ describe Admin::UsersController do it "raises an error when the user doesn't have permission" do Guardian.any_instance.expects(:can_unblock_user?).with(@reg_user).returns(false) xhr :put, :unblock, user_id: @reg_user.id - response.should be_forbidden + expect(response).to be_forbidden end it "returns a 403 if the user doesn't exist" do xhr :put, :unblock, user_id: 123123 - response.should be_forbidden + expect(response).to be_forbidden end it "punishes the user for spamming" do @@ -462,20 +462,20 @@ describe Admin::UsersController do it 'should invite admin' do Jobs.expects(:enqueue).with(:user_email, anything).returns(true) xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com' - response.should be_success + expect(response).to be_success u = User.find_by(email: 'bill@bill.com') - u.name.should == "Bill" - u.username.should == "bill22" - u.admin.should == true + expect(u.name).to eq("Bill") + expect(u.username).to eq("bill22") + expect(u.admin).to eq(true) end it "doesn't send the email with send_email falsy" do Jobs.expects(:enqueue).with(:user_email, anything).never xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0' - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json["password_url"].should be_present + expect(json["password_url"]).to be_present end end @@ -507,12 +507,12 @@ describe Admin::UsersController do sso.email = "bob2@bob.com" xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload) - response.should be_success + expect(response).to be_success user.reload - user.email.should == "bob2@bob.com" - user.name.should == "Bill" - user.username.should == "Hokli" + expect(user.email).to eq("bob2@bob.com") + expect(user.name).to eq("Bill") + expect(user.username).to eq("Hokli") end diff --git a/spec/controllers/admin/versions_controller_spec.rb b/spec/controllers/admin/versions_controller_spec.rb index a6ba9fc9c..deca11ecc 100644 --- a/spec/controllers/admin/versions_controller_spec.rb +++ b/spec/controllers/admin/versions_controller_spec.rb @@ -11,7 +11,7 @@ describe Admin::VersionsController do end it "is a subclass of AdminController" do - (Admin::VersionsController < Admin::AdminController).should == true + expect(Admin::VersionsController < Admin::AdminController).to eq(true) end context 'while logged in as an admin' do @@ -21,16 +21,16 @@ describe Admin::VersionsController do describe 'show' do subject { xhr :get, :show } - it { should be_success } + it { is_expected.to be_success } it 'should return the currently available version' do json = JSON.parse(subject.body) - json['latest_version'].should == '1.2.33' + expect(json['latest_version']).to eq('1.2.33') end it "should return the installed version" do json = JSON.parse(subject.body) - json['installed_version'].should == Discourse::VERSION::STRING + expect(json['installed_version']).to eq(Discourse::VERSION::STRING) end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index c927de399..b42d1fa3a 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -14,14 +14,14 @@ describe TopicsController do end it "doesn't store an incoming link when there's no referer" do - lambda { + expect { get :show, id: topic.id - }.should_not change(IncomingLink, :count) + }.not_to change(IncomingLink, :count) end it "doesn't raise an error on a very long link" do set_referer("http://#{'a' * 2000}.com") - lambda { get :show, {id: topic.id} }.should_not raise_error + expect { get :show, {id: topic.id} }.not_to raise_error end describe "has_escaped_fragment?" do @@ -34,7 +34,7 @@ describe TopicsController do it "uses the application layout even with an escaped fragment param" do get :show, {'topic_id' => topic.id, 'slug' => topic.slug, '_escaped_fragment_' => 'true'} - response.should render_template(layout: 'application') + expect(response).to render_template(layout: 'application') assert_select "meta[name=fragment]", false, "it doesn't have the meta tag" end end @@ -46,13 +46,13 @@ describe TopicsController do it "uses the application layout when there's no param" do get :show, topic_id: topic.id, slug: topic.slug - response.should render_template(layout: 'application') + expect(response).to render_template(layout: 'application') assert_select "meta[name=fragment]", true, "it has the meta tag" end it "uses the crawler layout when there's an _escaped_fragment_ param" do get :show, topic_id: topic.id, slug: topic.slug, _escaped_fragment_: 'true' - response.should render_template(layout: 'crawler') + expect(response).to render_template(layout: 'crawler') assert_select "meta[name=fragment]", false, "it doesn't have the meta tag" end end @@ -67,7 +67,7 @@ describe TopicsController do end it "renders with the application layout" do get :show, topic_id: topic.id, slug: topic.slug - response.should render_template(layout: 'application') + expect(response).to render_template(layout: 'application') assert_select "meta[name=fragment]", true, "it has the meta tag" end end @@ -78,7 +78,7 @@ describe TopicsController do end it "renders with the crawler layout" do get :show, topic_id: topic.id, slug: topic.slug - response.should render_template(layout: 'crawler') + expect(response).to render_template(layout: 'crawler') assert_select "meta[name=fragment]", false, "it doesn't have the meta tag" end end @@ -94,7 +94,7 @@ describe TopicsController do get :show, {topic_id: topic.id} - I18n.locale.should == :fr + expect(I18n.locale).to eq(:fr) end it 'is sets the default locale when the setting not enabled' do @@ -103,7 +103,7 @@ describe TopicsController do get :show, {topic_id: topic.id} - I18n.locale.should == :en + expect(I18n.locale).to eq(:en) end end @@ -135,31 +135,31 @@ describe 'api' do it 'allows users with api key to bookmark posts' do PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).once put :bookmark, bookmarked: "true", post_id: post.id, api_key: api_key.key, format: :json - response.should be_success + expect(response).to be_success end it 'raises an error with a user key that does not match an optionally specified username' do PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).never put :bookmark, bookmarked: "true", post_id: post.id, api_key: api_key.key, api_username: 'made_up', format: :json - response.should_not be_success + expect(response).not_to be_success end it 'allows users with a master api key to bookmark posts' do PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).once put :bookmark, bookmarked: "true", post_id: post.id, api_key: master_key.key, api_username: user.username, format: :json - response.should be_success + expect(response).to be_success end it 'disallows phonies to bookmark posts' do PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).never put :bookmark, bookmarked: "true", post_id: post.id, api_key: SecureRandom.hex(32), api_username: user.username, format: :json - response.code.to_i.should == 403 + expect(response.code.to_i).to eq(403) end it 'disallows blank api' do PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).never put :bookmark, bookmarked: "true", post_id: post.id, api_key: "", api_username: user.username, format: :json - response.code.to_i.should == 403 + expect(response.code.to_i).to eq(403) end end end diff --git a/spec/controllers/badges_controller_spec.rb b/spec/controllers/badges_controller_spec.rb index f45ffd507..ab98f35cf 100644 --- a/spec/controllers/badges_controller_spec.rb +++ b/spec/controllers/badges_controller_spec.rb @@ -12,26 +12,26 @@ describe BadgesController do it 'should return a list of all badges' do get :index, format: :json - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["badges"].length.should == Badge.count + expect(parsed["badges"].length).to eq(Badge.count) end end context 'show' do it "should return a badge" do get :show, id: badge.id, format: :json - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["badge"].should be_present + expect(parsed["badge"]).to be_present end it "should mark the notification as viewed" do log_in_user(user) user_badge = BadgeGranter.grant(badge, user) - user_badge.notification.read.should == false + expect(user_badge.notification.read).to eq(false) get :show, id: badge.id, format: :json - user_badge.notification.reload.read.should == true + expect(user_badge.notification.reload.read).to eq(true) end end end diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index 0dd227c4b..9a7d342ae 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -4,7 +4,7 @@ describe CategoriesController do describe "create" do it "requires the user to be logged in" do - lambda { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :create }.to raise_error(Discourse::NotLoggedIn) end describe "logged in" do @@ -15,19 +15,19 @@ describe CategoriesController do it "raises an exception when they don't have permission to create it" do Guardian.any_instance.expects(:can_create?).with(Category, nil).returns(false) xhr :post, :create, name: 'hello', color: 'ff0', text_color: 'fff' - response.should be_forbidden + expect(response).to be_forbidden end it "raises an exception when the name is missing" do - lambda { xhr :post, :create, color: "ff0", text_color: "fff" }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create, color: "ff0", text_color: "fff" }.to raise_error(ActionController::ParameterMissing) end it "raises an exception when the color is missing" do - lambda { xhr :post, :create, name: "hello", text_color: "fff" }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create, name: "hello", text_color: "fff" }.to raise_error(ActionController::ParameterMissing) end it "raises an exception when the text color is missing" do - lambda { xhr :post, :create, name: "hello", color: "ff0" }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create, name: "hello", color: "ff0" }.to raise_error(ActionController::ParameterMissing) end describe "failure" do @@ -36,10 +36,10 @@ describe CategoriesController do xhr :post, :create, name: @category.name, color: "ff0", text_color: "fff" end - it { should_not respond_with(:success) } + it { is_expected.not_to respond_with(:success) } it "returns errors on a duplicate category name" do - response.status.should == 422 + expect(response.status).to eq(422) end end @@ -55,15 +55,15 @@ describe CategoriesController do "staff" => create_post } - response.status.should == 200 + expect(response.status).to eq(200) category = Category.find_by(name: "hello") - category.category_groups.map{|g| [g.group_id, g.permission_type]}.sort.should == [ + expect(category.category_groups.map{|g| [g.group_id, g.permission_type]}.sort).to eq([ [Group[:everyone].id, readonly],[Group[:staff].id,create_post] - ] - category.name.should == "hello" - category.slug.should == "hello-cat" - category.color.should == "ff0" - category.auto_close_hours.should == 72 + ]) + expect(category.name).to eq("hello") + expect(category.slug).to eq("hello-cat") + expect(category.color).to eq("ff0") + expect(category.auto_close_hours).to eq(72) end end end @@ -72,7 +72,7 @@ describe CategoriesController do describe "destroy" do it "requires the user to be logged in" do - lambda { xhr :delete, :destroy, id: "category"}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy, id: "category"}.to raise_error(Discourse::NotLoggedIn) end describe "logged in" do @@ -84,12 +84,12 @@ describe CategoriesController do it "raises an exception if they don't have permission to delete it" do Guardian.any_instance.expects(:can_delete_category?).returns(false) xhr :delete, :destroy, id: @category.slug - response.should be_forbidden + expect(response).to be_forbidden end it "deletes the record" do Guardian.any_instance.expects(:can_delete_category?).returns(true) - lambda { xhr :delete, :destroy, id: @category.slug}.should change(Category, :count).by(-1) + expect { xhr :delete, :destroy, id: @category.slug}.to change(Category, :count).by(-1) end end @@ -97,7 +97,7 @@ describe CategoriesController do describe "upload" do it "requires the user to be logged in" do - lambda { xhr :post, :upload, image_type: 'logo'}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :upload, image_type: 'logo'}.to raise_error(Discourse::NotLoggedIn) end describe "logged in" do @@ -111,17 +111,17 @@ describe CategoriesController do it "raises an error when you don't have permission to upload" do Guardian.any_instance.expects(:can_create?).with(Category).returns(false) xhr :post, :upload, image_type: 'logo', file: upload - response.should be_forbidden + expect(response).to be_forbidden end it "requires the `image_type` param" do - -> { xhr :post, :upload }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :upload }.to raise_error(ActionController::ParameterMissing) end it "calls Upload.create_for" do Upload.expects(:create_for).returns(Upload.new) xhr :post, :upload, image_type: 'logo', file: upload - response.should be_success + expect(response).to be_success end end end @@ -129,7 +129,7 @@ describe CategoriesController do describe "update" do it "requires the user to be logged in" do - lambda { xhr :put, :update, id: 'category'}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :update, id: 'category'}.to raise_error(Discourse::NotLoggedIn) end @@ -144,19 +144,19 @@ describe CategoriesController do it "raises an exception if they don't have permission to edit it" do Guardian.any_instance.expects(:can_edit?).returns(false) xhr :put, :update, id: @category.slug, name: 'hello', color: 'ff0', text_color: 'fff' - response.should be_forbidden + expect(response).to be_forbidden end it "requires a name" do - lambda { xhr :put, :update, id: @category.slug, color: 'fff', text_color: '0ff' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :update, id: @category.slug, color: 'fff', text_color: '0ff' }.to raise_error(ActionController::ParameterMissing) end it "requires a color" do - lambda { xhr :put, :update, id: @category.slug, name: 'asdf', text_color: '0ff' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :update, id: @category.slug, name: 'asdf', text_color: '0ff' }.to raise_error(ActionController::ParameterMissing) end it "requires a text color" do - lambda { xhr :put, :update, id: @category.slug, name: 'asdf', color: 'fff' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :update, id: @category.slug, name: 'asdf', color: 'fff' }.to raise_error(ActionController::ParameterMissing) end describe "failure" do @@ -166,11 +166,11 @@ describe CategoriesController do end it "returns errors on a duplicate category name" do - response.should_not be_success + expect(response).not_to be_success end it "returns errors on a duplicate category name" do - response.code.to_i.should == 422 + expect(response.code.to_i).to eq(422) end end @@ -187,15 +187,15 @@ describe CategoriesController do "staff" => create_post } - response.status.should == 200 + expect(response.status).to eq(200) @category.reload - @category.category_groups.map{|g| [g.group_id, g.permission_type]}.sort.should == [ + expect(@category.category_groups.map{|g| [g.group_id, g.permission_type]}.sort).to eq([ [Group[:everyone].id, readonly],[Group[:staff].id,create_post] - ] - @category.name.should == "hello" - @category.slug.should == "hello-category" - @category.color.should == "ff0" - @category.auto_close_hours.should == 72 + ]) + expect(@category.name).to eq("hello") + expect(@category.slug).to eq("hello-category") + expect(@category.color).to eq("ff0") + expect(@category.auto_close_hours).to eq(72) end end end @@ -205,7 +205,7 @@ describe CategoriesController do describe 'update_slug' do it 'requires the user to be logged in' do - lambda { xhr :put, :update_slug, category_id: 'category'}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :update_slug, category_id: 'category'}.to raise_error(Discourse::NotLoggedIn) end describe 'logged in' do @@ -218,26 +218,26 @@ describe CategoriesController do it 'rejects blank' do xhr :put, :update_slug, category_id: @category.id, slug: nil - response.status.should == 422 + expect(response.status).to eq(422) end it 'accepts valid custom slug' do xhr :put, :update_slug, category_id: @category.id, slug: 'valid-slug' - response.should be_success + expect(response).to be_success category = Category.find(@category.id) - category.slug.should == 'valid-slug' + expect(category.slug).to eq('valid-slug') end it 'accepts not well formed custom slug' do xhr :put, :update_slug, category_id: @category.id, slug: ' valid slug' - response.should be_success + expect(response).to be_success category = Category.find(@category.id) - category.slug.should == 'valid-slug' + expect(category.slug).to eq('valid-slug') end it 'rejects invalid custom slug' do xhr :put, :update_slug, category_id: @category.id, slug: ' ' - response.status.should == 422 + expect(response.status).to eq(422) end end end diff --git a/spec/controllers/clicks_controller_spec.rb b/spec/controllers/clicks_controller_spec.rb index 6d88633d7..c86b1af45 100644 --- a/spec/controllers/clicks_controller_spec.rb +++ b/spec/controllers/clicks_controller_spec.rb @@ -6,12 +6,12 @@ describe ClicksController do context 'missing params' do it 'raises an error without the url param' do - lambda { xhr :get, :track, post_id: 123 }.should raise_error(ActionController::ParameterMissing) + expect { xhr :get, :track, post_id: 123 }.to raise_error(ActionController::ParameterMissing) end it "redirects to the url even without the topic_id or post_id params" do xhr :get, :track, url: 'http://google.com' - response.should_not be_redirect + expect(response).not_to be_redirect end end @@ -26,7 +26,7 @@ describe ClicksController do it "doesn't redirect" do TopicLinkClick.expects(:create_from).returns(nil) xhr :get, :track, url: 'http://discourse.org', post_id: 123 - response.should_not be_redirect + expect(response).not_to be_redirect end end @@ -42,25 +42,25 @@ describe ClicksController do it 'calls create_from' do TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1').returns(url) xhr :get, :track, url: url, post_id: 123 - response.should redirect_to(url) + expect(response).to redirect_to(url) end it 'redirects to the url' do TopicLinkClick.stubs(:create_from).returns(url) xhr :get, :track, url: url, post_id: 123 - response.should redirect_to(url) + expect(response).to redirect_to(url) end it 'will pass the user_id to create_from' do TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1').returns(url) xhr :get, :track, url: url, post_id: 123 - response.should redirect_to(url) + expect(response).to redirect_to(url) end it "doesn't redirect with the redirect=false param" do TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1', 'redirect' => 'false').returns(url) xhr :get, :track, url: url, post_id: 123, redirect: 'false' - response.should_not be_redirect + expect(response).not_to be_redirect end end @@ -69,7 +69,7 @@ describe ClicksController do it 'calls create_from' do TopicLinkClick.expects(:create_from).with('url' => url, 'topic_id' => '789', 'ip' => '192.168.0.1').returns(url) xhr :get, :track, url: url, topic_id: 789 - response.should redirect_to(url) + expect(response).to redirect_to(url) end end diff --git a/spec/controllers/composer_messages_controller_spec.rb b/spec/controllers/composer_messages_controller_spec.rb index 45aafd94e..4c7b77fe2 100644 --- a/spec/controllers/composer_messages_controller_spec.rb +++ b/spec/controllers/composer_messages_controller_spec.rb @@ -5,7 +5,7 @@ describe ComposerMessagesController do context '.index' do it 'requires you to be logged in' do - lambda { xhr :get, :index }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :get, :index }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do @@ -14,7 +14,7 @@ describe ComposerMessagesController do it 'redirects to your user preferences' do xhr :get, :index - response.should be_success + expect(response).to be_success end it 'delegates args to the finder' do diff --git a/spec/controllers/draft_controller_spec.rb b/spec/controllers/draft_controller_spec.rb index de5b2ea30..86bc5a9b6 100644 --- a/spec/controllers/draft_controller_spec.rb +++ b/spec/controllers/draft_controller_spec.rb @@ -3,20 +3,20 @@ require 'spec_helper' describe DraftController do it 'requires you to be logged in' do - lambda { post :update }.should raise_error(Discourse::NotLoggedIn) + expect { post :update }.to raise_error(Discourse::NotLoggedIn) end it 'saves a draft on update' do user = log_in post :update, draft_key: 'xyz', data: 'my data', sequence: 0 - Draft.get(user, 'xyz', 0).should == 'my data' + expect(Draft.get(user, 'xyz', 0)).to eq('my data') end it 'destroys drafts when required' do user = log_in Draft.set(user, 'xxx', 0, 'hi') delete :destroy, draft_key: 'xxx', sequence: 0 - Draft.get(user, 'xxx', 0).should == nil + expect(Draft.get(user, 'xxx', 0)).to eq(nil) end end diff --git a/spec/controllers/email_controller_spec.rb b/spec/controllers/email_controller_spec.rb index e67ce633f..65dc32b5b 100644 --- a/spec/controllers/email_controller_spec.rb +++ b/spec/controllers/email_controller_spec.rb @@ -5,7 +5,7 @@ describe EmailController do context '.preferences_redirect' do it 'requires you to be logged in' do - lambda { get :preferences_redirect }.should raise_error(Discourse::NotLoggedIn) + expect { get :preferences_redirect }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do @@ -13,7 +13,7 @@ describe EmailController do it 'redirects to your user preferences' do get :preferences_redirect - response.should redirect_to("/users/#{user.username}/preferences") + expect(response).to redirect_to("/users/#{user.username}/preferences") end end @@ -30,7 +30,7 @@ describe EmailController do end it 'subscribes the user' do - user.email_digests.should == true + expect(user.email_digests).to eq(true) end end @@ -47,11 +47,11 @@ describe EmailController do end it 'unsubscribes the user' do - user.email_digests.should == false + expect(user.email_digests).to eq(false) end it "sets the appropriate instance variables" do - assigns(:success).should be_present + expect(assigns(:success)).to be_present end end @@ -61,7 +61,7 @@ describe EmailController do end it "sets the appropriate instance variables" do - assigns(:success).should be_blank + expect(assigns(:success)).to be_blank end end @@ -74,12 +74,12 @@ describe EmailController do end it 'does not unsubscribe the user' do - user.email_digests.should == true + expect(user.email_digests).to eq(true) end it 'sets the appropriate instance variables' do - assigns(:success).should be_blank - assigns(:different_user).should be_present + expect(assigns(:success)).to be_blank + expect(assigns(:different_user)).to be_present end end @@ -92,17 +92,17 @@ describe EmailController do end it 'unsubscribes the user' do - user.email_digests.should == false + expect(user.email_digests).to eq(false) end it 'sets the appropriate instance variables' do - assigns(:success).should be_present + expect(assigns(:success)).to be_present end end it "sets not_found when the key didn't match anything" do get :unsubscribe, key: 'asdfasdf' - assigns(:not_found).should == true + expect(assigns(:not_found)).to eq(true) end end diff --git a/spec/controllers/embed_controller_spec.rb b/spec/controllers/embed_controller_spec.rb index 02448a1b5..e68965d9b 100644 --- a/spec/controllers/embed_controller_spec.rb +++ b/spec/controllers/embed_controller_spec.rb @@ -7,13 +7,13 @@ describe EmbedController do it "is 404 without an embed_url" do get :comments - response.should_not be_success + expect(response).not_to be_success end it "raises an error with a missing host" do SiteSetting.stubs(:embeddable_host).returns(nil) get :comments, embed_url: embed_url - response.should_not be_success + expect(response).not_to be_success end context "with a host" do @@ -23,7 +23,7 @@ describe EmbedController do it "raises an error with no referer" do get :comments, embed_url: embed_url - response.should_not be_success + expect(response).not_to be_success end context "success" do @@ -33,8 +33,8 @@ describe EmbedController do end after do - response.should be_success - response.headers['X-Frame-Options'].should == "ALLOWALL" + expect(response).to be_success + expect(response.headers['X-Frame-Options']).to eq("ALLOWALL") end it "tells the topic retriever to work when no previous embed is found" do diff --git a/spec/controllers/export_csv_controller_spec.rb b/spec/controllers/export_csv_controller_spec.rb index 1b9a7337a..49a9b36b9 100644 --- a/spec/controllers/export_csv_controller_spec.rb +++ b/spec/controllers/export_csv_controller_spec.rb @@ -11,19 +11,19 @@ describe ExportCsvController do it "enqueues export job" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "user_archive", user_id: @user.id)) xhr :post, :export_entity, entity: "user_archive", entity_type: "user" - response.should be_success + expect(response).to be_success end it "should not enqueue export job if rate limit is reached" do Jobs::ExportCsvFile.any_instance.expects(:execute).never UserExport.create(export_type: "user", user_id: @user.id) xhr :post, :export_entity, entity: "user_archive", entity_type: "user" - response.should_not be_success + expect(response).not_to be_success end it "returns 404 when normal user tries to export admin entity" do xhr :post, :export_entity, entity: "staff_action", entity_type: "admin" - response.should_not be_success + expect(response).not_to be_success end end @@ -36,18 +36,18 @@ describe ExportCsvController do UserExport.expects(:get_download_path).with(file_name).returns(export) subject.expects(:send_file).with(export) get :show, id: file_name - response.should be_success + expect(response).to be_success end it "returns 404 when the user tries to export another user's csv file" do get :show, id: export_filename - response.should be_not_found + expect(response).to be_not_found end it "returns 404 when the export file does not exist" do UserExport.expects(:get_download_path).returns(nil) get :show, id: export_filename - response.should be_not_found + expect(response).to be_not_found end end end @@ -60,14 +60,14 @@ describe ExportCsvController do it "enqueues export job" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id)) xhr :post, :export_entity, entity: "staff_action", entity_type: "admin" - response.should be_success + expect(response).to be_success end it "should not rate limit export for staff" do Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id)) UserExport.create(export_type: "admin", user_id: @admin.id) xhr :post, :export_entity, entity: "staff_action", entity_type: "admin" - response.should be_success + expect(response).to be_success end end @@ -80,13 +80,13 @@ describe ExportCsvController do UserExport.expects(:get_download_path).with(file_name).returns(export) subject.expects(:send_file).with(export) get :show, id: file_name - response.should be_success + expect(response).to be_success end it "returns 404 when the export file does not exist" do UserExport.expects(:get_download_path).returns(nil) get :show, id: export_filename - response.should be_not_found + expect(response).to be_not_found end end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index e70d96949..60f63487f 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -7,21 +7,21 @@ describe GroupsController do it "ensures the group can be seen" do Guardian.any_instance.expects(:can_see?).with(group).returns(false) xhr :get, :show, id: group.name - response.should_not be_success + expect(response).not_to be_success end it "responds with JSON" do Guardian.any_instance.expects(:can_see?).with(group).returns(true) xhr :get, :show, id: group.name - response.should be_success - ::JSON.parse(response.body)['basic_group']['id'].should == group.id + expect(response).to be_success + expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id) end it "works even with an upper case group name" do Guardian.any_instance.expects(:can_see?).with(group).returns(true) xhr :get, :show, id: group.name.upcase - response.should be_success - ::JSON.parse(response.body)['basic_group']['id'].should == group.id + expect(response).to be_success + expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id) end end @@ -29,14 +29,14 @@ describe GroupsController do it "ensures the group can be seen" do Guardian.any_instance.expects(:can_see?).with(group).returns(false) xhr :get, :counts, group_id: group.name - response.should_not be_success + expect(response).not_to be_success end it "performs the query and responds with JSON" do Guardian.any_instance.expects(:can_see?).with(group).returns(true) Group.any_instance.expects(:posts_for).returns(Group.none) xhr :get, :counts, group_id: group.name - response.should be_success + expect(response).to be_success end end @@ -44,14 +44,14 @@ describe GroupsController do it "ensures the group can be seen" do Guardian.any_instance.expects(:can_see?).with(group).returns(false) xhr :get, :posts, group_id: group.name - response.should_not be_success + expect(response).not_to be_success end it "calls `posts_for` and responds with JSON" do Guardian.any_instance.expects(:can_see?).with(group).returns(true) Group.any_instance.expects(:posts_for).returns(Group.none) xhr :get, :posts, group_id: group.name - response.should be_success + expect(response).to be_success end end @@ -59,13 +59,13 @@ describe GroupsController do it "ensures the group can be seen" do Guardian.any_instance.expects(:can_see?).with(group).returns(false) xhr :get, :members, group_id: group.name - response.should_not be_success + expect(response).not_to be_success end it "calls `posts_for` and responds with JSON" do Guardian.any_instance.expects(:can_see?).with(group).returns(true) xhr :get, :posts, group_id: group.name - response.should be_success + expect(response).to be_success end # Pending until we fix group truncation @@ -74,14 +74,14 @@ describe GroupsController do usernames = group.users.map{ |m| m['username'] }.sort xhr :get, :members, group_id: group.name, limit: 3 - response.should be_success + expect(response).to be_success members = JSON.parse(response.body) - members.map{ |m| m['username'] }.should eq(usernames[0..2]) + expect(members.map{ |m| m['username'] }).to eq(usernames[0..2]) xhr :get, :members, group_id: group.name, limit: 3, offset: 3 - response.should be_success + expect(response).to be_success members = JSON.parse(response.body) - members.map{ |m| m['username'] }.should eq(usernames[3..4]) + expect(members.map{ |m| m['username'] }).to eq(usernames[3..4]) end end end diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 980dadea2..f5ce32a6f 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -5,9 +5,9 @@ describe InvitesController do context '.destroy' do it 'requires you to be logged in' do - lambda { + expect { delete :destroy, email: 'jake@adventuretime.ooo' - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -17,15 +17,15 @@ describe InvitesController do it 'raises an error when the email is missing' do - lambda { delete :destroy }.should raise_error(ActionController::ParameterMissing) + expect { delete :destroy }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the email cannot be found" do - lambda { delete :destroy, email: 'finn@adventuretime.ooo' }.should raise_error(Discourse::InvalidParameters) + expect { delete :destroy, email: 'finn@adventuretime.ooo' }.to raise_error(Discourse::InvalidParameters) end it 'raises an error when the invite is not yours' do - lambda { delete :destroy, email: another_invite.email }.should raise_error(Discourse::InvalidParameters) + expect { delete :destroy, email: another_invite.email }.to raise_error(Discourse::InvalidParameters) end it "destroys the invite" do @@ -39,9 +39,9 @@ describe InvitesController do context '.create' do it 'requires you to be logged in' do - lambda { + expect { post :create, email: 'jake@adventuretime.ooo' - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -50,7 +50,7 @@ describe InvitesController do it "fails if you can't invite to the forum" do log_in post :create, email: email - response.should_not be_success + expect(response).not_to be_success end it "fails for normal user if invite email already exists" do @@ -58,15 +58,15 @@ describe InvitesController do invite = Invite.invite_by_email("invite@example.com", user) invite.reload post :create, email: invite.email - response.should_not be_success + expect(response).not_to be_success end it "allows admins to invite to groups" do group = Fabricate(:group) log_in(:admin) post :create, email: email, group_names: group.name - response.should be_success - Invite.find_by(email: email).invited_groups.count.should == 1 + expect(response).to be_success + expect(Invite.find_by(email: email).invited_groups.count).to eq(1) end it "allows admin to send multiple invites to same email" do @@ -74,7 +74,7 @@ describe InvitesController do invite = Invite.invite_by_email("invite@example.com", user) invite.reload post :create, email: invite.email - response.should be_success + expect(response).to be_success end end @@ -88,11 +88,11 @@ describe InvitesController do end it "redirects to the root" do - response.should redirect_to("/") + expect(response).to redirect_to("/") end it "should not change the session" do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end end @@ -105,11 +105,11 @@ describe InvitesController do end it "redirects to the root" do - response.should redirect_to("/") + expect(response).to redirect_to("/") end it "should not change the session" do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end end @@ -133,11 +133,11 @@ describe InvitesController do end it 'logs in the user' do - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end it 'redirects to the first topic the user was invited to' do - response.should redirect_to(topic.relative_url) + expect(response).to redirect_to(topic.relative_url) end end @@ -179,9 +179,9 @@ describe InvitesController do context '.create_disposable_invite' do it 'requires you to be logged in' do - lambda { + expect { post :create, email: 'jake@adventuretime.ooo' - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in as normal user' do @@ -190,7 +190,7 @@ describe InvitesController do it "does not create disposable invitation" do log_in post :create_disposable_invite, email: user.email - response.should_not be_success + expect(response).not_to be_success end end @@ -202,29 +202,29 @@ describe InvitesController do it "creates disposable invitation" do post :create_disposable_invite, email: user.email - response.should be_success - Invite.where(invited_by_id: user.id).count.should == 1 + expect(response).to be_success + expect(Invite.where(invited_by_id: user.id).count).to eq(1) end it "creates multiple disposable invitations" do post :create_disposable_invite, email: user.email, quantity: 10 - response.should be_success - Invite.where(invited_by_id: user.id).count.should == 10 + expect(response).to be_success + expect(Invite.where(invited_by_id: user.id).count).to eq(10) end it "allows group invite" do group = Fabricate(:group) post :create_disposable_invite, email: user.email, group_names: group.name - response.should be_success - Invite.find_by(invited_by_id: user.id).invited_groups.count.should == 1 + expect(response).to be_success + expect(Invite.find_by(invited_by_id: user.id).invited_groups.count).to eq(1) end it "allows multiple group invite" do group_1 = Fabricate(:group, name: "security") group_2 = Fabricate(:group, name: "support") post :create_disposable_invite, email: user.email, group_names: "security,support" - response.should be_success - Invite.find_by(invited_by_id: user.id).invited_groups.count.should == 2 + expect(response).to be_success + expect(Invite.find_by(invited_by_id: user.id).invited_groups.count).to eq(2) end end @@ -239,11 +239,11 @@ describe InvitesController do end it "redirects to the root" do - response.should redirect_to("/") + expect(response).to redirect_to("/") end it "should not change the session" do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end end @@ -271,7 +271,7 @@ describe InvitesController do end it 'logs in user' do - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end @@ -283,9 +283,9 @@ describe InvitesController do context '.resend_invite' do it 'requires you to be logged in' do - lambda { + expect { delete :resend_invite, email: 'first_name@example.com' - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -294,15 +294,15 @@ describe InvitesController do let(:another_invite) { Fabricate(:invite, email: 'last_name@example.com') } it 'raises an error when the email is missing' do - lambda { post :resend_invite }.should raise_error(ActionController::ParameterMissing) + expect { post :resend_invite }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the email cannot be found" do - lambda { post :resend_invite, email: 'first_name@example.com' }.should raise_error(Discourse::InvalidParameters) + expect { post :resend_invite, email: 'first_name@example.com' }.to raise_error(Discourse::InvalidParameters) end it 'raises an error when the invite is not yours' do - lambda { post :resend_invite, email: another_invite.email }.should raise_error(Discourse::InvalidParameters) + expect { post :resend_invite, email: another_invite.email }.to raise_error(Discourse::InvalidParameters) end it "resends the invite" do @@ -316,9 +316,9 @@ describe InvitesController do context '.check_csv_chunk' do it 'requires you to be logged in' do - lambda { + expect { post :check_csv_chunk - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -330,7 +330,7 @@ describe InvitesController do it "fails if you can't bulk invite to the forum" do log_in post :check_csv_chunk, resumableChunkNumber: resumableChunkNumber, resumableCurrentChunkSize: resumableCurrentChunkSize.to_i, resumableIdentifier: resumableIdentifier, resumableFilename: resumableFilename - response.should_not be_success + expect(response).not_to be_success end end @@ -339,9 +339,9 @@ describe InvitesController do context '.upload_csv_chunk' do it 'requires you to be logged in' do - lambda { + expect { post :upload_csv_chunk - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -361,13 +361,13 @@ describe InvitesController do it "fails if you can't bulk invite to the forum" do log_in post :upload_csv_chunk, file: file, resumableChunkNumber: resumableChunkNumber.to_i, resumableChunkSize: resumableChunkSize.to_i, resumableCurrentChunkSize: resumableCurrentChunkSize.to_i, resumableTotalSize: resumableTotalSize.to_i, resumableType: resumableType, resumableIdentifier: resumableIdentifier, resumableFilename: resumableFilename - response.should_not be_success + expect(response).not_to be_success end it "allows admins to bulk invite" do log_in(:admin) post :upload_csv_chunk, file: file, resumableChunkNumber: resumableChunkNumber.to_i, resumableChunkSize: resumableChunkSize.to_i, resumableCurrentChunkSize: resumableCurrentChunkSize.to_i, resumableTotalSize: resumableTotalSize.to_i, resumableType: resumableType, resumableIdentifier: resumableIdentifier, resumableFilename: resumableFilename - response.should be_success + expect(response).to be_success end end diff --git a/spec/controllers/list_controller_spec.rb b/spec/controllers/list_controller_spec.rb index 49184a289..05ec93c3a 100644 --- a/spec/controllers/list_controller_spec.rb +++ b/spec/controllers/list_controller_spec.rb @@ -16,7 +16,7 @@ describe ListController do (Discourse.anonymous_filters - [:categories]).each do |filter| context "#{filter}" do before { xhr :get, filter } - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } end end @@ -30,9 +30,9 @@ describe ListController do p = create_post xhr :get, :latest, format: :json, topic_ids: "#{p.topic_id}" - response.should be_success + expect(response).to be_success parsed = JSON.parse(response.body) - parsed["topic_list"]["topics"].length.should == 1 + expect(parsed["topic_list"]["topics"].length).to eq(1) end end @@ -43,8 +43,8 @@ describe ListController do it 'renders RSS' do get "#{filter}_feed", format: :rss - response.should be_success - response.content_type.should == 'application/rss+xml' + expect(response).to be_success + expect(response.content_type).to eq('application/rss+xml') end end @@ -62,7 +62,7 @@ describe ListController do xhr :get, :category_latest, category: category.slug end - it { should_not respond_with(:success) } + it { is_expected.not_to respond_with(:success) } end context 'with access to see the category' do @@ -70,7 +70,7 @@ describe ListController do xhr :get, :category_latest, category: category.slug end - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } end context 'with a link that includes an id' do @@ -78,7 +78,7 @@ describe ListController do xhr :get, :category_latest, category: "#{category.id}-#{category.slug}" end - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } end context 'another category exists with a number at the beginning of its name' do @@ -89,10 +89,10 @@ describe ListController do xhr :get, :category_latest, category: other_category.slug end - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } it 'uses the correct category' do - assigns(:category).should == other_category + expect(assigns(:category)).to eq(other_category) end end @@ -104,7 +104,7 @@ describe ListController do xhr :get, :category_latest, parent_category: category.slug, category: sub_category.slug end - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } end context 'when child is requested with the wrong parent' do @@ -112,7 +112,7 @@ describe ListController do xhr :get, :category_latest, parent_category: 'not_the_right_slug', category: sub_category.slug end - it { should_not respond_with(:success) } + it { is_expected.not_to respond_with(:success) } end end @@ -120,8 +120,8 @@ describe ListController do describe 'feed' do it 'renders RSS' do get :category_feed, category: category.slug, format: :rss - response.should be_success - response.content_type.should == 'application/rss+xml' + expect(response).to be_success + expect(response.content_type).to eq('application/rss+xml') end end end @@ -132,7 +132,7 @@ describe ListController do it "should respond with a list" do xhr :get, :topics_by, username: @user.username - response.should be_success + expect(response).to be_success end end @@ -142,13 +142,13 @@ describe ListController do it "raises an error when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(false) xhr :get, :private_messages, username: @user.username - response.should be_forbidden + expect(response).to be_forbidden end it "succeeds when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(true) xhr :get, :private_messages, username: @user.username - response.should be_success + expect(response).to be_success end end @@ -158,13 +158,13 @@ describe ListController do it "raises an error when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(false) xhr :get, :private_messages_sent, username: @user.username - response.should be_forbidden + expect(response).to be_forbidden end it "succeeds when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(true) xhr :get, :private_messages_sent, username: @user.username - response.should be_success + expect(response).to be_success end end @@ -174,19 +174,19 @@ describe ListController do it "raises an error when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(false) xhr :get, :private_messages_unread, username: @user.username - response.should be_forbidden + expect(response).to be_forbidden end it "succeeds when can_see_private_messages? is false " do Guardian.any_instance.expects(:can_see_private_messages?).returns(true) xhr :get, :private_messages_unread, username: @user.username - response.should be_success + expect(response).to be_success end end context 'read' do it 'raises an error when not logged in' do - lambda { xhr :get, :read }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :get, :read }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do @@ -195,32 +195,32 @@ describe ListController do xhr :get, :read end - it { should respond_with(:success) } + it { is_expected.to respond_with(:success) } end end describe "best_periods_for" do it "returns yearly for more than 180 days" do - ListController.best_periods_for(nil).should == [:yearly] - ListController.best_periods_for(180.days.ago).should == [:yearly] + expect(ListController.best_periods_for(nil)).to eq([:yearly]) + expect(ListController.best_periods_for(180.days.ago)).to eq([:yearly]) end it "includes monthly when less than 180 days and more than 35 days" do (35...180).each do |date| - ListController.best_periods_for(date.days.ago).should == [:monthly, :yearly] + expect(ListController.best_periods_for(date.days.ago)).to eq([:monthly, :yearly]) end end it "includes weekly when less than 35 days and more than 8 days" do (8...35).each do |date| - ListController.best_periods_for(date.days.ago).should == [:weekly, :monthly, :yearly] + expect(ListController.best_periods_for(date.days.ago)).to eq([:weekly, :monthly, :yearly]) end end it "includes daily when less than 8 days" do (0...8).each do |date| - ListController.best_periods_for(date.days.ago).should == [:daily, :weekly, :monthly, :yearly] + expect(ListController.best_periods_for(date.days.ago)).to eq([:daily, :weekly, :monthly, :yearly]) end end diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index d326c8c8e..cb9771447 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -7,51 +7,51 @@ describe NotificationsController do it 'should succeed for recent' do xhr :get, :recent - response.should be_success + expect(response).to be_success end it 'should succeed for history' do xhr :get, :history - response.should be_success + expect(response).to be_success end it 'should succeed for history' do xhr :get, :reset_new - response.should be_success + expect(response).to be_success end it 'should mark notifications as viewed' do notification = Fabricate(:notification, user: user) - user.reload.unread_notifications.should == 1 - user.reload.total_unread_notifications.should == 1 + expect(user.reload.unread_notifications).to eq(1) + expect(user.reload.total_unread_notifications).to eq(1) xhr :get, :recent - user.reload.unread_notifications.should == 0 - user.reload.total_unread_notifications.should == 1 + expect(user.reload.unread_notifications).to eq(0) + expect(user.reload.total_unread_notifications).to eq(1) end it 'should not mark notifications as viewed if silent param is present' do notification = Fabricate(:notification, user: user) - user.reload.unread_notifications.should == 1 - user.reload.total_unread_notifications.should == 1 + expect(user.reload.unread_notifications).to eq(1) + expect(user.reload.total_unread_notifications).to eq(1) xhr :get, :recent, silent: true - user.reload.unread_notifications.should == 1 - user.reload.total_unread_notifications.should == 1 + expect(user.reload.unread_notifications).to eq(1) + expect(user.reload.total_unread_notifications).to eq(1) end it "updates the `read` status" do notification = Fabricate(:notification, user: user) - user.reload.unread_notifications.should == 1 - user.reload.total_unread_notifications.should == 1 + expect(user.reload.unread_notifications).to eq(1) + expect(user.reload.total_unread_notifications).to eq(1) xhr :put, :reset_new user.reload - user.reload.unread_notifications.should == 0 - user.reload.total_unread_notifications.should == 0 + expect(user.reload.unread_notifications).to eq(0) + expect(user.reload.total_unread_notifications).to eq(0) end end context 'when not logged in' do it 'should raise an error' do - lambda { xhr :get, :recent }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :get, :recent }.to raise_error(Discourse::NotLoggedIn) end end diff --git a/spec/controllers/onebox_controller_spec.rb b/spec/controllers/onebox_controller_spec.rb index 94fda6fd4..12eaa3103 100644 --- a/spec/controllers/onebox_controller_spec.rb +++ b/spec/controllers/onebox_controller_spec.rb @@ -19,11 +19,11 @@ describe OneboxController do end it 'returns success' do - response.should be_success + expect(response).to be_success end it 'returns the onebox response in the body' do - response.body.should == body + expect(response.body).to eq(body) end end @@ -33,13 +33,13 @@ describe OneboxController do it "returns 404 if the onebox is nil" do Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(nil) xhr :get, :show, url: url - response.response_code.should == 404 + expect(response.response_code).to eq(404) end it "returns 404 if the onebox is an empty string" do Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(" \t ") xhr :get, :show, url: url - response.response_code.should == 404 + expect(response.response_code).to eq(404) end end diff --git a/spec/controllers/permalinks_controller_spec.rb b/spec/controllers/permalinks_controller_spec.rb index afc50e364..2cf79a93c 100644 --- a/spec/controllers/permalinks_controller_spec.rb +++ b/spec/controllers/permalinks_controller_spec.rb @@ -6,13 +6,13 @@ describe PermalinksController do permalink = Fabricate(:permalink) Permalink.any_instance.stubs(:target_url).returns('/t/the-topic-slug/42') get :show, url: permalink.url - response.should redirect_to('/t/the-topic-slug/42') - response.status.should == 301 + expect(response).to redirect_to('/t/the-topic-slug/42') + expect(response.status).to eq(301) end it 'return 404 if permalink record does not exist' do get :show, url: '/not/a/valid/url' - response.status.should == 404 + expect(response.status).to eq(404) end end diff --git a/spec/controllers/post_actions_controller_spec.rb b/spec/controllers/post_actions_controller_spec.rb index f87a21958..09e00b3b5 100644 --- a/spec/controllers/post_actions_controller_spec.rb +++ b/spec/controllers/post_actions_controller_spec.rb @@ -4,7 +4,7 @@ describe PostActionsController do describe 'create' do it 'requires you to be logged in' do - lambda { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :create }.to raise_error(Discourse::NotLoggedIn) end describe 'logged in' do @@ -14,23 +14,23 @@ describe PostActionsController do end it 'raises an error when the id is missing' do - lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.to raise_error(ActionController::ParameterMissing) end it 'raises an error when the post_action_type_id index is missing' do - lambda { xhr :post, :create, id: @post.id }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create, id: @post.id }.to raise_error(ActionController::ParameterMissing) end it "fails when the user doesn't have permission to see the post" do Guardian.any_instance.expects(:can_see?).with(@post).returns(false) xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like] - response.should be_forbidden + expect(response).to be_forbidden end it "fails when the user doesn't have permission to perform that action" do Guardian.any_instance.expects(:post_can_act?).with(@post, :like, taken_actions: nil).returns(false) xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like] - response.should be_forbidden + expect(response).to be_forbidden end it 'allows us to create an post action on a post' do @@ -69,19 +69,19 @@ describe PostActionsController do let(:post) { Fabricate(:post, user: Fabricate(:coding_horror)) } it 'requires you to be logged in' do - lambda { xhr :delete, :destroy, id: post.id }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy, id: post.id }.to raise_error(Discourse::NotLoggedIn) end context 'logged in' do let!(:user) { log_in } it 'raises an error when the post_action_type_id is missing' do - lambda { xhr :delete, :destroy, id: post.id }.should raise_error(ActionController::ParameterMissing) + expect { xhr :delete, :destroy, id: post.id }.to raise_error(ActionController::ParameterMissing) end it "returns 404 when the post action type doesn't exist for that user" do xhr :delete, :destroy, id: post.id, post_action_type_id: 1 - response.code.should == '404' + expect(response.code).to eq('404') end context 'with a post_action record ' do @@ -89,18 +89,18 @@ describe PostActionsController do it 'returns success' do xhr :delete, :destroy, id: post.id, post_action_type_id: 1 - response.should be_success + expect(response).to be_success end it 'deletes the action' do xhr :delete, :destroy, id: post.id, post_action_type_id: 1 - PostAction.exists?(user_id: user.id, post_id: post.id, post_action_type_id: 1, deleted_at: nil).should == false + expect(PostAction.exists?(user_id: user.id, post_id: post.id, post_action_type_id: 1, deleted_at: nil)).to eq(false) end it 'ensures it can be deleted' do Guardian.any_instance.expects(:can_delete?).with(post_action).returns(false) xhr :delete, :destroy, id: post.id, post_action_type_id: 1 - response.should be_forbidden + expect(response).to be_forbidden end end @@ -114,7 +114,7 @@ describe PostActionsController do context "not logged in" do it "should not allow them to clear flags" do - lambda { xhr :post, :defer_flags }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :defer_flags }.to raise_error(Discourse::NotLoggedIn) end end @@ -122,13 +122,13 @@ describe PostActionsController do let!(:user) { log_in(:moderator) } it "raises an error without a post_action_type_id" do - -> { xhr :post, :defer_flags, id: flagged_post.id }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :defer_flags, id: flagged_post.id }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the user doesn't have access" do Guardian.any_instance.expects(:can_defer_flags?).returns(false) xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] - response.should be_forbidden + expect(response).to be_forbidden end context "success" do @@ -139,13 +139,13 @@ describe PostActionsController do it "delegates to defer_flags" do xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] - response.should be_success + expect(response).to be_success end it "works with a deleted post" do flagged_post.trash!(user) xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] - response.should be_success + expect(response).to be_success end end @@ -159,32 +159,32 @@ describe PostActionsController do let!(:post) { Fabricate(:post, user: log_in) } it 'raises an error without an id' do - lambda { + expect { xhr :get, :users, post_action_type_id: PostActionType.types[:like] - }.should raise_error(ActionController::ParameterMissing) + }.to raise_error(ActionController::ParameterMissing) end it 'raises an error without a post action type' do - lambda { + expect { xhr :get, :users, id: post.id - }.should raise_error(ActionController::ParameterMissing) + }.to raise_error(ActionController::ParameterMissing) end it "fails when the user doesn't have permission to see the post" do Guardian.any_instance.expects(:can_see?).with(post).returns(false) xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like] - response.should be_forbidden + expect(response).to be_forbidden end it 'raises an error when the post action type cannot be seen' do Guardian.any_instance.expects(:can_see_post_actors?).with(instance_of(Topic), PostActionType.types[:like]).returns(false) xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like] - response.should be_forbidden + expect(response).to be_forbidden end it 'succeeds' do xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like] - response.should be_success + expect(response).to be_success end end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 92a2ba3d8..9277fc002 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -7,12 +7,12 @@ shared_examples 'finding and showing post' do it 'ensures the user can see the post' do Guardian.any_instance.expects(:can_see?).with(post).returns(false) xhr :get, action, params - response.should be_forbidden + expect(response).to be_forbidden end it 'succeeds' do xhr :get, action, params - response.should be_success + expect(response).to be_success end context "deleted post" do @@ -22,32 +22,32 @@ shared_examples 'finding and showing post' do it "can't find deleted posts as an anonymous user" do xhr :get, action, params - response.status.should == 404 + expect(response.status).to eq(404) end it "can't find deleted posts as a regular user" do log_in(:user) xhr :get, action, params - response.status.should == 404 + expect(response.status).to eq(404) end it "can find posts as a moderator" do log_in(:moderator) xhr :get, action, params - response.should be_success + expect(response).to be_success end it "can find posts as a admin" do log_in(:admin) xhr :get, action, params - response.should be_success + expect(response).to be_success end end end shared_examples 'action requires login' do |method, action, params| it 'raises an exception when not logged in' do - lambda { xhr method, action, params }.should raise_error(Discourse::NotLoggedIn) + expect { xhr method, action, params }.to raise_error(Discourse::NotLoggedIn) end end @@ -61,10 +61,10 @@ describe PostsController do it 'returns the cooked conent' do xhr :get, :cooked, id: 1234 - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json.should be_present - json['cooked'].should == 'wat' + expect(json).to be_present + expect(json['cooked']).to eq('wat') end end @@ -80,7 +80,7 @@ describe PostsController do xhr :get, :raw_email, id: post.id - response.should be_forbidden + expect(response).to be_forbidden end it "can view raw email" do @@ -88,9 +88,9 @@ describe PostsController do xhr :get, :raw_email, id: post.id - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['raw_email'].should == 'email_content' + expect(json['raw_email']).to eq('email_content') end end @@ -108,10 +108,10 @@ describe PostsController do new_post = create_post xhr :get, :show, {id: new_post.id} parsed = JSON.parse(response.body) - parsed["topic_slug"].should == new_post.topic.slug - parsed["moderator"].should == false - parsed["username"].should == new_post.user.username - parsed["cooked"].should == new_post.cooked + expect(parsed["topic_slug"]).to eq(new_post.topic.slug) + expect(parsed["moderator"]).to eq(false) + expect(parsed["username"]).to eq(new_post.user.username) + expect(parsed["cooked"]).to eq(new_post.cooked) end end @@ -160,14 +160,14 @@ describe PostsController do xhr :delete, :destroy, id: post.id - response.status.should == 422 - JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit')) + expect(response.status).to eq(422) + expect(JSON.parse(response.body)['errors']).to include(I18n.t('too_late_to_edit')) end it "raises an error when the user doesn't have permission to see the post" do Guardian.any_instance.expects(:can_delete?).with(post).returns(false) xhr :delete, :destroy, id: post.id - response.should be_forbidden + expect(response).to be_forbidden end it "uses a PostDestroyer" do @@ -191,7 +191,7 @@ describe PostsController do it "raises an error when the user doesn't have permission to see the post" do Guardian.any_instance.expects(:can_recover_post?).with(post).returns(false) xhr :put, :recover, post_id: post.id - response.should be_forbidden + expect(response).to be_forbidden end it "recovers a post correctly" do @@ -201,7 +201,7 @@ describe PostsController do PostDestroyer.new(user, post).destroy xhr :put, :recover, post_id: post.id post.reload - post.deleted_at.should == nil + expect(post.deleted_at).to eq(nil) end end @@ -217,17 +217,17 @@ describe PostsController do let!(:post2) { Fabricate(:post, topic_id: post1.topic_id, user: poster, post_number: 3, reply_to_post_number: post1.post_number) } it "raises invalid parameters no post_ids" do - lambda { xhr :delete, :destroy_many }.should raise_error(ActionController::ParameterMissing) + expect { xhr :delete, :destroy_many }.to raise_error(ActionController::ParameterMissing) end it "raises invalid parameters with missing ids" do - lambda { xhr :delete, :destroy_many, post_ids: [12345] }.should raise_error(Discourse::InvalidParameters) + expect { xhr :delete, :destroy_many, post_ids: [12345] }.to raise_error(Discourse::InvalidParameters) end it "raises an error when the user doesn't have permission to delete the posts" do Guardian.any_instance.expects(:can_delete?).with(instance_of(Post)).returns(false) xhr :delete, :destroy_many, post_ids: [post1.id, post2.id] - response.should be_forbidden + expect(response).to be_forbidden end it "deletes the post" do @@ -278,8 +278,8 @@ describe PostsController do xhr :put, :update, update_params - response.status.should == 422 - JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit')) + expect(response.status).to eq(422) + expect(JSON.parse(response.body)['errors']).to include(I18n.t('too_late_to_edit')) end it 'passes the image sizes through' do @@ -294,15 +294,15 @@ describe PostsController do it "raises an error when the post parameter is missing" do update_params.delete(:post) - lambda { + expect { xhr :put, :update, update_params - }.should raise_error(ActionController::ParameterMissing) + }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the user doesn't have permission to see the post" do Guardian.any_instance.expects(:can_edit?).with(post).at_least_once.returns(false) xhr :put, :update, update_params - response.should be_forbidden + expect(response).to be_forbidden end it "calls revise with valid parameters" do @@ -331,7 +331,7 @@ describe PostsController do Guardian.any_instance.expects(:can_see?).with(post).returns(false).once xhr :put, :bookmark, post_id: post.id, bookmarked: 'true' - response.should be_forbidden + expect(response).to be_forbidden end it 'creates a bookmark' do @@ -361,7 +361,7 @@ describe PostsController do xhr :put, :wiki, post_id: post.id, wiki: 'true' - response.should be_forbidden + expect(response).to be_forbidden end it "can wiki a post" do @@ -370,7 +370,7 @@ describe PostsController do xhr :put, :wiki, post_id: post.id, wiki: 'true' post.reload - post.wiki.should == true + expect(post.wiki).to eq(true) end it "can unwiki a post" do @@ -380,7 +380,7 @@ describe PostsController do xhr :put, :wiki, post_id: wikied_post.id, wiki: 'false' wikied_post.reload - wikied_post.wiki.should == false + expect(wikied_post.wiki).to eq(false) end end @@ -400,7 +400,7 @@ describe PostsController do xhr :put, :post_type, post_id: post.id, post_type: 2 - response.should be_forbidden + expect(response).to be_forbidden end it "can change the post type" do @@ -409,7 +409,7 @@ describe PostsController do xhr :put, :post_type, post_id: post.id, post_type: 2 post.reload - post.post_type.should == 2 + expect(post.post_type).to eq(2) end end @@ -429,7 +429,7 @@ describe PostsController do xhr :put, :rebake, post_id: post.id - response.should be_forbidden + expect(response).to be_forbidden end it "can rebake the post" do @@ -437,7 +437,7 @@ describe PostsController do xhr :put, :rebake, post_id: post.id - response.should be_success + expect(response).to be_success end end @@ -457,13 +457,13 @@ describe PostsController do master_key = ApiKey.create_master_key.key xhr :post, :create, {api_username: user.username, api_key: master_key, raw: raw, title: title, wpid: 1} - response.should be_success + expect(response).to be_success original = response.body xhr :post, :create, {api_username: user.username_lower, api_key: master_key, raw: raw, title: title, wpid: 2} - response.should be_success + expect(response).to be_success - response.body.should == original + expect(response.body).to eq(original) end end @@ -474,19 +474,19 @@ describe PostsController do let(:new_post) { Fabricate.build(:post, user: user) } it "raises an exception without a raw parameter" do - lambda { xhr :post, :create }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing) end it 'calls the post creator' do PostCreator.any_instance.expects(:create).returns(new_post) xhr :post, :create, {raw: 'test'} - response.should be_success + expect(response).to be_success end it 'returns JSON of the post' do PostCreator.any_instance.expects(:create).returns(new_post) xhr :post, :create, {raw: 'test'} - ::JSON.parse(response.body).should be_present + expect(::JSON.parse(response.body)).to be_present end it 'protects against dupes' do @@ -494,10 +494,10 @@ describe PostsController do title = "this is a title #{SecureRandom.hash}" xhr :post, :create, {raw: raw, title: title, wpid: 1} - response.should be_success + expect(response).to be_success xhr :post, :create, {raw: raw, title: title, wpid: 2} - response.should_not be_success + expect(response).not_to be_success end context "errors" do @@ -513,7 +513,7 @@ describe PostsController do it "does not succeed" do xhr :post, :create, {raw: 'test'} User.any_instance.expects(:flag_linked_posts_as_spam).never - response.should_not be_success + expect(response).not_to be_success end it "it triggers flag_linked_posts_as_spam when the post creator returns spam" do @@ -619,19 +619,19 @@ describe PostsController do it "ensures anonymous cannot see the revisions" do xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_forbidden + expect(response).to be_forbidden end it "ensures regular user cannot see the revisions" do u = log_in(:user) xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_forbidden + expect(response).to be_forbidden end it "ensures staff can see the revisions" do log_in(:admin) xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_success + expect(response).to be_success end it "ensures poster can see the revisions" do @@ -639,13 +639,13 @@ describe PostsController do post = Fabricate(:post, user: user, version: 3) pr = Fabricate(:post_revision, user: user, post: post) xhr :get, :revisions, post_id: pr.post_id, revision: pr.number - response.should be_success + expect(response).to be_success end it "ensures trust level 4 can see the revisions" do log_in(:trust_level_4) xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_success + expect(response).to be_success end end @@ -656,7 +656,7 @@ describe PostsController do it "ensures anyone can see the revisions" do xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_success + expect(response).to be_success end end @@ -670,7 +670,7 @@ describe PostsController do it "also work on deleted post" do xhr :get, :revisions, post_id: deleted_post_revision.post_id, revision: deleted_post_revision.number - response.should be_success + expect(response).to be_success end end @@ -684,7 +684,7 @@ describe PostsController do it "also work on deleted topic" do xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number - response.should be_success + expect(response).to be_success end end @@ -696,15 +696,15 @@ describe PostsController do it "raises an error when you can't see the post" do Guardian.any_instance.expects(:can_see?).with(post).returns(false) xhr :get, :expand_embed, id: post.id - response.should_not be_success + expect(response).not_to be_success end it "retrieves the body when you can see the post" do Guardian.any_instance.expects(:can_see?).with(post).returns(true) TopicEmbed.expects(:expanded_for).with(post).returns("full content") xhr :get, :expand_embed, id: post.id - response.should be_success - ::JSON.parse(response.body)['cooked'].should == "full content" + expect(response).to be_success + expect(::JSON.parse(response.body)['cooked']).to eq("full content") end end @@ -718,13 +718,13 @@ describe PostsController do it "raises an error if the user doesn't have permission to see the flagged posts" do Guardian.any_instance.expects(:can_see_flagged_posts?).returns(false) xhr :get, :flagged_posts, username: "system" - response.should be_forbidden + expect(response).to be_forbidden end it "can see the flagged posts when authorized" do Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true) xhr :get, :flagged_posts, username: "system" - response.should be_success + expect(response).to be_success end it "only shows agreed and deferred flags" do @@ -745,9 +745,9 @@ describe PostsController do Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true) xhr :get, :flagged_posts, username: user.username - response.should be_success + expect(response).to be_success - JSON.parse(response.body).length.should == 2 + expect(JSON.parse(response.body).length).to eq(2) end end @@ -764,13 +764,13 @@ describe PostsController do it "raises an error if the user doesn't have permission to see the deleted posts" do Guardian.any_instance.expects(:can_see_deleted_posts?).returns(false) xhr :get, :deleted_posts, username: "system" - response.should be_forbidden + expect(response).to be_forbidden end it "can see the deleted posts when authorized" do Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true) xhr :get, :deleted_posts, username: "system" - response.should be_success + expect(response).to be_success end it "only shows posts deleted by other users" do @@ -786,12 +786,12 @@ describe PostsController do Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true) xhr :get, :deleted_posts, username: user.username - response.should be_success + expect(response).to be_success data = JSON.parse(response.body) - data.length.should == 1 - data[0]["id"].should == post_deleted_by_admin.id - data[0]["deleted_by"]["id"].should == admin.id + expect(data.length).to eq(1) + expect(data[0]["id"]).to eq(post_deleted_by_admin.id) + expect(data[0]["deleted_by"]["id"]).to eq(admin.id) end end diff --git a/spec/controllers/robots_txt_controller_spec.rb b/spec/controllers/robots_txt_controller_spec.rb index 4b034f9df..9a612c0e4 100644 --- a/spec/controllers/robots_txt_controller_spec.rb +++ b/spec/controllers/robots_txt_controller_spec.rb @@ -7,13 +7,13 @@ describe RobotsTxtController do it "returns index when indexing is allowed" do SiteSetting.stubs(:allow_index_in_robots_txt).returns(true) get :index - response.should render_template :index + expect(response).to render_template :index end it "returns noindex when indexing is disallowed" do SiteSetting.stubs(:allow_index_in_robots_txt).returns(false) get :index - response.should render_template :no_index + expect(response).to render_template :no_index end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 5d4d9e293..d44f31188 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -12,11 +12,11 @@ describe SearchController do my_post = Fabricate(:post, raw: 'this is my really awesome post') xhr :get, :query, term: 'awesome', include_blurb: true - response.should be_success + expect(response).to be_success data = JSON.parse(response.body) - data['posts'][0]['id'].should == my_post.id - data['posts'][0]['blurb'].should == 'this is my really awesome post' - data['topics'][0]['id'].should == my_post.topic_id + expect(data['posts'][0]['id']).to eq(my_post.id) + expect(data['posts'][0]['blurb']).to eq('this is my really awesome post') + expect(data['topics'][0]['id']).to eq(my_post.topic_id) end end @@ -64,15 +64,15 @@ describe SearchController do context "search context" do it "raises an error with an invalid context type" do - lambda { + expect { xhr :get, :query, term: 'test', search_context: {type: 'security', id: 'hole'} - }.should raise_error(Discourse::InvalidParameters) + }.to raise_error(Discourse::InvalidParameters) end it "raises an error with a missing id" do - lambda { + expect { xhr :get, :query, term: 'test', search_context: {type: 'user'} - }.should raise_error(Discourse::InvalidParameters) + }.to raise_error(Discourse::InvalidParameters) end context "with a user" do @@ -82,7 +82,7 @@ describe SearchController do it "raises an error if the user can't see the context" do Guardian.any_instance.expects(:can_see?).with(user).returns(false) xhr :get, :query, term: 'test', search_context: {type: 'user', id: user.username} - response.should_not be_success + expect(response).not_to be_success end diff --git a/spec/controllers/session_controller_spec.rb b/spec/controllers/session_controller_spec.rb index 4bb1a76a8..584e1f3e6 100644 --- a/spec/controllers/session_controller_spec.rb +++ b/spec/controllers/session_controller_spec.rb @@ -8,15 +8,15 @@ describe SessionController do it "does not work when not in development mode" do Rails.env.stubs(:development?).returns(false) get :become, session_id: user.username - response.should_not be_redirect - session[:current_user_id].should be_blank + expect(response).not_to be_redirect + expect(session[:current_user_id]).to be_blank end it "works in developmenet mode" do Rails.env.stubs(:development?).returns(true) get :become, session_id: user.username - response.should be_redirect - session[:current_user_id].should == user.id + expect(response).to be_redirect + expect(session[:current_user_id]).to eq(user.id) end end @@ -58,11 +58,11 @@ describe SessionController do get :sso_login, Rack::Utils.parse_query(sso.payload) - response.should redirect_to('/') + expect(response).to redirect_to('/') logged_on_user = Discourse.current_user_provider.new(request.env).current_user - logged_on_user.email.should == user.email - logged_on_user.single_sign_on_record.external_id.should == "abc" - logged_on_user.single_sign_on_record.external_username.should == 'sam' + expect(logged_on_user.email).to eq(user.email) + expect(logged_on_user.single_sign_on_record.external_id).to eq("abc") + expect(logged_on_user.single_sign_on_record.external_username).to eq('sam') end it 'allows you to create an admin account' do @@ -78,7 +78,7 @@ describe SessionController do get :sso_login, Rack::Utils.parse_query(sso.payload) logged_on_user = Discourse.current_user_provider.new(request.env).current_user - logged_on_user.admin.should == true + expect(logged_on_user.admin).to eq(true) end @@ -92,24 +92,24 @@ describe SessionController do sso.custom_fields["shop_name"] = "Sam" get :sso_login, Rack::Utils.parse_query(sso.payload) - response.should redirect_to('/a/') + expect(response).to redirect_to('/a/') logged_on_user = Discourse.current_user_provider.new(request.env).current_user # ensure nothing is transient logged_on_user = User.find(logged_on_user.id) - logged_on_user.admin.should == false - logged_on_user.email.should == 'bob@bob.com' - logged_on_user.name.should == 'Sam Saffron' - logged_on_user.username.should == 'sam' + expect(logged_on_user.admin).to eq(false) + expect(logged_on_user.email).to eq('bob@bob.com') + expect(logged_on_user.name).to eq('Sam Saffron') + expect(logged_on_user.username).to eq('sam') - logged_on_user.single_sign_on_record.external_id.should == "666" - logged_on_user.single_sign_on_record.external_username.should == 'sam' - logged_on_user.active.should == true - logged_on_user.custom_fields["shop_url"].should == "http://my_shop.com" - logged_on_user.custom_fields["shop_name"].should == "Sam" - logged_on_user.custom_fields["bla"].should == nil + expect(logged_on_user.single_sign_on_record.external_id).to eq("666") + expect(logged_on_user.single_sign_on_record.external_username).to eq('sam') + expect(logged_on_user.active).to eq(true) + expect(logged_on_user.custom_fields["shop_url"]).to eq("http://my_shop.com") + expect(logged_on_user.custom_fields["shop_name"]).to eq("Sam") + expect(logged_on_user.custom_fields["bla"]).to eq(nil) end it 'allows login to existing account with valid nonce' do @@ -123,16 +123,16 @@ describe SessionController do get :sso_login, Rack::Utils.parse_query(sso.payload) user.single_sign_on_record.reload - user.single_sign_on_record.last_payload.should == sso.unsigned_payload + expect(user.single_sign_on_record.last_payload).to eq(sso.unsigned_payload) - response.should redirect_to('/hello/world') + expect(response).to redirect_to('/hello/world') logged_on_user = Discourse.current_user_provider.new(request.env).current_user - user.id.should == logged_on_user.id + expect(user.id).to eq(logged_on_user.id) # nonce is bad now get :sso_login, Rack::Utils.parse_query(sso.payload) - response.code.should == '500' + expect(response.code).to eq('500') end it 'can act as an SSO provider' do @@ -148,7 +148,7 @@ describe SessionController do get :sso_provider, Rack::Utils.parse_query(sso.payload) - response.should redirect_to("/login") + expect(response).to redirect_to("/login") user = Fabricate(:user, password: "frogs", active: true, admin: true) EmailToken.update_all(confirmed: true) @@ -156,18 +156,18 @@ describe SessionController do xhr :post, :create, login: user.username, password: "frogs", format: :json location = response.header["Location"] - location.should =~ /^http:\/\/somewhere.over.rainbow\/sso/ + expect(location).to match(/^http:\/\/somewhere.over.rainbow\/sso/) payload = location.split("?")[1] sso2 = SingleSignOn.parse(payload, "topsecret") - sso2.email.should == user.email - sso2.name.should == user.name - sso2.username.should == user.username - sso2.external_id.should == user.id.to_s - sso2.admin.should == true - sso2.moderator.should == false + expect(sso2.email).to eq(user.email) + expect(sso2.name).to eq(user.name) + expect(sso2.username).to eq(user.username) + expect(sso2.external_id).to eq(user.id.to_s) + expect(sso2.admin).to eq(true) + expect(sso2.moderator).to eq(false) end @@ -196,18 +196,18 @@ describe SessionController do it 'stores the external attributes' do get :sso_login, Rack::Utils.parse_query(@sso.payload) @user.single_sign_on_record.reload - @user.single_sign_on_record.external_username.should == @sso.username - @user.single_sign_on_record.external_email.should == @sso.email - @user.single_sign_on_record.external_name.should == @sso.name + expect(@user.single_sign_on_record.external_username).to eq(@sso.username) + expect(@user.single_sign_on_record.external_email).to eq(@sso.email) + expect(@user.single_sign_on_record.external_name).to eq(@sso.name) end it 'overrides attributes' do get :sso_login, Rack::Utils.parse_query(@sso.payload) logged_on_user = Discourse.current_user_provider.new(request.env).current_user - logged_on_user.username.should == @suggested_username - logged_on_user.email.should == "#{@reversed_username}@garbage.org" - logged_on_user.name.should == @suggested_name + expect(logged_on_user.username).to eq(@suggested_username) + expect(logged_on_user.email).to eq("#{@reversed_username}@garbage.org") + expect(logged_on_user.name).to eq(@suggested_name) end it 'does not change matching attributes for an existing account' do @@ -218,9 +218,9 @@ describe SessionController do get :sso_login, Rack::Utils.parse_query(@sso.payload) logged_on_user = Discourse.current_user_provider.new(request.env).current_user - logged_on_user.username.should == @user.username - logged_on_user.name.should == @user.name - logged_on_user.email.should == @user.email + expect(logged_on_user.username).to eq(@user.username) + expect(logged_on_user.name).to eq(@user.name) + expect(logged_on_user.email).to eq(@user.email) end it 'does not change attributes for unchanged external attributes' do @@ -231,9 +231,9 @@ describe SessionController do get :sso_login, Rack::Utils.parse_query(@sso.payload) logged_on_user = Discourse.current_user_provider.new(request.env).current_user - logged_on_user.username.should == @user.username - logged_on_user.email.should == @user.email - logged_on_user.name.should == @user.name + expect(logged_on_user.username).to eq(@user.username) + expect(logged_on_user.email).to eq(@user.email) + expect(logged_on_user.name).to eq(@user.name) end end end @@ -249,13 +249,13 @@ describe SessionController do end it "raises an error when the login isn't present" do - lambda { xhr :post, :create }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing) end describe 'invalid password' do it "should return an error with an invalid password" do xhr :post, :create, login: user.username, password: 'sssss' - ::JSON.parse(response.body)['error'].should be_present + expect(::JSON.parse(response.body)['error']).to be_present end end @@ -263,7 +263,7 @@ describe SessionController do it "should return an error with an invalid password if too long" do User.any_instance.expects(:confirm_password?).never xhr :post, :create, login: user.username, password: ('s' * (User.max_password_length + 1)) - ::JSON.parse(response.body)['error'].should be_present + expect(::JSON.parse(response.body)['error']).to be_present end end @@ -272,7 +272,7 @@ describe SessionController do User.any_instance.stubs(:suspended?).returns(true) User.any_instance.stubs(:suspended_till).returns(2.days.from_now) xhr :post, :create, login: user.username, password: 'myawesomepassword' - ::JSON.parse(response.body)['error'].should be_present + expect(::JSON.parse(response.body)['error']).to be_present end end @@ -290,9 +290,9 @@ describe SessionController do user.reload - session[:current_user_id].should == user.id - user.auth_token.should be_present - cookies[:_t].should == user.auth_token + expect(session[:current_user_id]).to eq(user.id) + expect(user.auth_token).to be_present + expect(cookies[:_t]).to eq(user.auth_token) end end @@ -300,7 +300,7 @@ describe SessionController do it 'fails' do SiteSetting.stubs(:enable_local_logins).returns(false) xhr :post, :create, login: user.username, password: 'myawesomepassword' - response.status.to_i.should == 500 + expect(response.status.to_i).to eq(500) end end @@ -311,7 +311,7 @@ describe SessionController do end it 'sets a session id' do - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end @@ -321,7 +321,7 @@ describe SessionController do end it 'sets a session id' do - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end @@ -331,12 +331,12 @@ describe SessionController do it "strips spaces from the username" do xhr :post, :create, login: username, password: 'myawesomepassword' - ::JSON.parse(response.body)['error'].should_not be_present + expect(::JSON.parse(response.body)['error']).not_to be_present end it "strips spaces from the email" do xhr :post, :create, login: email, password: 'myawesomepassword' - ::JSON.parse(response.body)['error'].should_not be_present + expect(::JSON.parse(response.body)['error']).not_to be_present end end @@ -351,7 +351,7 @@ describe SessionController do end it "doesn't log in the user" do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end it "shows the 'not approved' error message" do @@ -368,7 +368,7 @@ describe SessionController do end it 'sets a session id' do - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end end @@ -384,22 +384,22 @@ describe SessionController do User.any_instance.stubs(:admin?).returns(true) ActionDispatch::Request.any_instance.stubs(:remote_ip).returns(permitted_ip_address) xhr :post, :create, login: user.username, password: 'myawesomepassword' - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end it 'returns an error for admin not at the ip address' do User.any_instance.stubs(:admin?).returns(true) ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12") xhr :post, :create, login: user.username, password: 'myawesomepassword' - JSON.parse(response.body)['error'].should be_present - session[:current_user_id].should_not == user.id + expect(JSON.parse(response.body)['error']).to be_present + expect(session[:current_user_id]).not_to eq(user.id) end it 'is successful for non-admin not at the ip address' do User.any_instance.stubs(:admin?).returns(false) ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12") xhr :post, :create, login: user.username, password: 'myawesomepassword' - session[:current_user_id].should == user.id + expect(session[:current_user_id]).to eq(user.id) end end end @@ -411,7 +411,7 @@ describe SessionController do it "doesn't log in the user" do post_login - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end it "shows the 'not activated' error message" do @@ -441,24 +441,24 @@ describe SessionController do end it 'removes the session variable' do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end it 'removes the auth token cookie' do - cookies[:_t].should be_blank + expect(cookies[:_t]).to be_blank end end describe '.forgot_password' do it 'raises an error without a username parameter' do - lambda { xhr :post, :forgot_password }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :forgot_password }.to raise_error(ActionController::ParameterMissing) end context 'for a non existant username' do it "doesn't generate a new token for a made up username" do - lambda { xhr :post, :forgot_password, login: 'made_up'}.should_not change(EmailToken, :count) + expect { xhr :post, :forgot_password, login: 'made_up'}.not_to change(EmailToken, :count) end it "doesn't enqueue an email" do @@ -473,11 +473,11 @@ describe SessionController do it "returns a 500 if local logins are disabled" do SiteSetting.enable_local_logins = false xhr :post, :forgot_password, login: user.username - response.code.to_i.should == 500 + expect(response.code.to_i).to eq(500) end it "generates a new token for a made up username" do - lambda { xhr :post, :forgot_password, login: user.username}.should change(EmailToken, :count) + expect { xhr :post, :forgot_password, login: user.username}.to change(EmailToken, :count) end it "enqueues an email" do @@ -490,7 +490,7 @@ describe SessionController do let(:user) { Discourse.system_user } it 'generates no token for system username' do - lambda { xhr :post, :forgot_password, login: user.username}.should_not change(EmailToken, :count) + expect { xhr :post, :forgot_password, login: user.username}.not_to change(EmailToken, :count) end it 'enqueues no email' do @@ -504,7 +504,7 @@ describe SessionController do context "when not logged in" do it "retuns 404" do xhr :get, :current - response.should_not be_success + expect(response).not_to be_success end end @@ -513,10 +513,10 @@ describe SessionController do it "returns the JSON for the user" do xhr :get, :current - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json['current_user'].should be_present - json['current_user']['id'].should == user.id + expect(json['current_user']).to be_present + expect(json['current_user']['id']).to eq(user.id) end end end diff --git a/spec/controllers/site_customizations_controller_spec.rb b/spec/controllers/site_customizations_controller_spec.rb index 3097ed0ca..d9948d595 100644 --- a/spec/controllers/site_customizations_controller_spec.rb +++ b/spec/controllers/site_customizations_controller_spec.rb @@ -22,10 +22,10 @@ describe SiteCustomizationsController do ) get :show, key: SiteCustomization::ENABLED_KEY, format: :css, target: 'mobile' - response.body.should =~ /\.a1.*\.a2/m + expect(response.body).to match(/\.a1.*\.a2/m) get :show, key: SiteCustomization::ENABLED_KEY, format: :css - response.body.should =~ /\.b1.*\.b2/m + expect(response.body).to match(/\.b1.*\.b2/m) end it 'can deliver specific css' do @@ -37,9 +37,9 @@ describe SiteCustomizationsController do ) get :show, key: c.key, format: :css, target: 'mobile' - response.body.should =~ /\.a1/ + expect(response.body).to match(/\.a1/) get :show, key: c.key, format: :css - response.body.should =~ /\.b1/ + expect(response.body).to match(/\.b1/) end end diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index 9621593d9..786445e16 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -17,12 +17,12 @@ describe StaticController do end it 'renders the static file if present' do - response.should be_success + expect(response).to be_success end it "renders the file" do - response.should render_template('static/show') - assigns(:page).should == 'faq' + expect(response).to render_template('static/show') + expect(assigns(:page)).to eq('faq') end end @@ -33,7 +33,7 @@ describe StaticController do context "when #{setting_name} site setting is NOT set" do it "renders the #{id} page" do expect(subject).to render_template("static/show") - assigns(:page).should == id + expect(assigns(:page)).to eq(id) end end @@ -50,20 +50,20 @@ describe StaticController do context "with a missing file" do it "should respond 404" do xhr :get, :show, id: 'does-not-exist' - response.response_code.should == 404 + expect(response.response_code).to eq(404) end end it 'should redirect to / when logged in and path is /login' do log_in xhr :get, :show, id: 'login' - response.should redirect_to '/' + expect(response).to redirect_to '/' end it "should display the login template when login is required" do SiteSetting.stubs(:login_required).returns(true) xhr :get, :show, id: 'login' - response.should be_success + expect(response).to be_success end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 48c06963d..23e98b73c 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -10,37 +10,37 @@ describe TopicsController do it "returns the JSON in the format our wordpress plugin needs" do xhr :get, :wordpress, topic_id: topic.id, best: 3 - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json.should be_present + expect(json).to be_present # The JSON has the data the wordpress plugin needs - json['id'].should == topic.id - json['posts_count'].should == 2 - json['filtered_posts_count'].should == 2 + expect(json['id']).to eq(topic.id) + expect(json['posts_count']).to eq(2) + expect(json['filtered_posts_count']).to eq(2) # Posts - json['posts'].size.should == 1 + expect(json['posts'].size).to eq(1) post = json['posts'][0] - post['id'].should == p2.id - post['username'].should == user.username - post['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}" - post['name'].should == user.name - post['created_at'].should be_present - post['cooked'].should == p2.cooked + expect(post['id']).to eq(p2.id) + expect(post['username']).to eq(user.username) + expect(post['avatar_template']).to eq("#{Discourse.base_url_no_prefix}#{user.avatar_template}") + expect(post['name']).to eq(user.name) + expect(post['created_at']).to be_present + expect(post['cooked']).to eq(p2.cooked) # Participants - json['participants'].size.should == 1 + expect(json['participants'].size).to eq(1) participant = json['participants'][0] - participant['id'].should == user.id - participant['username'].should == user.username - participant['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}" + expect(participant['id']).to eq(user.id) + expect(participant['username']).to eq(user.username) + expect(participant['avatar_template']).to eq("#{Discourse.base_url_no_prefix}#{user.avatar_template}") end end context 'move_posts' do it 'needs you to be logged in' do - lambda { xhr :post, :move_posts, topic_id: 111, title: 'blah', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :move_posts, topic_id: 111, title: 'blah', post_ids: [1,2,3] }.to raise_error(Discourse::NotLoggedIn) end describe 'moving to a new topic' do @@ -49,13 +49,13 @@ describe TopicsController do let(:topic) { p1.topic } it "raises an error without postIds" do - lambda { xhr :post, :move_posts, topic_id: topic.id, title: 'blah' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :move_posts, topic_id: topic.id, title: 'blah' }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the user doesn't have permission to move the posts" do Guardian.any_instance.expects(:can_move_posts?).returns(false) xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [1,2,3] - response.should be_forbidden + expect(response).to be_forbidden end context 'success' do @@ -67,10 +67,10 @@ describe TopicsController do end it "returns success" do - response.should be_success + expect(response).to be_success result = ::JSON.parse(response.body) - result['success'].should == true - result['url'].should be_present + expect(result['success']).to eq(true) + expect(result['url']).to be_present end end @@ -83,10 +83,10 @@ describe TopicsController do end it "returns JSON with a false success" do - response.should be_success + expect(response).to be_success result = ::JSON.parse(response.body) - result['success'].should == false - result['url'].should be_blank + expect(result['success']).to eq(false) + expect(result['url']).to be_blank end end end @@ -127,10 +127,10 @@ describe TopicsController do end it "returns success" do - response.should be_success + expect(response).to be_success result = ::JSON.parse(response.body) - result['success'].should == true - result['url'].should be_present + expect(result['success']).to eq(true) + expect(result['url']).to be_present end end @@ -143,10 +143,10 @@ describe TopicsController do end it "returns JSON with a false success" do - response.should be_success + expect(response).to be_success result = ::JSON.parse(response.body) - result['success'].should == false - result['url'].should be_blank + expect(result['success']).to eq(false) + expect(result['url']).to be_blank end end end @@ -154,7 +154,7 @@ describe TopicsController do context "merge_topic" do it 'needs you to be logged in' do - lambda { xhr :post, :merge_topic, topic_id: 111, destination_topic_id: 345 }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :merge_topic, topic_id: 111, destination_topic_id: 345 }.to raise_error(Discourse::NotLoggedIn) end describe 'moving to a new topic' do @@ -163,13 +163,13 @@ describe TopicsController do let(:topic) { p1.topic } it "raises an error without destination_topic_id" do - lambda { xhr :post, :merge_topic, topic_id: topic.id }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :merge_topic, topic_id: topic.id }.to raise_error(ActionController::ParameterMissing) end it "raises an error when the user doesn't have permission to merge" do Guardian.any_instance.expects(:can_move_posts?).returns(false) xhr :post, :merge_topic, topic_id: 111, destination_topic_id: 345 - response.should be_forbidden + expect(response).to be_forbidden end let(:dest_topic) { Fabricate(:topic) } @@ -183,10 +183,10 @@ describe TopicsController do end it "returns success" do - response.should be_success + expect(response).to be_success result = ::JSON.parse(response.body) - result['success'].should == true - result['url'].should be_present + expect(result['success']).to eq(true) + expect(result['url']).to be_present end end @@ -197,14 +197,14 @@ describe TopicsController do context 'change_post_owners' do it 'needs you to be logged in' do - lambda { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] }.to raise_error(Discourse::NotLoggedIn) end describe 'forbidden to moderators' do let!(:moderator) { log_in(:moderator) } it 'correctly denies' do xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] - response.should be_forbidden + expect(response).to be_forbidden end end @@ -213,7 +213,7 @@ describe TopicsController do it 'correctly denies' do xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] - response.should be_forbidden + expect(response).to be_forbidden end end @@ -224,21 +224,21 @@ describe TopicsController do let(:p1) { Fabricate(:post, topic_id: topic.id) } it "raises an error with a parameter missing" do - lambda { xhr :post, :change_post_owners, topic_id: 111, post_ids: [1,2,3] }.should raise_error(ActionController::ParameterMissing) - lambda { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :change_post_owners, topic_id: 111, post_ids: [1,2,3] }.to raise_error(ActionController::ParameterMissing) + expect { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a' }.to raise_error(ActionController::ParameterMissing) end it "calls PostRevisor" do PostRevisor.any_instance.expects(:revise!) xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] - response.should be_success + expect(response).to be_success end it "changes the user" do old_user = p1.user xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] p1.reload - old_user.should_not == p1.user + expect(old_user).not_to eq(p1.user) end # Make sure that p1.reload isn't changing the user for us @@ -246,8 +246,8 @@ describe TopicsController do old_user = p1.user # xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] p1.reload - p1.user.should_not == nil - old_user.should == p1.user + expect(p1.user).not_to eq(nil) + expect(old_user).to eq(p1.user) end let(:p2) { Fabricate(:post, topic_id: topic.id) } @@ -256,8 +256,8 @@ describe TopicsController do xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id, p2.id] p1.reload p2.reload - p1.user.should_not == nil - p1.user.should == p2.user + expect(p1.user).not_to eq(nil) + expect(p1.user).to eq(p2.user) end end end @@ -268,21 +268,21 @@ describe TopicsController do let(:raw) { 'this body is long enough to search for' } it "requires a title" do - -> { xhr :get, :similar_to, raw: raw }.should raise_error(ActionController::ParameterMissing) + expect { xhr :get, :similar_to, raw: raw }.to raise_error(ActionController::ParameterMissing) end it "requires a raw body" do - -> { xhr :get, :similar_to, title: title }.should raise_error(ActionController::ParameterMissing) + expect { xhr :get, :similar_to, title: title }.to raise_error(ActionController::ParameterMissing) end it "raises an error if the title length is below the minimum" do SiteSetting.stubs(:min_title_similar_length).returns(100) - -> { xhr :get, :similar_to, title: title, raw: raw }.should raise_error(Discourse::InvalidParameters) + expect { xhr :get, :similar_to, title: title, raw: raw }.to raise_error(Discourse::InvalidParameters) end it "raises an error if the body length is below the minimum" do SiteSetting.stubs(:min_body_similar_length).returns(100) - -> { xhr :get, :similar_to, title: title, raw: raw }.should raise_error(Discourse::InvalidParameters) + expect { xhr :get, :similar_to, title: title, raw: raw }.to raise_error(Discourse::InvalidParameters) end describe "minimum_topics_similar" do @@ -326,7 +326,7 @@ describe TopicsController do context 'clear_pin' do it 'needs you to be logged in' do - lambda { xhr :put, :clear_pin, topic_id: 1 }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :clear_pin, topic_id: 1 }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do @@ -336,7 +336,7 @@ describe TopicsController do it "fails when the user can't see the topic" do Guardian.any_instance.expects(:can_see?).with(topic).returns(false) xhr :put, :clear_pin, topic_id: topic.id - response.should_not be_success + expect(response).not_to be_success end describe 'when the user can see the topic' do @@ -347,7 +347,7 @@ describe TopicsController do it "succeeds" do xhr :put, :clear_pin, topic_id: topic.id - response.should be_success + expect(response).to be_success end end @@ -357,7 +357,7 @@ describe TopicsController do context 'status' do it 'needs you to be logged in' do - lambda { xhr :put, :status, topic_id: 1, status: 'visible', enabled: true }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :status, topic_id: 1, status: 'visible', enabled: true }.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -369,19 +369,19 @@ describe TopicsController do it "raises an exception if you can't change it" do Guardian.any_instance.expects(:can_moderate?).with(@topic).returns(false) xhr :put, :status, topic_id: @topic.id, status: 'visible', enabled: 'true' - response.should be_forbidden + expect(response).to be_forbidden end it 'requires the status parameter' do - lambda { xhr :put, :status, topic_id: @topic.id, enabled: true }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :status, topic_id: @topic.id, enabled: true }.to raise_error(ActionController::ParameterMissing) end it 'requires the enabled parameter' do - lambda { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.to raise_error(ActionController::ParameterMissing) end it 'raises an error with a status not in the whitelist' do - lambda { xhr :put, :status, topic_id: @topic.id, status: 'title', enabled: 'true' }.should raise_error(Discourse::InvalidParameters) + expect { xhr :put, :status, topic_id: @topic.id, status: 'title', enabled: 'true' }.to raise_error(Discourse::InvalidParameters) end it 'calls update_status on the forum topic with false' do @@ -401,7 +401,7 @@ describe TopicsController do context 'delete_timings' do it 'needs you to be logged in' do - lambda { xhr :delete, :destroy_timings, topic_id: 1 }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy_timings, topic_id: 1 }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do @@ -424,11 +424,11 @@ describe TopicsController do describe 'mute/unmute' do it 'needs you to be logged in' do - lambda { xhr :put, :mute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :mute, topic_id: 99}.to raise_error(Discourse::NotLoggedIn) end it 'needs you to be logged in' do - lambda { xhr :put, :unmute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :unmute, topic_id: 99}.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -442,7 +442,7 @@ describe TopicsController do describe 'recover' do it "won't allow us to recover a topic when we're not logged in" do - lambda { xhr :put, :recover, topic_id: 1 }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :recover, topic_id: 1 }.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -452,7 +452,7 @@ describe TopicsController do it "raises an exception when the user doesn't have permission to delete the topic" do Guardian.any_instance.expects(:can_recover_topic?).with(topic).returns(false) xhr :put, :recover, topic_id: topic.id - response.should be_forbidden + expect(response).to be_forbidden end end @@ -464,7 +464,7 @@ describe TopicsController do it 'succeeds' do PostDestroyer.any_instance.expects(:recover) xhr :put, :recover, topic_id: topic.id - response.should be_success + expect(response).to be_success end end end @@ -473,7 +473,7 @@ describe TopicsController do describe 'delete' do it "won't allow us to delete a topic when we're not logged in" do - lambda { xhr :delete, :destroy, id: 1 }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy, id: 1 }.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -483,7 +483,7 @@ describe TopicsController do it "raises an exception when the user doesn't have permission to delete the topic" do Guardian.any_instance.expects(:can_delete?).with(topic).returns(false) xhr :delete, :destroy, id: topic.id - response.should be_forbidden + expect(response).to be_forbidden end end @@ -495,7 +495,7 @@ describe TopicsController do it 'succeeds' do PostDestroyer.any_instance.expects(:destroy) xhr :delete, :destroy, id: topic.id - response.should be_success + expect(response).to be_success end end @@ -508,18 +508,18 @@ describe TopicsController do it "returns JSON for the slug" do xhr :get, :id_for_slug, slug: topic.slug - response.should be_success + expect(response).to be_success json = ::JSON.parse(response.body) - json.should be_present - json['topic_id'].should == topic.id - json['url'].should == topic.url - json['slug'].should == topic.slug + expect(json).to be_present + expect(json['topic_id']).to eq(topic.id) + expect(json['url']).to eq(topic.url) + expect(json['slug']).to eq(topic.slug) end it "returns invalid access if the user can't see the topic" do Guardian.any_instance.expects(:can_see?).with(topic).returns(false) xhr :get, :id_for_slug, slug: topic.slug - response.should_not be_success + expect(response).not_to be_success end end @@ -531,12 +531,12 @@ describe TopicsController do it 'shows a topic correctly' do xhr :get, :show, topic_id: topic.id, slug: topic.slug - response.should be_success + expect(response).to be_success end it 'return 404 for an invalid page' do xhr :get, :show, topic_id: topic.id, slug: topic.slug, page: 2 - response.code.should == "404" + expect(response.code).to eq("404") end it 'can find a topic given a slug in the id param' do @@ -572,14 +572,14 @@ describe TopicsController do end it 'records a view' do - lambda { xhr :get, :show, topic_id: topic.id, slug: topic.slug }.should change(TopicViewItem, :count).by(1) + expect { xhr :get, :show, topic_id: topic.id, slug: topic.slug }.to change(TopicViewItem, :count).by(1) end it 'records incoming links' do user = Fabricate(:user) get :show, topic_id: topic.id, slug: topic.slug, u: user.username - IncomingLink.count.should == 1 + expect(IncomingLink.count).to eq(1) end it 'records redirects' do @@ -590,7 +590,7 @@ describe TopicsController do get :show, topic_id: topic.id, slug: topic.slug link = IncomingLink.first - link.referer.should == 'http://twitter.com' + expect(link.referer).to eq('http://twitter.com') end it 'tracks a visit for all html requests' do @@ -602,7 +602,7 @@ describe TopicsController do context 'consider for a promotion' do let!(:user) { log_in(:coding_horror) } let(:promotion) do - result = mock + result = double Promotion.stubs(:new).with(user).returns(result) result end @@ -662,7 +662,7 @@ describe TopicsController do expect(response).to be_successful topic.reload # free test, only costs a reload - topic.views.should == 1 + expect(topic.views).to eq(1) end it 'returns 403 for an invalid key' do @@ -678,14 +678,14 @@ describe TopicsController do it 'renders rss of the topic' do get :feed, topic_id: topic.id, slug: 'foo', format: :rss - response.should be_success - response.content_type.should == 'application/rss+xml' + expect(response).to be_success + expect(response.content_type).to eq('application/rss+xml') end end describe 'update' do it "won't allow us to update a topic when we're not logged in" do - lambda { xhr :put, :update, topic_id: 1, slug: 'xyz' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :update, topic_id: 1, slug: 'xyz' }.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -698,7 +698,7 @@ describe TopicsController do it "raises an exception when the user doesn't have permission to update the topic" do Guardian.any_instance.expects(:can_edit?).with(@topic).returns(false) xhr :put, :update, topic_id: @topic.id, slug: @topic.title - response.should be_forbidden + expect(response).to be_forbidden end end @@ -709,14 +709,14 @@ describe TopicsController do it 'succeeds' do xhr :put, :update, topic_id: @topic.id, slug: @topic.title - response.should be_success - ::JSON.parse(response.body)['basic_topic'].should be_present + expect(response).to be_success + expect(::JSON.parse(response.body)['basic_topic']).to be_present end it 'allows a change of title' do xhr :put, :update, topic_id: @topic.id, slug: @topic.title, title: 'This is a new title for the topic' @topic.reload - @topic.title.should == 'This is a new title for the topic' + expect(@topic.title).to eq('This is a new title for the topic') end it 'triggers a change of category' do @@ -732,7 +732,7 @@ describe TopicsController do it "returns errors when the rate limit is exceeded" do EditRateLimiter.any_instance.expects(:performed!).raises(RateLimiter::LimitExceeded.new(60)) xhr :put, :update, topic_id: @topic.id, slug: @topic.title, title: 'This is a new title for the topic' - response.should_not be_success + expect(response).not_to be_success end it "returns errors with invalid categories" do @@ -755,7 +755,7 @@ describe TopicsController do it "can add a category to an uncategorized topic" do Topic.any_instance.expects(:change_category_to_id).with(456).returns(true) xhr :put, :update, topic_id: @topic.id, slug: @topic.title, category_id: 456 - response.should be_success + expect(response).to be_success end end @@ -773,17 +773,17 @@ describe TopicsController do xhr :post, :invite, topic_id: topic.id, email: 'hiro@from.heros', group_ids: "#{group.id}" - response.should be_success + expect(response).to be_success invite = Invite.find_by(email: 'hiro@from.heros') groups = invite.groups.to_a - groups.count.should == 1 - groups[0].id.should == group.id + expect(groups.count).to eq(1) + expect(groups[0].id).to eq(group.id) end end it "won't allow us to invite toa topic when we're not logged in" do - lambda { xhr :post, :invite, topic_id: 1, email: 'jake@adventuretime.ooo' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :invite, topic_id: 1, email: 'jake@adventuretime.ooo' }.to raise_error(Discourse::NotLoggedIn) end describe 'when logged in' do @@ -792,13 +792,13 @@ describe TopicsController do end it 'requires an email parameter' do - lambda { xhr :post, :invite, topic_id: @topic.id }.should raise_error(ActionController::ParameterMissing) + expect { xhr :post, :invite, topic_id: @topic.id }.to raise_error(ActionController::ParameterMissing) end describe 'without permission' do it "raises an exception when the user doesn't have permission to invite to the topic" do xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo' - response.should be_forbidden + expect(response).to be_forbidden end end @@ -810,15 +810,15 @@ describe TopicsController do it 'should work as expected' do xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo' - response.should be_success - ::JSON.parse(response.body).should == {'success' => 'OK'} - Invite.where(invited_by_id: admin.id).count.should == 1 + expect(response).to be_success + expect(::JSON.parse(response.body)).to eq({'success' => 'OK'}) + expect(Invite.where(invited_by_id: admin.id).count).to eq(1) end it 'should fail on shoddy email' do xhr :post, :invite, topic_id: @topic.id, user: 'i_am_not_an_email' - response.should_not be_success - ::JSON.parse(response.body).should == {'failed' => 'FAILED'} + expect(response).not_to be_success + expect(::JSON.parse(response.body)).to eq({'failed' => 'FAILED'}) end end @@ -830,15 +830,15 @@ describe TopicsController do describe 'autoclose' do it 'needs you to be logged in' do - -> { + expect { xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false - }.should raise_error(Discourse::NotLoggedIn) + }.to raise_error(Discourse::NotLoggedIn) end it 'needs you to be an admin or mod' do user = log_in xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false - response.should be_forbidden + expect(response).to be_forbidden end describe 'when logged in' do @@ -851,8 +851,8 @@ describe TopicsController do Topic.any_instance.expects(:set_auto_close).with("24", @admin) xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: '24', auto_close_based_on_last_post: true json = ::JSON.parse(response.body) - json.should have_key('auto_close_at') - json.should have_key('auto_close_hours') + expect(json).to have_key('auto_close_at') + expect(json).to have_key('auto_close_hours') end it "can remove a topic's auto close time" do @@ -868,7 +868,7 @@ describe TopicsController do it 'needs you to be a staff member' do log_in xhr :put, :make_banner, topic_id: 99 - response.should be_forbidden + expect(response).to be_forbidden end describe 'when logged in' do @@ -878,7 +878,7 @@ describe TopicsController do Topic.any_instance.expects(:make_banner!) xhr :put, :make_banner, topic_id: topic.id - response.should be_success + expect(response).to be_success end end @@ -890,7 +890,7 @@ describe TopicsController do it 'needs you to be a staff member' do log_in xhr :put, :remove_banner, topic_id: 99 - response.should be_forbidden + expect(response).to be_forbidden end describe 'when logged in' do @@ -900,7 +900,7 @@ describe TopicsController do Topic.any_instance.expects(:remove_banner!) xhr :put, :remove_banner, topic_id: topic.id - response.should be_success + expect(response).to be_success end end @@ -909,7 +909,7 @@ describe TopicsController do describe "bulk" do it 'needs you to be logged in' do - lambda { xhr :put, :bulk }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :bulk }.to raise_error(Discourse::NotLoggedIn) end describe "when logged in" do @@ -918,15 +918,15 @@ describe TopicsController do let(:topic_ids) { [1,2,3] } it "requires a list of topic_ids or filter" do - lambda { xhr :put, :bulk, operation: operation }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :bulk, operation: operation }.to raise_error(ActionController::ParameterMissing) end it "requires an operation param" do - lambda { xhr :put, :bulk, topic_ids: topic_ids}.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :bulk, topic_ids: topic_ids}.to raise_error(ActionController::ParameterMissing) end it "requires a type field for the operation param" do - lambda { xhr :put, :bulk, topic_ids: topic_ids, operation: {}}.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :bulk, topic_ids: topic_ids, operation: {}}.to raise_error(ActionController::ParameterMissing) end it "delegates work to `TopicsBulkAction`" do @@ -941,7 +941,7 @@ describe TopicsController do describe 'reset_new' do it 'needs you to be logged in' do - lambda { xhr :put, :reset_new }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :reset_new }.to raise_error(Discourse::NotLoggedIn) end let(:user) { log_in(:user) } @@ -953,7 +953,7 @@ describe TopicsController do xhr :put, :reset_new user.reload - user.user_stat.new_since.to_date.should_not == old_date.to_date + expect(user.user_stat.new_since.to_date).not_to eq(old_date.to_date) end diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 4591b2dae..feef3a60a 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -5,7 +5,7 @@ describe UploadsController do context '.create' do it 'requires you to be logged in' do - -> { xhr :post, :create }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :post, :create }.to raise_error(Discourse::NotLoggedIn) end context 'logged in' do @@ -43,12 +43,12 @@ describe UploadsController do it 'is successful with an image' do xhr :post, :create, file: logo - response.status.should eq 200 + expect(response.status).to eq 200 end it 'is successful with an attachment' do xhr :post, :create, file: text_file - response.status.should eq 200 + expect(response.status).to eq 200 end it 'correctly sets retain_hours for admins' do @@ -56,7 +56,7 @@ describe UploadsController do xhr :post, :create, file: logo, retain_hours: 100 url = JSON.parse(response.body)["url"] id = url.split("/")[3].to_i - Upload.find(id).retain_hours.should == 100 + expect(Upload.find(id).retain_hours).to eq(100) end context 'with a big file' do @@ -65,7 +65,7 @@ describe UploadsController do it 'rejects the upload' do xhr :post, :create, file: text_file - response.status.should eq 422 + expect(response.status).to eq 422 end end @@ -78,7 +78,7 @@ describe UploadsController do it 'rejects the upload' do xhr :post, :create, file: text_file - response.status.should eq 422 + expect(response.status).to eq 422 end end @@ -89,12 +89,12 @@ describe UploadsController do it 'is successful with an image' do xhr :post, :create, file: logo - response.status.should eq 200 + expect(response.status).to eq 200 end it 'is successful with an attachment' do xhr :post, :create, file: text_file - response.status.should eq 200 + expect(response.status).to eq 200 end end @@ -105,12 +105,12 @@ describe UploadsController do it 'is successful' do xhr :post, :create, files: files - response.should be_success + expect(response).to be_success end it 'takes the first file' do xhr :post, :create, files: files - response.body.should match /logo-dev.png/ + expect(response.body).to match /logo-dev.png/ end end @@ -126,7 +126,7 @@ describe UploadsController do Discourse.stubs(:store).returns(store) Upload.expects(:find_by).never get :show, site: "default", id: 1, sha: "1234567890abcdef", extension: "pdf" - response.response_code.should == 404 + expect(response.response_code).to eq(404) end it "returns 404 when the upload doens't exist" do @@ -134,7 +134,7 @@ describe UploadsController do Upload.expects(:find_by).with(sha1: "1234567890abcdef").returns(nil) get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf" - response.response_code.should == 404 + expect(response.response_code).to eq(404) end it 'uses send_file' do @@ -154,7 +154,7 @@ describe UploadsController do it "returns 404 when an anonymous user tries to download a file" do Upload.expects(:find_by).never get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf" - response.response_code.should == 404 + expect(response.response_code).to eq(404) end end diff --git a/spec/controllers/user_actions_controller_spec.rb b/spec/controllers/user_actions_controller_spec.rb index b08ae1748..c119ad3be 100644 --- a/spec/controllers/user_actions_controller_spec.rb +++ b/spec/controllers/user_actions_controller_spec.rb @@ -13,14 +13,14 @@ describe UserActionsController do xhr :get, :index, username: post.user.username - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) actions = parsed["user_actions"] - actions.length.should == 1 + expect(actions.length).to eq(1) action = actions[0] - action["acting_name"].should == post.user.name - action["email"].should == nil - action["post_number"].should == 1 + expect(action["acting_name"]).to eq(post.user.name) + expect(action["email"]).to eq(nil) + expect(action["post_number"]).to eq(1) end end end diff --git a/spec/controllers/user_badges_controller_spec.rb b/spec/controllers/user_badges_controller_spec.rb index e278ddcae..867751b56 100644 --- a/spec/controllers/user_badges_controller_spec.rb +++ b/spec/controllers/user_badges_controller_spec.rb @@ -11,10 +11,10 @@ describe UserBadgesController do UserBadge.create(badge: badge, user: user, post_id: p.id, granted_by_id: -1, granted_at: Time.now) xhr :get, :index, badge_id: badge.id - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["topics"].should == nil - parsed["user_badges"][0]["post_id"].should == nil + expect(parsed["topics"]).to eq(nil) + expect(parsed["user_badges"][0]["post_id"]).to eq(nil) end end @@ -28,25 +28,25 @@ describe UserBadgesController do it 'returns user_badges for a user' do xhr :get, :username, username: user.username - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["user_badges"].length.should == 1 + expect(parsed["user_badges"].length).to eq(1) end it 'returns user_badges for a badge' do xhr :get, :index, badge_id: badge.id - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["user_badges"].length.should == 1 + expect(parsed["user_badges"].length).to eq(1) end it 'includes counts when passed the aggregate argument' do xhr :get, :username, username: user.username, grouped: true - response.status.should == 200 + expect(response.status).to eq(200) parsed = JSON.parse(response.body) - parsed["user_badges"].first.has_key?('count').should == true + expect(parsed["user_badges"].first.has_key?('count')).to eq(true) end end @@ -58,7 +58,7 @@ describe UserBadgesController do it 'does not allow regular users to grant badges' do log_in_user Fabricate(:user) xhr :post, :create, badge_id: badge.id, username: user.username - response.status.should == 403 + expect(response.status).to eq(403) end it 'grants badges from staff' do @@ -66,26 +66,26 @@ describe UserBadgesController do log_in_user admin StaffActionLogger.any_instance.expects(:log_badge_grant).once xhr :post, :create, badge_id: badge.id, username: user.username - response.status.should == 200 + expect(response.status).to eq(200) user_badge = UserBadge.find_by(user: user, badge: badge) - user_badge.should be_present - user_badge.granted_by.should eq(admin) + expect(user_badge).to be_present + expect(user_badge.granted_by).to eq(admin) end it 'does not grant badges from regular api calls' do Fabricate(:api_key, user: user) xhr :post, :create, badge_id: badge.id, username: user.username, api_key: user.api_key.key - response.status.should == 403 + expect(response.status).to eq(403) end it 'grants badges from master api calls' do api_key = Fabricate(:api_key) StaffActionLogger.any_instance.expects(:log_badge_grant).never xhr :post, :create, badge_id: badge.id, username: user.username, api_key: api_key.key, api_username: "system" - response.status.should == 200 + expect(response.status).to eq(200) user_badge = UserBadge.find_by(user: user, badge: badge) - user_badge.should be_present - user_badge.granted_by.should eq(Discourse.system_user) + expect(user_badge).to be_present + expect(user_badge.granted_by).to eq(Discourse.system_user) end end @@ -94,15 +94,15 @@ describe UserBadgesController do it 'checks that the user is authorized to revoke a badge' do xhr :delete, :destroy, id: user_badge.id - response.status.should == 403 + expect(response.status).to eq(403) end it 'revokes the badge' do log_in :admin StaffActionLogger.any_instance.expects(:log_badge_revoke).once xhr :delete, :destroy, id: user_badge.id - response.status.should == 200 - UserBadge.find_by(id: user_badge.id).should == nil + expect(response.status).to eq(200) + expect(UserBadge.find_by(id: user_badge.id)).to eq(nil) end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index b6f7cb15c..abd8cb76c 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -7,28 +7,28 @@ describe UsersController do it 'returns success' do xhr :get, :show, username: user.username, format: :json - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["user"]["has_title_badges"].should == false + expect(json["user"]["has_title_badges"]).to eq(false) end it "returns not found when the username doesn't exist" do xhr :get, :show, username: 'madeuppity' - response.should_not be_success + expect(response).not_to be_success end it 'returns not found when the user is inactive' do inactive = Fabricate(:user, active: false) xhr :get, :show, username: inactive.username - response.should_not be_success + expect(response).not_to be_success end it "raises an error on invalid access" do Guardian.any_instance.expects(:can_see?).with(user).returns(false) xhr :get, :show, username: user.username - response.should be_forbidden + expect(response).to be_forbidden end context "fetching a user by external_id" do @@ -36,33 +36,33 @@ describe UsersController do it "returns fetch for a matching external_id" do xhr :get, :show, external_id: '997' - response.should be_success + expect(response).to be_success end it "returns not found when external_id doesn't match" do xhr :get, :show, external_id: '99' - response.should_not be_success + expect(response).not_to be_success end end end describe '.user_preferences_redirect' do it 'requires the user to be logged in' do - lambda { get :user_preferences_redirect }.should raise_error(Discourse::NotLoggedIn) + expect { get :user_preferences_redirect }.to raise_error(Discourse::NotLoggedIn) end it "redirects to their profile when logged in" do user = log_in get :user_preferences_redirect - response.should redirect_to("/users/#{user.username_lower}/preferences") + expect(response).to redirect_to("/users/#{user.username_lower}/preferences") end end describe '.authorize_email' do it 'errors out for invalid tokens' do get :authorize_email, token: 'asdfasdf' - response.should be_success - flash[:error].should be_present + expect(response).to be_success + expect(flash[:error]).to be_present end context 'valid token' do @@ -71,9 +71,9 @@ describe UsersController do email_token = user.email_tokens.create(email: user.email) get :authorize_email, token: email_token.token - response.should be_success - flash[:error].should be_blank - session[:current_user_id].should be_present + expect(response).to be_success + expect(flash[:error]).to be_blank + expect(session[:current_user_id]).to be_present end end end @@ -90,11 +90,11 @@ describe UsersController do end it 'return success' do - response.should be_success + expect(response).to be_success end it 'sets a flash error' do - flash[:error].should be_present + expect(flash[:error]).to be_present end end @@ -123,7 +123,7 @@ describe UsersController do it "raises an error if the honeypot is invalid" do UsersController.any_instance.stubs(:honeypot_or_challenge_fails?).returns(true) put :perform_account_activation, token: 'asdfasdf' - response.should_not be_success + expect(response).not_to be_success end end @@ -135,19 +135,19 @@ describe UsersController do end it 'returns success' do - response.should be_success + expect(response).to be_success end it "doesn't set an error" do - flash[:error].should be_blank + expect(flash[:error]).to be_blank end it 'logs in as the user' do - session[:current_user_id].should be_present + expect(session[:current_user_id]).to be_present end it "doesn't set @needs_approval" do - assigns[:needs_approval].should be_blank + expect(assigns[:needs_approval]).to be_blank end end @@ -159,19 +159,19 @@ describe UsersController do end it 'returns success' do - response.should be_success + expect(response).to be_success end it 'sets @needs_approval' do - assigns[:needs_approval].should be_present + expect(assigns[:needs_approval]).to be_present end it "doesn't set an error" do - flash[:error].should be_blank + expect(flash[:error]).to be_blank end it "doesn't log the user in" do - session[:current_user_id].should be_blank + expect(session[:current_user_id]).to be_blank end end @@ -182,30 +182,30 @@ describe UsersController do let(:new_email) { 'bubblegum@adventuretime.ooo' } it "requires you to be logged in" do - lambda { xhr :put, :change_email, username: 'asdf', email: new_email }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :change_email, username: 'asdf', email: new_email }.to raise_error(Discourse::NotLoggedIn) end context 'when logged in' do let!(:user) { log_in } it 'raises an error without an email parameter' do - lambda { xhr :put, :change_email, username: user.username }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :change_email, username: user.username }.to raise_error(ActionController::ParameterMissing) end it "raises an error if you can't edit the user's email" do Guardian.any_instance.expects(:can_edit_email?).with(user).returns(false) xhr :put, :change_email, username: user.username, email: new_email - response.should be_forbidden + expect(response).to be_forbidden end context 'when the new email address is taken' do let!(:other_user) { Fabricate(:coding_horror) } it 'raises an error' do - lambda { xhr :put, :change_email, username: user.username, email: other_user.email }.should raise_error(Discourse::InvalidParameters) + expect { xhr :put, :change_email, username: user.username, email: other_user.email }.to raise_error(Discourse::InvalidParameters) end it 'raises an error if there is whitespace too' do - lambda { xhr :put, :change_email, username: user.username, email: other_user.email + ' ' }.should raise_error(Discourse::InvalidParameters) + expect { xhr :put, :change_email, username: user.username, email: other_user.email + ' ' }.to raise_error(Discourse::InvalidParameters) end end @@ -213,14 +213,14 @@ describe UsersController do let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com')} it 'raises an error' do - lambda { xhr :put, :change_email, username: user.username, email: other_user.email.upcase }.should raise_error(Discourse::InvalidParameters) + expect { xhr :put, :change_email, username: user.username, email: other_user.email.upcase }.to raise_error(Discourse::InvalidParameters) end end context 'success' do it 'has an email token' do - lambda { xhr :put, :change_email, username: user.username, email: new_email }.should change(EmailToken, :count) + expect { xhr :put, :change_email, username: user.username, email: new_email }.to change(EmailToken, :count) end it 'enqueues an email authorization' do @@ -239,7 +239,7 @@ describe UsersController do it "returns success" do SiteSetting.login_required = true get :password_reset, token: 'asdfasdf' - response.should be_success + expect(response).to be_success end end @@ -249,10 +249,10 @@ describe UsersController do end it 'disallows login' do - flash[:error].should be_present - session[:current_user_id].should be_blank - assigns[:invalid_token].should == nil - response.should be_success + expect(flash[:error]).to be_present + expect(session[:current_user_id]).to be_blank + expect(assigns[:invalid_token]).to eq(nil) + expect(response).to be_success end end @@ -262,10 +262,10 @@ describe UsersController do end it 'disallows login' do - flash[:error].should be_present - session[:current_user_id].should be_blank - assigns[:invalid_token].should == true - response.should be_success + expect(flash[:error]).to be_present + expect(session[:current_user_id]).to be_blank + expect(assigns[:invalid_token]).to eq(true) + expect(response).to be_success end end @@ -276,8 +276,8 @@ describe UsersController do get :password_reset, token: token put :password_reset, token: token, password: 'newpassword' - response.should be_success - flash[:error].should be_blank + expect(response).to be_success + expect(flash[:error]).to be_blank end end @@ -289,27 +289,27 @@ describe UsersController do it "fails when the password is blank" do put :password_reset, token: token, password: '' - assigns(:user).errors.should be_present - session[:current_user_id].should be_blank + expect(assigns(:user).errors).to be_present + expect(session[:current_user_id]).to be_blank end it "fails when the password is too long" do put :password_reset, token: token, password: ('x' * (User.max_password_length + 1)) - assigns(:user).errors.should be_present - session[:current_user_id].should be_blank + expect(assigns(:user).errors).to be_present + expect(session[:current_user_id]).to be_blank end it "logs in the user" do put :password_reset, token: token, password: 'newpassword' - assigns(:user).errors.should be_blank - session[:current_user_id].should be_present + expect(assigns(:user).errors).to be_blank + expect(session[:current_user_id]).to be_present end it "doesn't log in the user when not approved" do SiteSetting.expects(:must_approve_users?).returns(true) put :password_reset, token: token, password: 'newpassword' - assigns(:user).errors.should be_blank - session[:current_user_id].should be_blank + expect(assigns(:user).errors).to be_blank + expect(session[:current_user_id]).to be_blank end end end @@ -345,8 +345,8 @@ describe UsersController do SiteSetting.stubs(:allow_new_registrations).returns(false) post_user json = JSON.parse(response.body) - json['success'].should == false - json['message'].should be_present + expect(json['success']).to eq(false) + expect(json['message']).to be_present end it 'creates a user correctly' do @@ -358,7 +358,7 @@ describe UsersController do expect(JSON.parse(response.body)['active']).to be_falsey # should save user_created_message in session - session["user_created_message"].should be_present + expect(session["user_created_message"]).to be_present end context "and 'must approve users' site setting is enabled" do @@ -394,7 +394,7 @@ describe UsersController do post_user # should save user_created_message in session - session["user_created_message"].should be_present + expect(session["user_created_message"]).to be_present end it "shows the 'active' message" do @@ -408,7 +408,7 @@ describe UsersController do it "should be logged in" do User.any_instance.expects(:enqueue_welcome_message) post_user - session[:current_user_id].should be_present + expect(session[:current_user_id]).to be_present end it 'indicates the user is active in the response' do @@ -421,8 +421,8 @@ describe UsersController do SiteSetting.stubs(:allow_new_registrations).returns(false) post_user json = JSON.parse(response.body) - json['success'].should == false - json['message'].should be_present + expect(json['success']).to eq(false) + expect(json['message']).to be_present end context 'authentication records for' do @@ -448,16 +448,16 @@ describe UsersController do before { post_user } it 'should succeed' do - should respond_with(:success) + is_expected.to respond_with(:success) end it 'has the proper JSON' do json = JSON::parse(response.body) - json["success"].should == true + expect(json["success"]).to eq(true) end it 'should not result in an active account' do - User.find_by(username: @user.username).active.should == false + expect(User.find_by(username: @user.username).active).to eq(false) end end @@ -476,10 +476,10 @@ describe UsersController do it 'should say it was successful' do xhr :post, :create, create_params json = JSON::parse(response.body) - json["success"].should == true + expect(json["success"]).to eq(true) # should not change the session - session["user_created_message"].should be_blank + expect(session["user_created_message"]).to be_blank end end @@ -520,10 +520,10 @@ describe UsersController do it 'should report failed' do xhr :post, :create, create_params json = JSON::parse(response.body) - json["success"].should_not == true + expect(json["success"]).not_to eq(true) # should not change the session - session["user_created_message"].should be_blank + expect(session["user_created_message"]).to be_blank end end @@ -580,25 +580,25 @@ describe UsersController do it "should succeed without the optional field" do xhr :post, :create, create_params - response.should be_success + expect(response).to be_success inserted = User.where(email: @user.email).first - inserted.should be_present - inserted.custom_fields.should be_present - inserted.custom_fields["user_field_#{user_field.id}"].should == 'value1' - inserted.custom_fields["user_field_#{another_field.id}"].should == 'value2' - inserted.custom_fields["user_field_#{optional_field.id}"].should be_blank + expect(inserted).to be_present + expect(inserted.custom_fields).to be_present + expect(inserted.custom_fields["user_field_#{user_field.id}"]).to eq('value1') + expect(inserted.custom_fields["user_field_#{another_field.id}"]).to eq('value2') + expect(inserted.custom_fields["user_field_#{optional_field.id}"]).to be_blank end it "should succeed with the optional field" do create_params[:user_fields][optional_field.id.to_s] = 'value3' xhr :post, :create, create_params.merge(create_params) - response.should be_success + expect(response).to be_success inserted = User.where(email: @user.email).first - inserted.should be_present - inserted.custom_fields.should be_present - inserted.custom_fields["user_field_#{user_field.id}"].should == 'value1' - inserted.custom_fields["user_field_#{another_field.id}"].should == 'value2' - inserted.custom_fields["user_field_#{optional_field.id}"].should == 'value3' + expect(inserted).to be_present + expect(inserted.custom_fields).to be_present + expect(inserted.custom_fields["user_field_#{user_field.id}"]).to eq('value1') + expect(inserted.custom_fields["user_field_#{another_field.id}"]).to eq('value2') + expect(inserted.custom_fields["user_field_#{optional_field.id}"]).to eq('value3') end end @@ -608,7 +608,7 @@ describe UsersController do context '.username' do it 'raises an error when not logged in' do - lambda { xhr :put, :username, username: 'somename' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :username, username: 'somename' }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -616,29 +616,29 @@ describe UsersController do let(:new_username) { "#{user.username}1234" } it 'raises an error without a new_username param' do - lambda { xhr :put, :username, username: user.username }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :username, username: user.username }.to raise_error(ActionController::ParameterMissing) end it 'raises an error when you don\'t have permission to change the username' do Guardian.any_instance.expects(:can_edit_username?).with(user).returns(false) xhr :put, :username, username: user.username, new_username: new_username - response.should be_forbidden + expect(response).to be_forbidden end it 'raises an error when change_username fails' do User.any_instance.expects(:change_username).with(new_username).returns(false) - lambda { xhr :put, :username, username: user.username, new_username: new_username }.should raise_error(Discourse::InvalidParameters) + expect { xhr :put, :username, username: user.username, new_username: new_username }.to raise_error(Discourse::InvalidParameters) end it 'should succeed when the change_username returns true' do User.any_instance.expects(:change_username).with(new_username).returns(true) xhr :put, :username, username: user.username, new_username: new_username - response.should be_success + expect(response).to be_success end it 'should return a JSON response with the updated username' do xhr :put, :username, username: user.username, new_username: new_username - ::JSON.parse(response.body)['username'].should == new_username + expect(::JSON.parse(response.body)['username']).to eq(new_username) end end @@ -646,36 +646,36 @@ describe UsersController do context '.check_username' do it 'raises an error without any parameters' do - lambda { xhr :get, :check_username }.should raise_error(ActionController::ParameterMissing) + expect { xhr :get, :check_username }.to raise_error(ActionController::ParameterMissing) end shared_examples 'when username is unavailable' do it 'should return success' do - response.should be_success + expect(response).to be_success end it 'should return available as false in the JSON' do - ::JSON.parse(response.body)['available'].should == false + expect(::JSON.parse(response.body)['available']).to eq(false) end it 'should return a suggested username' do - ::JSON.parse(response.body)['suggestion'].should be_present + expect(::JSON.parse(response.body)['suggestion']).to be_present end end shared_examples 'when username is available' do it 'should return success' do - response.should be_success + expect(response).to be_success end it 'should return available in the JSON' do - ::JSON.parse(response.body)['available'].should == true + expect(::JSON.parse(response.body)['available']).to eq(true) end end it 'returns nothing when given an email param but no username' do xhr :get, :check_username, email: 'dood@example.com' - response.should be_success + expect(response).to be_success end context 'username is available' do @@ -695,15 +695,15 @@ describe UsersController do shared_examples 'checking an invalid username' do it 'should return success' do - response.should be_success + expect(response).to be_success end it 'should not return an available key' do - ::JSON.parse(response.body)['available'].should == nil + expect(::JSON.parse(response.body)['available']).to eq(nil) end it 'should return an error message' do - ::JSON.parse(response.body)['errors'].should_not be_empty + expect(::JSON.parse(response.body)['errors']).not_to be_empty end end @@ -714,7 +714,7 @@ describe UsersController do include_examples 'checking an invalid username' it 'should return the invalid characters message' do - ::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.characters')) + expect(::JSON.parse(response.body)['errors']).to include(I18n.t(:'user.username.characters')) end end @@ -725,7 +725,7 @@ describe UsersController do include_examples 'checking an invalid username' it 'should return the "too long" message' do - ::JSON.parse(response.body)['errors'].should include(I18n.t(:'user.username.long', max: User.username_length.end)) + expect(::JSON.parse(response.body)['errors']).to include(I18n.t(:'user.username.long', max: User.username_length.end)) end end @@ -787,7 +787,7 @@ describe UsersController do xhr :get, :invited, username: inviter.username, filter: 'billybob' invites = JSON.parse(response.body)['invites'] - invites.size.should == 1 + expect(invites.size).to eq(1) expect(invites.first).to include('email' => 'billybob@example.com') end @@ -809,7 +809,7 @@ describe UsersController do xhr :get, :invited, username: inviter.username, filter: 'billybob' invites = JSON.parse(response.body)['invites'] - invites.size.should == 1 + expect(invites.size).to eq(1) expect(invites.first).to include('email' => 'billybob@example.com') end @@ -835,7 +835,7 @@ describe UsersController do xhr :get, :invited, username: inviter.username invites = JSON.parse(response.body)['invites'] - invites.size.should == 1 + expect(invites.size).to eq(1) expect(invites.first).to include('email' => invite.email) end end @@ -856,7 +856,7 @@ describe UsersController do xhr :get, :invited, username: inviter.username invites = JSON.parse(response.body)['invites'] - invites.size.should == 1 + expect(invites.size).to eq(1) expect(invites.first).to include("email" => invite.email) end end @@ -890,7 +890,7 @@ describe UsersController do xhr :get, :invited, username: inviter.username invites = JSON.parse(response.body)['invites'] - invites.size.should == 1 + expect(invites.size).to eq(1) expect(invites.first).to include('email' => invite.email) end end @@ -933,8 +933,8 @@ describe UsersController do it "cannot be updated to blank" do put :update, username: user.username, name: 'Jim Tom', user_fields: { user_field.id.to_s => '' } - response.should_not be_success - user.user_fields[user_field.id.to_s].should_not == 'happy' + expect(response).not_to be_success + expect(user.user_fields[user_field.id.to_s]).not_to eq('happy') end end @@ -984,15 +984,15 @@ describe UsersController do it "sets the user's card image to the badge" do log_in_user user xhr :put, :update_card_badge, user_badge_id: user_badge.id, username: user.username - user.user_profile.reload.card_image_badge_id.should be_blank + expect(user.user_profile.reload.card_image_badge_id).to be_blank badge.update_attributes image: "wat.com/wat.jpg" xhr :put, :update_card_badge, user_badge_id: user_badge.id, username: user.username - user.user_profile.reload.card_image_badge_id.should == badge.id + expect(user.user_profile.reload.card_image_badge_id).to eq(badge.id) # Can set to nothing xhr :put, :update_card_badge, username: user.username - user.user_profile.reload.card_image_badge_id.should be_blank + expect(user.user_profile.reload.card_image_badge_id).to be_blank end end @@ -1004,16 +1004,16 @@ describe UsersController do it "sets the user's title to the badge name if it is titleable" do log_in_user user xhr :put, :badge_title, user_badge_id: user_badge.id, username: user.username - user.reload.title.should_not == badge.name + expect(user.reload.title).not_to eq(badge.name) badge.update_attributes allow_title: true xhr :put, :badge_title, user_badge_id: user_badge.id, username: user.username - user.reload.title.should == badge.name - user.user_profile.badge_granted_title.should == true + expect(user.reload.title).to eq(badge.name) + expect(user.user_profile.badge_granted_title).to eq(true) user.title = "testing" user.save user.user_profile.reload - user.user_profile.badge_granted_title.should == false + expect(user.user_profile.badge_granted_title).to eq(false) end end @@ -1030,23 +1030,23 @@ describe UsersController do it "searches when provided the term only" do xhr :post, :search_users, term: user.name.split(" ").last - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["users"].map { |u| u["username"] }.should include(user.username) + expect(json["users"].map { |u| u["username"] }).to include(user.username) end it "searches when provided the topic only" do xhr :post, :search_users, topic_id: topic.id - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["users"].map { |u| u["username"] }.should include(user.username) + expect(json["users"].map { |u| u["username"] }).to include(user.username) end it "searches when provided the term and topic" do xhr :post, :search_users, term: user.name.split(" ").last, topic_id: topic.id - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["users"].map { |u| u["username"] }.should include(user.username) + expect(json["users"].map { |u| u["username"] }).to include(user.username) end context "when `enable_names` is true" do @@ -1057,7 +1057,7 @@ describe UsersController do it "returns names" do xhr :post, :search_users, term: user.name json = JSON.parse(response.body) - json["users"].map { |u| u["name"] }.should include(user.name) + expect(json["users"].map { |u| u["name"] }).to include(user.name) end end @@ -1069,7 +1069,7 @@ describe UsersController do it "returns names" do xhr :post, :search_users, term: user.name json = JSON.parse(response.body) - json["users"].map { |u| u["name"] }.should_not include(user.name) + expect(json["users"].map { |u| u["name"] }).not_to include(user.name) end end @@ -1116,7 +1116,7 @@ describe UsersController do describe '.upload_user_image' do it 'raises an error when not logged in' do - lambda { xhr :put, :upload_user_image, username: 'asdf' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :upload_user_image, username: 'asdf' }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -1130,7 +1130,7 @@ describe UsersController do end it 'raises an error without a image_type param' do - lambda { xhr :put, :upload_user_image, username: user.username }.should raise_error(ActionController::ParameterMissing) + expect { xhr :put, :upload_user_image, username: user.username }.to raise_error(ActionController::ParameterMissing) end describe "with uploaded file" do @@ -1138,19 +1138,19 @@ describe UsersController do it 'raises an error when you don\'t have permission to upload an user image' do Guardian.any_instance.expects(:can_edit?).with(user).returns(false) xhr :post, :upload_user_image, username: user.username, image_type: "avatar" - response.should be_forbidden + expect(response).to be_forbidden end it 'rejects large images' do SiteSetting.stubs(:max_image_size_kb).returns(1) xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar" - response.status.should eq 422 + expect(response.status).to eq 422 end it 'rejects unauthorized images' do SiteSetting.stubs(:authorized_extensions).returns(".txt") xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar" - response.status.should eq 422 + expect(response.status).to eq 422 end it 'is successful for avatars' do @@ -1160,10 +1160,10 @@ describe UsersController do xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar" # returns the url, width and height of the uploaded image json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 - json['upload_id'].should == upload.id + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) + expect(json['upload_id']).to eq(upload.id) end it 'is successful for profile backgrounds' do @@ -1172,13 +1172,13 @@ describe UsersController do xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "profile_background" user.reload - user.user_profile.profile_background.should == "/uploads/default/1/1234567890123456.png" + expect(user.user_profile.profile_background).to eq("/uploads/default/1/1234567890123456.png") # returns the url, width and height of the uploaded image json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) end it 'is successful for card backgrounds' do @@ -1187,13 +1187,13 @@ describe UsersController do xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "card_background" user.reload - user.user_profile.card_background.should == "/uploads/default/1/1234567890123456.png" + expect(user.user_profile.card_background).to eq("/uploads/default/1/1234567890123456.png") # returns the url, width and height of the uploaded image json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) end end @@ -1210,13 +1210,13 @@ describe UsersController do it 'rejects large images' do SiteSetting.stubs(:max_image_size_kb).returns(1) xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" - response.status.should eq 422 + expect(response.status).to eq 422 end it 'rejects unauthorized images' do SiteSetting.stubs(:authorized_extensions).returns(".txt") xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" - response.status.should eq 422 + expect(response.status).to eq 422 end it 'is successful for avatars' do @@ -1225,10 +1225,10 @@ describe UsersController do # enqueues the user_image generator job xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "avatar" json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 - json['upload_id'].should == upload.id + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) + expect(json['upload_id']).to eq(upload.id) end it 'is successful for profile backgrounds' do @@ -1236,13 +1236,13 @@ describe UsersController do Upload.expects(:create_for).returns(upload) xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" user.reload - user.user_profile.profile_background.should == "/uploads/default/1/1234567890123456.png" + expect(user.user_profile.profile_background).to eq("/uploads/default/1/1234567890123456.png") # returns the url, width and height of the uploaded image json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) end it 'is successful for card backgrounds' do @@ -1250,19 +1250,19 @@ describe UsersController do Upload.expects(:create_for).returns(upload) xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "card_background" user.reload - user.user_profile.card_background.should == "/uploads/default/1/1234567890123456.png" + expect(user.user_profile.card_background).to eq("/uploads/default/1/1234567890123456.png") # returns the url, width and height of the uploaded image json = JSON.parse(response.body) - json['url'].should == "/uploads/default/1/1234567890123456.png" - json['width'].should == 100 - json['height'].should == 200 + expect(json['url']).to eq("/uploads/default/1/1234567890123456.png") + expect(json['width']).to eq(100) + expect(json['height']).to eq(200) end end it "should handle malformed urls" do xhr :post, :upload_user_image, username: user.username, file: "foobar", image_type: "profile_background" - response.status.should eq 422 + expect(response.status).to eq 422 end end @@ -1274,7 +1274,7 @@ describe UsersController do describe '.pick_avatar' do it 'raises an error when not logged in' do - lambda { xhr :put, :pick_avatar, username: 'asdf', avatar_id: 1}.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :pick_avatar, username: 'asdf', avatar_id: 1}.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -1284,25 +1284,25 @@ describe UsersController do it 'raises an error when you don\'t have permission to toggle the avatar' do another_user = Fabricate(:user) xhr :put, :pick_avatar, username: another_user.username, upload_id: 1 - response.should be_forbidden + expect(response).to be_forbidden end it 'it successful' do xhr :put, :pick_avatar, username: user.username, upload_id: 111 - user.reload.uploaded_avatar_id.should == 111 - response.should be_success + expect(user.reload.uploaded_avatar_id).to eq(111) + expect(response).to be_success xhr :put, :pick_avatar, username: user.username - user.reload.uploaded_avatar_id.should == nil - response.should be_success + expect(user.reload.uploaded_avatar_id).to eq(nil) + expect(response).to be_success end it 'returns success' do xhr :put, :pick_avatar, username: user.username, upload_id: 111 - user.reload.uploaded_avatar_id.should == 111 - response.should be_success + expect(user.reload.uploaded_avatar_id).to eq(111) + expect(response).to be_success json = ::JSON.parse(response.body) - json['success'].should == "OK" + expect(json['success']).to eq("OK") end end @@ -1311,7 +1311,7 @@ describe UsersController do describe '.destroy_user_image' do it 'raises an error when not logged in' do - lambda { xhr :delete, :destroy_user_image, type: 'profile_background', username: 'asdf' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy_user_image, type: 'profile_background', username: 'asdf' }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -1321,21 +1321,21 @@ describe UsersController do it 'raises an error when you don\'t have permission to clear the profile background' do Guardian.any_instance.expects(:can_edit?).with(user).returns(false) xhr :delete, :destroy_user_image, username: user.username, image_type: 'profile_background' - response.should be_forbidden + expect(response).to be_forbidden end it "requires the `image_type` param" do - -> { xhr :delete, :destroy_user_image, username: user.username }.should raise_error(ActionController::ParameterMissing) + expect { xhr :delete, :destroy_user_image, username: user.username }.to raise_error(ActionController::ParameterMissing) end it "only allows certain `image_types`" do - -> { xhr :delete, :destroy_user_image, username: user.username, image_type: 'wat' }.should raise_error(Discourse::InvalidParameters) + expect { xhr :delete, :destroy_user_image, username: user.username, image_type: 'wat' }.to raise_error(Discourse::InvalidParameters) end it 'can clear the profile background' do xhr :delete, :destroy_user_image, image_type: 'profile_background', username: user.username - user.reload.user_profile.profile_background.should == "" - response.should be_success + expect(user.reload.user_profile.profile_background).to eq("") + expect(response).to be_success end end @@ -1343,7 +1343,7 @@ describe UsersController do describe '.destroy' do it 'raises an error when not logged in' do - lambda { xhr :delete, :destroy, username: 'nobody' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :delete, :destroy, username: 'nobody' }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -1353,20 +1353,20 @@ describe UsersController do Guardian.any_instance.stubs(:can_delete_user?).returns(false) UserDestroyer.any_instance.expects(:destroy).never xhr :delete, :destroy, username: user.username - response.should be_forbidden + expect(response).to be_forbidden end it "raises an error when you try to delete someone else's account" do UserDestroyer.any_instance.expects(:destroy).never xhr :delete, :destroy, username: Fabricate(:user).username - response.should be_forbidden + expect(response).to be_forbidden end it "deletes your account when you're allowed to" do Guardian.any_instance.stubs(:can_delete_user?).returns(true) UserDestroyer.any_instance.expects(:destroy).with(user, anything).returns(user) xhr :delete, :destroy, username: user.username - response.should be_success + expect(response).to be_success end end end @@ -1375,8 +1375,8 @@ describe UsersController do it "returns 404 if the user is not logged in" do get :my_redirect, path: "wat" - response.should_not be_success - response.should_not be_redirect + expect(response).not_to be_success + expect(response).not_to be_redirect end context "when the user is logged in" do @@ -1384,17 +1384,17 @@ describe UsersController do it "will not redirect to an invalid path" do get :my_redirect, path: "wat/..password.txt" - response.should_not be_redirect + expect(response).not_to be_redirect end it "will redirect to an valid path" do get :my_redirect, path: "preferences" - response.should be_redirect + expect(response).to be_redirect end it "permits forward slashes" do get :my_redirect, path: "activity/posts" - response.should be_redirect + expect(response).to be_redirect end end end @@ -1402,7 +1402,7 @@ describe UsersController do describe '.check_emails' do it 'raises an error when not logged in' do - lambda { xhr :put, :check_emails, username: 'zogstrip' }.should raise_error(Discourse::NotLoggedIn) + expect { xhr :put, :check_emails, username: 'zogstrip' }.to raise_error(Discourse::NotLoggedIn) end context 'while logged in' do @@ -1411,26 +1411,26 @@ describe UsersController do it "raises an error when you aren't allowed to check emails" do Guardian.any_instance.expects(:can_check_emails?).returns(false) xhr :put, :check_emails, username: Fabricate(:user).username - response.should be_forbidden + expect(response).to be_forbidden end it "returns both email and associated_accounts when you're allowed to see them" do Guardian.any_instance.expects(:can_check_emails?).returns(true) xhr :put, :check_emails, username: Fabricate(:user).username - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["email"].should be_present - json["associated_accounts"].should be_present + expect(json["email"]).to be_present + expect(json["associated_accounts"]).to be_present end it "works on inactive users" do inactive_user = Fabricate(:user, active: false) Guardian.any_instance.expects(:can_check_emails?).returns(true) xhr :put, :check_emails, username: inactive_user.username - response.should be_success + expect(response).to be_success json = JSON.parse(response.body) - json["email"].should be_present - json["associated_accounts"].should be_present + expect(json["email"]).to be_present + expect(json["associated_accounts"]).to be_present end end