controllers with rspec3 syntax

This commit is contained in:
Luciano Sousa 2015-01-09 14:04:02 -03:00
parent c96220ca76
commit bc73238c8f
50 changed files with 955 additions and 955 deletions

View File

@ -5,13 +5,13 @@ describe Admin::AdminController do
context 'index' do context 'index' do
it 'needs you to be logged in' 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 end
it "raises an error if you aren't an admin" do it "raises an error if you aren't an admin" do
user = log_in user = log_in
xhr :get, :index xhr :get, :index
response.should be_forbidden expect(response).to be_forbidden
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ApiController do describe Admin::ApiController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ApiController < Admin::AdminController).should == true expect(Admin::ApiController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -11,7 +11,7 @@ describe Admin::ApiController do
context '.index' do context '.index' do
it "succeeds" do it "succeeds" do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
end end
@ -20,8 +20,8 @@ describe Admin::ApiController do
it "returns 404 when there is no key" do it "returns 404 when there is no key" do
xhr :put, :regenerate_key, id: 1234 xhr :put, :regenerate_key, id: 1234
response.should_not be_success expect(response).not_to be_success
response.status.should == 404 expect(response.status).to eq(404)
end end
it "delegates to the api key's `regenerate!` method" do 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 it "returns 404 when there is no key" do
xhr :delete, :revoke_key, id: 1234 xhr :delete, :revoke_key, id: 1234
response.should_not be_success expect(response).not_to be_success
response.status.should == 404 expect(response.status).to eq(404)
end end
it "delegates to the api key's `regenerate!` method" do it "delegates to the api key's `regenerate!` method" do
@ -47,9 +47,9 @@ describe Admin::ApiController do
context '.create_master_key' do context '.create_master_key' do
it "creates a record" do it "creates a record" do
lambda { expect {
xhr :post, :create_master_key xhr :post, :create_master_key
}.should change(ApiKey, :count).by(1) }.to change(ApiKey, :count).by(1)
end end
end end

View File

@ -3,7 +3,7 @@ require "spec_helper"
describe Admin::BackupsController do describe Admin::BackupsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::BackupsController < Admin::AdminController).should == true expect(Admin::BackupsController < Admin::AdminController).to eq(true)
end end
let(:backup_filename) { "2014-02-10-065935.tar.gz" } let(:backup_filename) { "2014-02-10-065935.tar.gz" }
@ -28,7 +28,7 @@ describe Admin::BackupsController do
xhr :get, :index, format: :html xhr :get, :index, format: :html
response.should be_success expect(response).to be_success
end end
end end
@ -40,11 +40,11 @@ describe Admin::BackupsController do
xhr :get, :index, format: :json xhr :get, :index, format: :json
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) json = JSON.parse(response.body)
json[0]["filename"].should == "backup1" expect(json[0]["filename"]).to eq("backup1")
json[1]["filename"].should == "backup2" expect(json[1]["filename"]).to eq("backup2")
end end
end end
@ -58,7 +58,7 @@ describe Admin::BackupsController do
xhr :get, :status xhr :get, :status
response.should be_success expect(response).to be_success
end end
end end
@ -70,7 +70,7 @@ describe Admin::BackupsController do
xhr :post, :create, { with_uploads: false } xhr :post, :create, { with_uploads: false }
response.should be_success expect(response).to be_success
end end
end end
@ -82,7 +82,7 @@ describe Admin::BackupsController do
xhr :delete, :cancel xhr :delete, :cancel
response.should be_success expect(response).to be_success
end end
end end
@ -99,8 +99,8 @@ describe Admin::BackupsController do
get :show, id: backup_filename get :show, id: backup_filename
response.headers['Content-Length'].should == 5 expect(response.headers['Content-Length']).to eq(5)
response.headers['Content-Disposition'].should =~ /attachment; filename/ expect(response.headers['Content-Disposition']).to match(/attachment; filename/)
end end
it "returns 404 when the backup does not exist" do it "returns 404 when the backup does not exist" do
@ -108,7 +108,7 @@ describe Admin::BackupsController do
get :show, id: backup_filename get :show, id: backup_filename
response.should be_not_found expect(response).to be_not_found
end end
end end
@ -121,14 +121,14 @@ describe Admin::BackupsController do
Backup.expects(:[]).with(backup_filename).returns(b) Backup.expects(:[]).with(backup_filename).returns(b)
b.expects(:remove) b.expects(:remove)
xhr :delete, :destroy, id: backup_filename xhr :delete, :destroy, id: backup_filename
response.should be_success expect(response).to be_success
end end
it "doesn't remove the backup if not found" do it "doesn't remove the backup if not found" do
Backup.expects(:[]).with(backup_filename).returns(nil) Backup.expects(:[]).with(backup_filename).returns(nil)
b.expects(:remove).never b.expects(:remove).never
xhr :delete, :destroy, id: backup_filename xhr :delete, :destroy, id: backup_filename
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -144,7 +144,7 @@ describe Admin::BackupsController do
xhr :get, :logs, format: :html xhr :get, :logs, format: :html
response.should be_success expect(response).to be_success
end end
end end
@ -155,7 +155,7 @@ describe Admin::BackupsController do
xhr :post, :restore, id: backup_filename xhr :post, :restore, id: backup_filename
response.should be_success expect(response).to be_success
end end
end end
@ -167,7 +167,7 @@ describe Admin::BackupsController do
xhr :get, :rollback xhr :get, :rollback
response.should be_success expect(response).to be_success
end end
end end
@ -179,7 +179,7 @@ describe Admin::BackupsController do
xhr :put, :readonly, enable: true xhr :put, :readonly, enable: true
response.should be_success expect(response).to be_success
end end
it "disables readonly mode" do it "disables readonly mode" do
@ -187,7 +187,7 @@ describe Admin::BackupsController do
xhr :put, :readonly, enable: false xhr :put, :readonly, enable: false
response.should be_success expect(response).to be_success
end end
end end

View File

@ -9,7 +9,7 @@ describe Admin::BadgesController do
context 'index' do context 'index' do
it 'returns badge index' do it 'returns badge index' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
end end
@ -30,46 +30,46 @@ describe Admin::BadgesController do
groupings2 = BadgeGrouping.all.order(:position).to_a groupings2 = BadgeGrouping.all.order(:position).to_a
groupings2.map{|g| g.name}.should == names expect(groupings2.map{|g| g.name}).to eq(names)
(groupings.map(&:id) - groupings2.map{|g| g.id}).compact.should be_blank 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
end end
context '.badge_types' do context '.badge_types' do
it 'returns success' do it 'returns success' do
xhr :get, :badge_types xhr :get, :badge_types
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :badge_types 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
end end
context '.destroy' do context '.destroy' do
it 'returns success' do it 'returns success' do
xhr :delete, :destroy, id: badge.id xhr :delete, :destroy, id: badge.id
response.should be_success expect(response).to be_success
end end
it 'deletes the badge' do it 'deletes the badge' do
xhr :delete, :destroy, id: badge.id 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
end end
context '.update' do context '.update' do
it 'returns success' 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 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 end
it 'updates the badge' do 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 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 end
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ColorSchemesController do describe Admin::ColorSchemesController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(described_class < Admin::AdminController).should == true expect(described_class < Admin::AdminController).to eq(true)
end end
context "while logged in as an admin" do context "while logged in as an admin" do
@ -20,33 +20,33 @@ describe Admin::ColorSchemesController do
describe "index" do describe "index" do
it "returns success" do it "returns success" do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it "returns JSON" do it "returns JSON" do
Fabricate(:color_scheme) Fabricate(:color_scheme)
xhr :get, :index xhr :get, :index
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end
describe "create" do describe "create" do
it "returns success" do it "returns success" do
xhr :post, :create, valid_params xhr :post, :create, valid_params
response.should be_success expect(response).to be_success
end end
it "returns JSON" do it "returns JSON" do
xhr :post, :create, valid_params xhr :post, :create, valid_params
::JSON.parse(response.body)['id'].should be_present expect(::JSON.parse(response.body)['id']).to be_present
end end
it "returns failure with invalid params" do it "returns failure with invalid params" do
params = valid_params params = valid_params
params[:color_scheme][:colors][0][:hex] = 'cool color please' params[:color_scheme][:colors][0][:hex] = 'cool color please'
xhr :post, :create, valid_params xhr :post, :create, valid_params
response.should_not be_success expect(response).not_to be_success
::JSON.parse(response.body)['errors'].should be_present expect(::JSON.parse(response.body)['errors']).to be_present
end end
end end
@ -56,13 +56,13 @@ describe Admin::ColorSchemesController do
it "returns success" do it "returns success" do
ColorSchemeRevisor.expects(:revise).returns(existing) ColorSchemeRevisor.expects(:revise).returns(existing)
xhr :put, :update, valid_params.merge(id: existing.id) xhr :put, :update, valid_params.merge(id: existing.id)
response.should be_success expect(response).to be_success
end end
it "returns JSON" do it "returns JSON" do
ColorSchemeRevisor.expects(:revise).returns(existing) ColorSchemeRevisor.expects(:revise).returns(existing)
xhr :put, :update, valid_params.merge(id: existing.id) 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 end
it "returns failure with invalid params" do 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][:name] = color_scheme.colors.first.name
params[:color_scheme][:colors][0][:hex] = 'cool color please' params[:color_scheme][:colors][0][:hex] = 'cool color please'
xhr :put, :update, params xhr :put, :update, params
response.should_not be_success expect(response).not_to be_success
::JSON.parse(response.body)['errors'].should be_present expect(::JSON.parse(response.body)['errors']).to be_present
end end
end end
@ -83,7 +83,7 @@ describe Admin::ColorSchemesController do
expect { expect {
xhr :delete, :destroy, id: existing.id xhr :delete, :destroy, id: existing.id
}.to change { ColorScheme.count }.by(-1) }.to change { ColorScheme.count }.by(-1)
response.should be_success expect(response).to be_success
end end
end end
end end

View File

@ -8,7 +8,7 @@ describe Admin::DashboardController do
end end
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::DashboardController < Admin::AdminController).should == true expect(Admin::DashboardController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -17,7 +17,7 @@ describe Admin::DashboardController do
context '.index' do context '.index' do
it 'should be successful' do it 'should be successful' do
xhr :get, :index xhr :get, :index
response.should be_successful expect(response).to be_successful
end end
context 'version checking is enabled' do context 'version checking is enabled' do
@ -28,7 +28,7 @@ describe Admin::DashboardController do
it 'returns discourse version info' do it 'returns discourse version info' do
xhr :get, :index xhr :get, :index
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['version_check'].should be_present expect(json['version_check']).to be_present
end end
end end
@ -40,7 +40,7 @@ describe Admin::DashboardController do
it 'does not return discourse version info' do it 'does not return discourse version info' do
xhr :get, :index xhr :get, :index
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['version_check'].should_not be_present expect(json['version_check']).not_to be_present
end end
end end
end end
@ -49,7 +49,7 @@ describe Admin::DashboardController do
it 'should be successful' do it 'should be successful' do
AdminDashboardData.stubs(:fetch_problems).returns([]) AdminDashboardData.stubs(:fetch_problems).returns([])
xhr :get, :problems xhr :get, :problems
response.should be_successful expect(response).to be_successful
end end
context 'when there are no problems' do context 'when there are no problems' do
@ -60,7 +60,7 @@ describe Admin::DashboardController do
it 'returns an empty array' do it 'returns an empty array' do
xhr :get, :problems xhr :get, :problems
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['problems'].size.should == 0 expect(json['problems'].size).to eq(0)
end end
end end
@ -72,9 +72,9 @@ describe Admin::DashboardController do
it 'returns an array of strings' do it 'returns an array of strings' do
xhr :get, :problems xhr :get, :problems
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['problems'].size.should == 2 expect(json['problems'].size).to eq(2)
json['problems'][0].should be_a(String) expect(json['problems'][0]).to be_a(String)
json['problems'][1].should be_a(String) expect(json['problems'][1]).to be_a(String)
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::EmailController do describe Admin::EmailController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::EmailController < Admin::AdminController).should == true expect(Admin::EmailController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -33,7 +33,7 @@ describe Admin::EmailController do
end end
subject { response } subject { response }
it { should be_success } it { is_expected.to be_success }
end end
context '.skipped' do context '.skipped' do
@ -42,12 +42,12 @@ describe Admin::EmailController do
end end
subject { response } subject { response }
it { should be_success } it { is_expected.to be_success }
end end
context '.test' do context '.test' do
it 'raises an error without the email parameter' 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 end
context 'with an email address' do context 'with an email address' do
@ -62,7 +62,7 @@ describe Admin::EmailController do
context '.preview_digest' do context '.preview_digest' do
it 'raises an error without the last_seen_at parameter' 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 end
it "previews the digest" do it "previews the digest" do

View File

@ -10,7 +10,7 @@ describe Admin::EmojisController do
end end
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::EmojisController < Admin::AdminController).should == true expect(Admin::EmojisController < Admin::AdminController).to eq(true)
end end
context "when logged in" do context "when logged in" do
@ -20,10 +20,10 @@ describe Admin::EmojisController do
it "returns a list of custom emojis" do it "returns a list of custom emojis" do
Emoji.expects(:custom).returns([custom_emoji]) Emoji.expects(:custom).returns([custom_emoji])
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json[0]['name'].should == custom_emoji.name expect(json[0]['name']).to eq(custom_emoji.name)
json[0]['url'].should == custom_emoji.url expect(json[0]['url']).to eq(custom_emoji.url)
end end
end end
@ -34,7 +34,7 @@ describe Admin::EmojisController do
context 'name already exist' do context 'name already exist' do
it "throws an error" do it "throws an error" do
xhr :post, :create, { name: "hello", file: "" } xhr :post, :create, { name: "hello", file: "" }
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -42,7 +42,7 @@ describe Admin::EmojisController do
it "throws an error" do it "throws an error" do
Emoji.expects(:create_for).returns(nil) Emoji.expects(:create_for).returns(nil)
xhr :post, :create, { name: "garbage", file: "" } xhr :post, :create, { name: "garbage", file: "" }
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -57,10 +57,10 @@ describe Admin::EmojisController do
it "creates a custom emoji" do it "creates a custom emoji" do
Emoji.expects(:create_for).returns(custom_emoji2) Emoji.expects(:create_for).returns(custom_emoji2)
xhr :post, :create, { name: "hello2", file: ""} xhr :post, :create, { name: "hello2", file: ""}
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['name'].should == custom_emoji2.name expect(json['name']).to eq(custom_emoji2.name)
json['url'].should == custom_emoji2.url expect(json['url']).to eq(custom_emoji2.url)
end end
end end
@ -71,7 +71,7 @@ describe Admin::EmojisController do
custom_emoji.expects(:remove) custom_emoji.expects(:remove)
Emoji.expects(:custom).returns([custom_emoji]) Emoji.expects(:custom).returns([custom_emoji])
xhr :delete, :destroy, id: "hello" xhr :delete, :destroy, id: "hello"
response.should be_success expect(response).to be_success
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::FlagsController do describe Admin::FlagsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::FlagsController < Admin::AdminController).should == true expect(Admin::FlagsController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -16,8 +16,8 @@ describe Admin::FlagsController do
xhr :get, :index xhr :get, :index
data = ::JSON.parse(response.body) data = ::JSON.parse(response.body)
data["users"].should == [] expect(data["users"]).to eq([])
data["posts"].should == [] expect(data["posts"]).to eq([])
end end
it 'returns a valid json payload when some thing is flagged' do it 'returns a valid json payload when some thing is flagged' do

View File

@ -7,7 +7,7 @@ describe Admin::GroupsController do
end end
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::GroupsController < Admin::AdminController).should == true expect(Admin::GroupsController < Admin::AdminController).to eq(true)
end end
context ".index" do context ".index" do
@ -18,15 +18,15 @@ describe Admin::GroupsController do
group.save group.save
xhr :get, :index xhr :get, :index
response.status.should == 200 expect(response.status).to eq(200)
::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }.should == [{ expect(::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }).to eq([{
"id"=>group.id, "id"=>group.id,
"name"=>group.name, "name"=>group.name,
"user_count"=>1, "user_count"=>1,
"automatic"=>false, "automatic"=>false,
"alias_level"=>0, "alias_level"=>0,
"visible"=>true "visible"=>true
}] }])
end end
end end
@ -36,12 +36,12 @@ describe Admin::GroupsController do
it "strip spaces on the group name" do it "strip spaces on the group name" do
xhr :post, :create, name: " bob " xhr :post, :create, name: " bob "
response.status.should == 200 expect(response.status).to eq(200)
groups = Group.where(name: "bob").to_a groups = Group.where(name: "bob").to_a
groups.count.should == 1 expect(groups.count).to eq(1)
groups[0].name.should == "bob" expect(groups[0].name).to eq("bob")
end end
end end
@ -50,11 +50,11 @@ describe Admin::GroupsController do
it "ignore name change on automatic group" do it "ignore name change on automatic group" do
xhr :put, :update, id: 1, name: "WAT", visible: "true" xhr :put, :update, id: 1, name: "WAT", visible: "true"
response.should be_success expect(response).to be_success
group = Group.find(1) group = Group.find(1)
group.name.should_not == "WAT" expect(group.name).not_to eq("WAT")
group.visible.should == true expect(group.visible).to eq(true)
end end
end end
@ -64,15 +64,15 @@ describe Admin::GroupsController do
it "returns a 422 if the group is automatic" do it "returns a 422 if the group is automatic" do
group = Fabricate(:group, automatic: true) group = Fabricate(:group, automatic: true)
xhr :delete, :destroy, id: group.id xhr :delete, :destroy, id: group.id
response.status.should == 422 expect(response.status).to eq(422)
Group.where(id: group.id).count.should == 1 expect(Group.where(id: group.id).count).to eq(1)
end end
it "is able to destroy a non-automatic group" do it "is able to destroy a non-automatic group" do
group = Fabricate(:group) group = Fabricate(:group)
xhr :delete, :destroy, id: group.id xhr :delete, :destroy, id: group.id
response.status.should == 200 expect(response.status).to eq(200)
Group.where(id: group.id).count.should == 0 expect(Group.where(id: group.id).count).to eq(0)
end end
end end
@ -83,7 +83,7 @@ describe Admin::GroupsController do
Group.expects(:refresh_automatic_groups!).returns(true) Group.expects(:refresh_automatic_groups!).returns(true)
xhr :post, :refresh_automatic_groups xhr :post, :refresh_automatic_groups
response.status.should == 200 expect(response.status).to eq(200)
end end
end end
@ -92,7 +92,7 @@ describe Admin::GroupsController do
it "cannot add members to automatic groups" do it "cannot add members to automatic groups" do
xhr :put, :add_members, group_id: 1, usernames: "l77t" xhr :put, :add_members, group_id: 1, usernames: "l77t"
response.status.should == 422 expect(response.status).to eq(422)
end end
it "is able to add several members to a group" do 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(",") 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.reload
group.users.count.should == 2 expect(group.users.count).to eq(2)
end end
end end
@ -113,7 +113,7 @@ describe Admin::GroupsController do
it "cannot remove members from automatic groups" do it "cannot remove members from automatic groups" do
xhr :put, :remove_member, group_id: 1, user_id: 42 xhr :put, :remove_member, group_id: 1, user_id: 42
response.status.should == 422 expect(response.status).to eq(422)
end end
it "is able to remove a member" do 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 xhr :delete, :remove_member, group_id: group.id, user_id: user.id
response.should be_success expect(response).to be_success
group.reload group.reload
group.users.count.should == 0 expect(group.users.count).to eq(0)
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ImpersonateController do describe Admin::ImpersonateController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ImpersonateController < Admin::AdminController).should == true expect(Admin::ImpersonateController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -13,25 +13,25 @@ describe Admin::ImpersonateController do
context 'index' do context 'index' do
it 'returns success' do it 'returns success' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
end end
context 'create' do context 'create' do
it 'requires a username_or_email parameter' 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 end
it 'returns 404 when that user does not exist' do it 'returns 404 when that user does not exist' do
xhr :post, :create, username_or_email: 'hedonismbot' xhr :post, :create, username_or_email: 'hedonismbot'
response.status.should == 404 expect(response.status).to eq(404)
end end
it "raises an invalid access error if the user can't be impersonated" do it "raises an invalid access error if the user can't be impersonated" do
Guardian.any_instance.expects(:can_impersonate?).with(user).returns(false) Guardian.any_instance.expects(:can_impersonate?).with(user).returns(false)
xhr :post, :create, username_or_email: user.email xhr :post, :create, username_or_email: user.email
response.should be_forbidden expect(response).to be_forbidden
end end
context 'success' do context 'success' do
@ -43,17 +43,17 @@ describe Admin::ImpersonateController do
it "changes the current user session id" do it "changes the current user session id" do
xhr :post, :create, username_or_email: user.username 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 end
it "returns success" do it "returns success" do
xhr :post, :create, username_or_email: user.email xhr :post, :create, username_or_email: user.email
response.should be_success expect(response).to be_success
end end
it "also works with an email address" do it "also works with an email address" do
xhr :post, :create, username_or_email: user.email 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
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ReportsController do describe Admin::ReportsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ReportsController < Admin::AdminController).should == true expect(Admin::ReportsController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -23,7 +23,7 @@ describe Admin::ReportsController do
it "returns 404" do it "returns 404" do
xhr :get, :show, type: invalid_id xhr :get, :show, type: invalid_id
response.status.should == 404 expect(response.status).to eq(404)
end end
end end
@ -36,7 +36,7 @@ describe Admin::ReportsController do
end end
it "renders the report as JSON" do it "renders the report as JSON" do
response.status.should == 404 expect(response.status).to eq(404)
end end
end end
@ -47,11 +47,11 @@ describe Admin::ReportsController do
end end
it "renders the report as JSON" do it "renders the report as JSON" do
response.should be_success expect(response).to be_success
end end
it "renders the report as JSON" do it "renders the report as JSON" do
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ScreenedEmailsController do describe Admin::ScreenedEmailsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ScreenedEmailsController < Admin::AdminController).should == true expect(Admin::ScreenedEmailsController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -13,10 +13,10 @@ describe Admin::ScreenedEmailsController do
end end
subject { response } subject { response }
it { should be_success } it { is_expected.to be_success }
it 'returns JSON' do it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array) expect(::JSON.parse(subject.body)).to be_a(Array)
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ScreenedIpAddressesController do describe Admin::ScreenedIpAddressesController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ScreenedIpAddressesController < Admin::AdminController).should == true expect(Admin::ScreenedIpAddressesController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -12,8 +12,8 @@ describe Admin::ScreenedIpAddressesController do
it 'returns JSON' do it 'returns JSON' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
JSON.parse(response.body).should be_a(Array) expect(JSON.parse(response.body)).to be_a(Array)
end end
end end
@ -32,11 +32,11 @@ describe Admin::ScreenedIpAddressesController do
SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(3) SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(3)
xhr :post, :roll_up 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 = ScreenedIpAddress.where(ip_address: "1.2.3.0/24").first
subnet.should be_present expect(subnet).to be_present
subnet.match_count.should == 3 expect(subnet.match_count).to eq(3)
end end
it "rolls up 1.2.*.* entries" do 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) SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(5)
xhr :post, :roll_up 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 = ScreenedIpAddress.where(ip_address: "1.2.0.0/16").first
subnet.should be_present expect(subnet).to be_present
subnet.match_count.should == 6 expect(subnet.match_count).to eq(6)
end end
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ScreenedUrlsController do describe Admin::ScreenedUrlsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::ScreenedUrlsController < Admin::AdminController).should == true expect(Admin::ScreenedUrlsController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -13,10 +13,10 @@ describe Admin::ScreenedUrlsController do
end end
subject { response } subject { response }
it { should be_success } it { is_expected.to be_success }
it 'returns JSON' do it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array) expect(::JSON.parse(subject.body)).to be_a(Array)
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteCustomizationsController do describe Admin::SiteCustomizationsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::UsersController < Admin::AdminController).should == true expect(Admin::UsersController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -15,24 +15,24 @@ describe Admin::SiteCustomizationsController do
it 'returns success' do it 'returns success' do
SiteCustomization.create!(name: 'my name', user_id: Fabricate(:user).id, header: "my awesome header", stylesheet: "my awesome css") SiteCustomization.create!(name: 'my name', user_id: Fabricate(:user).id, header: "my awesome header", stylesheet: "my awesome css")
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :index xhr :get, :index
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end
context ' .create' do context ' .create' do
it 'returns success' do it 'returns success' do
xhr :post, :create, site_customization: {name: 'my test name'} xhr :post, :create, site_customization: {name: 'my test name'}
response.should be_success expect(response).to be_success
end end
it 'returns json' do it 'returns json' do
xhr :post, :create, site_customization: {name: 'my test name'} 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 end
it 'logs the change' do it 'logs the change' do

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteSettingsController do describe Admin::SiteSettingsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::SiteSettingsController < Admin::AdminController).should == true expect(Admin::SiteSettingsController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -14,12 +14,12 @@ describe Admin::SiteSettingsController do
context 'index' do context 'index' do
it 'returns success' do it 'returns success' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :index xhr :get, :index
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteTextController do describe Admin::SiteTextController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::SiteTextController < Admin::AdminController).should == true expect(Admin::SiteTextController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -16,12 +16,12 @@ describe Admin::SiteTextController do
it 'returns success' do it 'returns success' do
xhr :get, :show, id: text_type xhr :get, :show, id: text_type
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :show, id: text_type xhr :get, :show, id: text_type
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteTextTypesController do describe Admin::SiteTextTypesController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::SiteTextTypesController < Admin::AdminController).should == true expect(Admin::SiteTextTypesController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -14,12 +14,12 @@ describe Admin::SiteTextTypesController do
context ' .index' do context ' .index' do
it 'returns success' do it 'returns success' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :index xhr :get, :index
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
end end
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::StaffActionLogsController do describe Admin::StaffActionLogsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::StaffActionLogsController < Admin::AdminController).should == true expect(Admin::StaffActionLogsController < Admin::AdminController).to eq(true)
end end
let!(:user) { log_in(:admin) } let!(:user) { log_in(:admin) }
@ -13,10 +13,10 @@ describe Admin::StaffActionLogsController do
end end
subject { response } subject { response }
it { should be_success } it { is_expected.to be_success }
it 'returns JSON' do it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array) expect(::JSON.parse(subject.body)).to be_a(Array)
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::UserFieldsController do describe Admin::UserFieldsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::UserFieldsController < Admin::AdminController).should == true expect(Admin::UserFieldsController < Admin::AdminController).to eq(true)
end end
context "when logged in" do context "when logged in" do
@ -11,10 +11,10 @@ describe Admin::UserFieldsController do
context '.create' do context '.create' do
it "creates a user field" do it "creates a user field" do
-> { expect {
xhr :post, :create, {user_field: {name: 'hello', description: 'hello desc', field_type: 'text'} } xhr :post, :create, {user_field: {name: 'hello', description: 'hello desc', field_type: 'text'} }
response.should be_success expect(response).to be_success
}.should change(UserField, :count).by(1) }.to change(UserField, :count).by(1)
end end
end end
@ -23,9 +23,9 @@ describe Admin::UserFieldsController do
it "returns a list of user fields" do it "returns a list of user fields" do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['user_fields'].should be_present expect(json['user_fields']).to be_present
end end
end end
@ -33,10 +33,10 @@ describe Admin::UserFieldsController do
let!(:user_field) { Fabricate(:user_field) } let!(:user_field) { Fabricate(:user_field) }
it "deletes the user field" do it "deletes the user field" do
-> { expect {
xhr :delete, :destroy, id: user_field.id xhr :delete, :destroy, id: user_field.id
response.should be_success expect(response).to be_success
}.should change(UserField, :count).by(-1) }.to change(UserField, :count).by(-1)
end end
end end
@ -45,10 +45,10 @@ describe Admin::UserFieldsController do
it "updates the user field" do it "updates the user field" do
xhr :put, :update, id: user_field.id, user_field: {name: 'fraggle', field_type: 'confirm', description: 'muppet'} 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.reload
user_field.name.should == 'fraggle' expect(user_field.name).to eq('fraggle')
user_field.field_type.should == 'confirm' expect(user_field.field_type).to eq('confirm')
end end
end end
end end

View File

@ -4,7 +4,7 @@ require_dependency 'single_sign_on'
describe Admin::UsersController do describe Admin::UsersController do
it 'is a subclass of AdminController' do it 'is a subclass of AdminController' do
(Admin::UsersController < Admin::AdminController).should == true expect(Admin::UsersController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -15,12 +15,12 @@ describe Admin::UsersController do
context '.index' do context '.index' do
it 'returns success' do it 'returns success' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it 'returns JSON' do it 'returns JSON' do
xhr :get, :index xhr :get, :index
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
context 'when showing emails' do context 'when showing emails' do
@ -29,17 +29,17 @@ describe Admin::UsersController do
xhr :get, :index, show_emails: "true" xhr :get, :index, show_emails: "true"
data = ::JSON.parse(response.body) data = ::JSON.parse(response.body)
data.each do |user| data.each do |user|
user["email"].should be_present expect(user["email"]).to be_present
end end
end end
it "logs only 1 enty" do 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" xhr :get, :index, show_emails: "true"
data = ::JSON.parse(response.body) 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
end end
@ -49,14 +49,14 @@ describe Admin::UsersController do
context 'an existing user' do context 'an existing user' do
it 'returns success' do it 'returns success' do
xhr :get, :show, id: @user.username xhr :get, :show, id: @user.username
response.should be_success expect(response).to be_success
end end
end end
context 'an existing user' do context 'an existing user' do
it 'returns success' do it 'returns success' do
xhr :get, :show, id: 'foobar' xhr :get, :show, id: 'foobar'
response.should_not be_success expect(response).not_to be_success
end end
end end
end end
@ -111,7 +111,7 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false) Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false)
xhr :put, :approve, user_id: evil_trout.id xhr :put, :approve, user_id: evil_trout.id
response.should be_forbidden expect(response).to be_forbidden
end end
it 'calls approve' do it 'calls approve' do
@ -129,13 +129,13 @@ describe Admin::UsersController do
it 'raises an error unless the user can revoke access' do it 'raises an error unless the user can revoke access' do
Guardian.any_instance.expects(:can_revoke_admin?).with(@another_admin).returns(false) Guardian.any_instance.expects(:can_revoke_admin?).with(@another_admin).returns(false)
xhr :put, :revoke_admin, user_id: @another_admin.id xhr :put, :revoke_admin, user_id: @another_admin.id
response.should be_forbidden expect(response).to be_forbidden
end end
it 'updates the admin flag' do it 'updates the admin flag' do
xhr :put, :revoke_admin, user_id: @another_admin.id xhr :put, :revoke_admin, user_id: @another_admin.id
@another_admin.reload @another_admin.reload
@another_admin.should_not be_admin expect(@another_admin).not_to be_admin
end end
end end
@ -147,18 +147,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" 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) Guardian.any_instance.expects(:can_grant_admin?).with(@another_user).returns(false)
xhr :put, :grant_admin, user_id: @another_user.id xhr :put, :grant_admin, user_id: @another_user.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 404 if the username doesn't exist" do it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_admin, user_id: 123123 xhr :put, :grant_admin, user_id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
it 'updates the admin flag' do it 'updates the admin flag' do
xhr :put, :grant_admin, user_id: @another_user.id xhr :put, :grant_admin, user_id: @another_user.id
@another_user.reload @another_user.reload
@another_user.should be_admin expect(@another_user).to be_admin
end end
end end
@ -170,18 +170,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" 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) Guardian.any_instance.expects(:can_change_primary_group?).with(@another_user).returns(false)
xhr :put, :primary_group, user_id: @another_user.id xhr :put, :primary_group, user_id: @another_user.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 404 if the user doesn't exist" do it "returns a 404 if the user doesn't exist" do
xhr :put, :primary_group, user_id: 123123 xhr :put, :primary_group, user_id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
it "changes the user's primary group" do it "changes the user's primary group" do
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: 2 xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: 2
@another_user.reload @another_user.reload
@another_user.primary_group_id.should == 2 expect(@another_user.primary_group_id).to eq(2)
end end
end end
@ -193,20 +193,20 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" 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) Guardian.any_instance.expects(:can_change_trust_level?).with(@another_user).returns(false)
xhr :put, :trust_level, user_id: @another_user.id xhr :put, :trust_level, user_id: @another_user.id
response.should_not be_success expect(response).not_to be_success
end end
it "returns a 404 if the username doesn't exist" do it "returns a 404 if the username doesn't exist" do
xhr :put, :trust_level, user_id: 123123 xhr :put, :trust_level, user_id: 123123
response.should_not be_success expect(response).not_to be_success
end end
it "upgrades the user's trust level" do 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 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 xhr :put, :trust_level, user_id: @another_user.id, level: 2
@another_user.reload @another_user.reload
@another_user.trust_level.should == 2 expect(@another_user.trust_level).to eq(2)
response.should be_success expect(response).to be_success
end end
it "raises no error when demoting a user below their current trust level (locks trust level)" do 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! stat.save!
@another_user.update_attributes(trust_level: TrustLevel[1]) @another_user.update_attributes(trust_level: TrustLevel[1])
xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel[0] 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.reload
@another_user.trust_level_locked.should == true expect(@another_user.trust_level_locked).to eq(true)
end end
end end
@ -231,13 +231,13 @@ describe Admin::UsersController do
it 'raises an error unless the user can revoke access' do it 'raises an error unless the user can revoke access' do
Guardian.any_instance.expects(:can_revoke_moderation?).with(@moderator).returns(false) Guardian.any_instance.expects(:can_revoke_moderation?).with(@moderator).returns(false)
xhr :put, :revoke_moderation, user_id: @moderator.id xhr :put, :revoke_moderation, user_id: @moderator.id
response.should be_forbidden expect(response).to be_forbidden
end end
it 'updates the moderator flag' do it 'updates the moderator flag' do
xhr :put, :revoke_moderation, user_id: @moderator.id xhr :put, :revoke_moderation, user_id: @moderator.id
@moderator.reload @moderator.reload
@moderator.moderator.should_not == true expect(@moderator.moderator).not_to eq(true)
end end
end end
@ -249,18 +249,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" 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) Guardian.any_instance.expects(:can_grant_moderation?).with(@another_user).returns(false)
xhr :put, :grant_moderation, user_id: @another_user.id xhr :put, :grant_moderation, user_id: @another_user.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 404 if the username doesn't exist" do it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_moderation, user_id: 123123 xhr :put, :grant_moderation, user_id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
it 'updates the moderator flag' do it 'updates the moderator flag' do
xhr :put, :grant_moderation, user_id: @another_user.id xhr :put, :grant_moderation, user_id: @another_user.id
@another_user.reload @another_user.reload
@another_user.moderator.should == true expect(@another_user.moderator).to eq(true)
end end
end end
@ -283,10 +283,10 @@ describe Admin::UsersController do
Guardian.any_instance.stubs(:can_delete_user?).returns(true) Guardian.any_instance.stubs(:can_delete_user?).returns(true)
UserDestroyer.any_instance.stubs(:destroy).returns(true) UserDestroyer.any_instance.stubs(:destroy).returns(true)
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] 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 = ::JSON.parse(response.body)
json['success'].to_i.should == 2 expect(json['success'].to_i).to eq(2)
json['failed'].to_i.should == 0 expect(json['failed'].to_i).to eq(0)
end end
context 'failures' do 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, anything).returns(false)
UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true) UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true)
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] 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 = ::JSON.parse(response.body)
json['success'].to_i.should == 1 expect(json['success'].to_i).to eq(1)
json['failed'].to_i.should == 1 expect(json['failed'].to_i).to eq(1)
end end
it 'reports failure due to a user still having posts' do it 'reports failure due to a user still having posts' do
UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError) UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError)
xhr :delete, :reject_bulk, users: [reject_me.id] xhr :delete, :reject_bulk, users: [reject_me.id]
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['success'].to_i.should == 0 expect(json['success'].to_i).to eq(0)
json['failed'].to_i.should == 1 expect(json['failed'].to_i).to eq(1)
end end
end end
end end
@ -323,12 +323,12 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" 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) Guardian.any_instance.expects(:can_delete_user?).with(@delete_me).returns(false)
xhr :delete, :destroy, id: @delete_me.id xhr :delete, :destroy, id: @delete_me.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 403 if the user doesn't exist" do it "returns a 403 if the user doesn't exist" do
xhr :delete, :destroy, id: 123123 xhr :delete, :destroy, id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
context "user has post" do context "user has post" do
@ -343,13 +343,13 @@ describe Admin::UsersController do
it "returns an error" do it "returns an error" do
xhr :delete, :destroy, id: @delete_me.id xhr :delete, :destroy, id: @delete_me.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "doesn't return an error if delete_posts == true" do 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) UserDestroyer.any_instance.expects(:destroy).with(@user, has_entry('delete_posts' => true)).returns(true)
xhr :delete, :destroy, id: @delete_me.id, delete_posts: true xhr :delete, :destroy, id: @delete_me.id, delete_posts: true
response.should be_success expect(response).to be_success
end end
end end
@ -367,9 +367,9 @@ describe Admin::UsersController do
it "returns success" do it "returns success" do
xhr :put, :activate, user_id: @reg_user.id xhr :put, :activate, user_id: @reg_user.id
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['success'].should == "OK" expect(json['success']).to eq("OK")
end end
end end
@ -380,14 +380,14 @@ describe Admin::UsersController do
it "returns success" do it "returns success" do
xhr :put, :log_out, user_id: @reg_user.id xhr :put, :log_out, user_id: @reg_user.id
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['success'].should == "OK" expect(json['success']).to eq("OK")
end end
it "returns 404 when user_id does not exist" do it "returns 404 when user_id does not exist" do
xhr :put, :log_out, user_id: 123123 xhr :put, :log_out, user_id: 123123
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -400,12 +400,12 @@ describe Admin::UsersController do
Guardian.any_instance.expects(:can_block_user?).with(@reg_user).returns(false) Guardian.any_instance.expects(:can_block_user?).with(@reg_user).returns(false)
UserBlocker.expects(:block).never UserBlocker.expects(:block).never
xhr :put, :block, user_id: @reg_user.id xhr :put, :block, user_id: @reg_user.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 403 if the user doesn't exist" do it "returns a 403 if the user doesn't exist" do
xhr :put, :block, user_id: 123123 xhr :put, :block, user_id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
it "punishes the user for spamming" do 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 it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_unblock_user?).with(@reg_user).returns(false) Guardian.any_instance.expects(:can_unblock_user?).with(@reg_user).returns(false)
xhr :put, :unblock, user_id: @reg_user.id xhr :put, :unblock, user_id: @reg_user.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns a 403 if the user doesn't exist" do it "returns a 403 if the user doesn't exist" do
xhr :put, :unblock, user_id: 123123 xhr :put, :unblock, user_id: 123123
response.should be_forbidden expect(response).to be_forbidden
end end
it "punishes the user for spamming" do it "punishes the user for spamming" do
@ -462,20 +462,20 @@ describe Admin::UsersController do
it 'should invite admin' do it 'should invite admin' do
Jobs.expects(:enqueue).with(:user_email, anything).returns(true) Jobs.expects(:enqueue).with(:user_email, anything).returns(true)
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com' 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 = User.find_by(email: 'bill@bill.com')
u.name.should == "Bill" expect(u.name).to eq("Bill")
u.username.should == "bill22" expect(u.username).to eq("bill22")
u.admin.should == true expect(u.admin).to eq(true)
end end
it "doesn't send the email with send_email falsy" do it "doesn't send the email with send_email falsy" do
Jobs.expects(:enqueue).with(:user_email, anything).never Jobs.expects(:enqueue).with(:user_email, anything).never
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0' 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 = ::JSON.parse(response.body)
json["password_url"].should be_present expect(json["password_url"]).to be_present
end end
end end
@ -507,12 +507,12 @@ describe Admin::UsersController do
sso.email = "bob2@bob.com" sso.email = "bob2@bob.com"
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload) xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
response.should be_success expect(response).to be_success
user.reload user.reload
user.email.should == "bob2@bob.com" expect(user.email).to eq("bob2@bob.com")
user.name.should == "Bill" expect(user.name).to eq("Bill")
user.username.should == "Hokli" expect(user.username).to eq("Hokli")
end end

View File

@ -11,7 +11,7 @@ describe Admin::VersionsController do
end end
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
(Admin::VersionsController < Admin::AdminController).should == true expect(Admin::VersionsController < Admin::AdminController).to eq(true)
end end
context 'while logged in as an admin' do context 'while logged in as an admin' do
@ -21,16 +21,16 @@ describe Admin::VersionsController do
describe 'show' do describe 'show' do
subject { xhr :get, :show } subject { xhr :get, :show }
it { should be_success } it { is_expected.to be_success }
it 'should return the currently available version' do it 'should return the currently available version' do
json = JSON.parse(subject.body) json = JSON.parse(subject.body)
json['latest_version'].should == '1.2.33' expect(json['latest_version']).to eq('1.2.33')
end end
it "should return the installed version" do it "should return the installed version" do
json = JSON.parse(subject.body) json = JSON.parse(subject.body)
json['installed_version'].should == Discourse::VERSION::STRING expect(json['installed_version']).to eq(Discourse::VERSION::STRING)
end end
end end
end end

View File

@ -14,14 +14,14 @@ describe TopicsController do
end end
it "doesn't store an incoming link when there's no referer" do it "doesn't store an incoming link when there's no referer" do
lambda { expect {
get :show, id: topic.id get :show, id: topic.id
}.should_not change(IncomingLink, :count) }.not_to change(IncomingLink, :count)
end end
it "doesn't raise an error on a very long link" do it "doesn't raise an error on a very long link" do
set_referer("http://#{'a' * 2000}.com") 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 end
describe "has_escaped_fragment?" do describe "has_escaped_fragment?" do
@ -34,7 +34,7 @@ describe TopicsController do
it "uses the application layout even with an escaped fragment param" 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'} 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" assert_select "meta[name=fragment]", false, "it doesn't have the meta tag"
end end
end end
@ -46,13 +46,13 @@ describe TopicsController do
it "uses the application layout when there's no param" do it "uses the application layout when there's no param" do
get :show, topic_id: topic.id, slug: topic.slug 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" assert_select "meta[name=fragment]", true, "it has the meta tag"
end end
it "uses the crawler layout when there's an _escaped_fragment_ param" do 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' 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" assert_select "meta[name=fragment]", false, "it doesn't have the meta tag"
end end
end end
@ -67,7 +67,7 @@ describe TopicsController do
end end
it "renders with the application layout" do it "renders with the application layout" do
get :show, topic_id: topic.id, slug: topic.slug 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" assert_select "meta[name=fragment]", true, "it has the meta tag"
end end
end end
@ -78,7 +78,7 @@ describe TopicsController do
end end
it "renders with the crawler layout" do it "renders with the crawler layout" do
get :show, topic_id: topic.id, slug: topic.slug 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" assert_select "meta[name=fragment]", false, "it doesn't have the meta tag"
end end
end end
@ -94,7 +94,7 @@ describe TopicsController do
get :show, {topic_id: topic.id} get :show, {topic_id: topic.id}
I18n.locale.should == :fr expect(I18n.locale).to eq(:fr)
end end
it 'is sets the default locale when the setting not enabled' do 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} get :show, {topic_id: topic.id}
I18n.locale.should == :en expect(I18n.locale).to eq(:en)
end end
end end
@ -135,31 +135,31 @@ describe 'api' do
it 'allows users with api key to bookmark posts' do it 'allows users with api key to bookmark posts' do
PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).once 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 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 end
it 'raises an error with a user key that does not match an optionally specified username' do 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 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 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 end
it 'allows users with a master api key to bookmark posts' do it 'allows users with a master api key to bookmark posts' do
PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).once 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 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 end
it 'disallows phonies to bookmark posts' do it 'disallows phonies to bookmark posts' do
PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).never 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 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 end
it 'disallows blank api' do it 'disallows blank api' do
PostAction.expects(:act).with(user, post, PostActionType.types[:bookmark]).never 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 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 end
end end

View File

@ -12,26 +12,26 @@ describe BadgesController do
it 'should return a list of all badges' do it 'should return a list of all badges' do
get :index, format: :json get :index, format: :json
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["badges"].length.should == Badge.count expect(parsed["badges"].length).to eq(Badge.count)
end end
end end
context 'show' do context 'show' do
it "should return a badge" do it "should return a badge" do
get :show, id: badge.id, format: :json get :show, id: badge.id, format: :json
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["badge"].should be_present expect(parsed["badge"]).to be_present
end end
it "should mark the notification as viewed" do it "should mark the notification as viewed" do
log_in_user(user) log_in_user(user)
user_badge = BadgeGranter.grant(badge, 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 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 end
end end

View File

@ -4,7 +4,7 @@ describe CategoriesController do
describe "create" do describe "create" do
it "requires the user to be logged in" 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 end
describe "logged in" do 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 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) Guardian.any_instance.expects(:can_create?).with(Category, nil).returns(false)
xhr :post, :create, name: 'hello', color: 'ff0', text_color: 'fff' xhr :post, :create, name: 'hello', color: 'ff0', text_color: 'fff'
response.should be_forbidden expect(response).to be_forbidden
end end
it "raises an exception when the name is missing" do 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 end
it "raises an exception when the color is missing" do 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 end
it "raises an exception when the text color is missing" do 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 end
describe "failure" do describe "failure" do
@ -36,10 +36,10 @@ describe CategoriesController do
xhr :post, :create, name: @category.name, color: "ff0", text_color: "fff" xhr :post, :create, name: @category.name, color: "ff0", text_color: "fff"
end end
it { should_not respond_with(:success) } it { is_expected.not_to respond_with(:success) }
it "returns errors on a duplicate category name" do it "returns errors on a duplicate category name" do
response.status.should == 422 expect(response.status).to eq(422)
end end
end end
@ -55,15 +55,15 @@ describe CategoriesController do
"staff" => create_post "staff" => create_post
} }
response.status.should == 200 expect(response.status).to eq(200)
category = Category.find_by(name: "hello") 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] [Group[:everyone].id, readonly],[Group[:staff].id,create_post]
] ])
category.name.should == "hello" expect(category.name).to eq("hello")
category.slug.should == "hello-cat" expect(category.slug).to eq("hello-cat")
category.color.should == "ff0" expect(category.color).to eq("ff0")
category.auto_close_hours.should == 72 expect(category.auto_close_hours).to eq(72)
end end
end end
end end
@ -72,7 +72,7 @@ describe CategoriesController do
describe "destroy" do describe "destroy" do
it "requires the user to be logged in" 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 end
describe "logged in" do 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 it "raises an exception if they don't have permission to delete it" do
Guardian.any_instance.expects(:can_delete_category?).returns(false) Guardian.any_instance.expects(:can_delete_category?).returns(false)
xhr :delete, :destroy, id: @category.slug xhr :delete, :destroy, id: @category.slug
response.should be_forbidden expect(response).to be_forbidden
end end
it "deletes the record" do it "deletes the record" do
Guardian.any_instance.expects(:can_delete_category?).returns(true) 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
end end
@ -97,7 +97,7 @@ describe CategoriesController do
describe "upload" do describe "upload" do
it "requires the user to be logged in" 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 end
describe "logged in" do describe "logged in" do
@ -111,17 +111,17 @@ describe CategoriesController do
it "raises an error when you don't have permission to upload" do it "raises an error when you don't have permission to upload" do
Guardian.any_instance.expects(:can_create?).with(Category).returns(false) Guardian.any_instance.expects(:can_create?).with(Category).returns(false)
xhr :post, :upload, image_type: 'logo', file: upload xhr :post, :upload, image_type: 'logo', file: upload
response.should be_forbidden expect(response).to be_forbidden
end end
it "requires the `image_type` param" do 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 end
it "calls Upload.create_for" do it "calls Upload.create_for" do
Upload.expects(:create_for).returns(Upload.new) Upload.expects(:create_for).returns(Upload.new)
xhr :post, :upload, image_type: 'logo', file: upload xhr :post, :upload, image_type: 'logo', file: upload
response.should be_success expect(response).to be_success
end end
end end
end end
@ -129,7 +129,7 @@ describe CategoriesController do
describe "update" do describe "update" do
it "requires the user to be logged in" 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 end
@ -144,19 +144,19 @@ describe CategoriesController do
it "raises an exception if they don't have permission to edit it" do it "raises an exception if they don't have permission to edit it" do
Guardian.any_instance.expects(:can_edit?).returns(false) Guardian.any_instance.expects(:can_edit?).returns(false)
xhr :put, :update, id: @category.slug, name: 'hello', color: 'ff0', text_color: 'fff' xhr :put, :update, id: @category.slug, name: 'hello', color: 'ff0', text_color: 'fff'
response.should be_forbidden expect(response).to be_forbidden
end end
it "requires a name" do 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 end
it "requires a color" do 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 end
it "requires a text color" do 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 end
describe "failure" do describe "failure" do
@ -166,11 +166,11 @@ describe CategoriesController do
end end
it "returns errors on a duplicate category name" do it "returns errors on a duplicate category name" do
response.should_not be_success expect(response).not_to be_success
end end
it "returns errors on a duplicate category name" do 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
end end
@ -187,15 +187,15 @@ describe CategoriesController do
"staff" => create_post "staff" => create_post
} }
response.status.should == 200 expect(response.status).to eq(200)
@category.reload @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] [Group[:everyone].id, readonly],[Group[:staff].id,create_post]
] ])
@category.name.should == "hello" expect(@category.name).to eq("hello")
@category.slug.should == "hello-category" expect(@category.slug).to eq("hello-category")
@category.color.should == "ff0" expect(@category.color).to eq("ff0")
@category.auto_close_hours.should == 72 expect(@category.auto_close_hours).to eq(72)
end end
end end
end end
@ -205,7 +205,7 @@ describe CategoriesController do
describe 'update_slug' do describe 'update_slug' do
it 'requires the user to be logged in' 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 end
describe 'logged in' do describe 'logged in' do
@ -218,26 +218,26 @@ describe CategoriesController do
it 'rejects blank' do it 'rejects blank' do
xhr :put, :update_slug, category_id: @category.id, slug: nil xhr :put, :update_slug, category_id: @category.id, slug: nil
response.status.should == 422 expect(response.status).to eq(422)
end end
it 'accepts valid custom slug' do it 'accepts valid custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: 'valid-slug' 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 = Category.find(@category.id)
category.slug.should == 'valid-slug' expect(category.slug).to eq('valid-slug')
end end
it 'accepts not well formed custom slug' do it 'accepts not well formed custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: ' valid slug' 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 = Category.find(@category.id)
category.slug.should == 'valid-slug' expect(category.slug).to eq('valid-slug')
end end
it 'rejects invalid custom slug' do it 'rejects invalid custom slug' do
xhr :put, :update_slug, category_id: @category.id, slug: ' ' xhr :put, :update_slug, category_id: @category.id, slug: ' '
response.status.should == 422 expect(response.status).to eq(422)
end end
end end
end end

View File

@ -6,12 +6,12 @@ describe ClicksController do
context 'missing params' do context 'missing params' do
it 'raises an error without the url param' 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 end
it "redirects to the url even without the topic_id or post_id params" do it "redirects to the url even without the topic_id or post_id params" do
xhr :get, :track, url: 'http://google.com' xhr :get, :track, url: 'http://google.com'
response.should_not be_redirect expect(response).not_to be_redirect
end end
end end
@ -26,7 +26,7 @@ describe ClicksController do
it "doesn't redirect" do it "doesn't redirect" do
TopicLinkClick.expects(:create_from).returns(nil) TopicLinkClick.expects(:create_from).returns(nil)
xhr :get, :track, url: 'http://discourse.org', post_id: 123 xhr :get, :track, url: 'http://discourse.org', post_id: 123
response.should_not be_redirect expect(response).not_to be_redirect
end end
end end
@ -42,25 +42,25 @@ describe ClicksController do
it 'calls create_from' do it 'calls create_from' do
TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1').returns(url) 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 xhr :get, :track, url: url, post_id: 123
response.should redirect_to(url) expect(response).to redirect_to(url)
end end
it 'redirects to the url' do it 'redirects to the url' do
TopicLinkClick.stubs(:create_from).returns(url) TopicLinkClick.stubs(:create_from).returns(url)
xhr :get, :track, url: url, post_id: 123 xhr :get, :track, url: url, post_id: 123
response.should redirect_to(url) expect(response).to redirect_to(url)
end end
it 'will pass the user_id to create_from' do 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) 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 xhr :get, :track, url: url, post_id: 123
response.should redirect_to(url) expect(response).to redirect_to(url)
end end
it "doesn't redirect with the redirect=false param" do 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) 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' xhr :get, :track, url: url, post_id: 123, redirect: 'false'
response.should_not be_redirect expect(response).not_to be_redirect
end end
end end
@ -69,7 +69,7 @@ describe ClicksController do
it 'calls create_from' do it 'calls create_from' do
TopicLinkClick.expects(:create_from).with('url' => url, 'topic_id' => '789', 'ip' => '192.168.0.1').returns(url) 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 xhr :get, :track, url: url, topic_id: 789
response.should redirect_to(url) expect(response).to redirect_to(url)
end end
end end

View File

@ -5,7 +5,7 @@ describe ComposerMessagesController do
context '.index' do context '.index' do
it 'requires you to be logged in' 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 end
context 'when logged in' do context 'when logged in' do
@ -14,7 +14,7 @@ describe ComposerMessagesController do
it 'redirects to your user preferences' do it 'redirects to your user preferences' do
xhr :get, :index xhr :get, :index
response.should be_success expect(response).to be_success
end end
it 'delegates args to the finder' do it 'delegates args to the finder' do

View File

@ -3,20 +3,20 @@ require 'spec_helper'
describe DraftController do describe DraftController do
it 'requires you to be logged in' 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 end
it 'saves a draft on update' do it 'saves a draft on update' do
user = log_in user = log_in
post :update, draft_key: 'xyz', data: 'my data', sequence: 0 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 end
it 'destroys drafts when required' do it 'destroys drafts when required' do
user = log_in user = log_in
Draft.set(user, 'xxx', 0, 'hi') Draft.set(user, 'xxx', 0, 'hi')
delete :destroy, draft_key: 'xxx', sequence: 0 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
end end

View File

@ -5,7 +5,7 @@ describe EmailController do
context '.preferences_redirect' do context '.preferences_redirect' do
it 'requires you to be logged in' 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 end
context 'when logged in' do context 'when logged in' do
@ -13,7 +13,7 @@ describe EmailController do
it 'redirects to your user preferences' do it 'redirects to your user preferences' do
get :preferences_redirect get :preferences_redirect
response.should redirect_to("/users/#{user.username}/preferences") expect(response).to redirect_to("/users/#{user.username}/preferences")
end end
end end
@ -30,7 +30,7 @@ describe EmailController do
end end
it 'subscribes the user' do it 'subscribes the user' do
user.email_digests.should == true expect(user.email_digests).to eq(true)
end end
end end
@ -47,11 +47,11 @@ describe EmailController do
end end
it 'unsubscribes the user' do it 'unsubscribes the user' do
user.email_digests.should == false expect(user.email_digests).to eq(false)
end end
it "sets the appropriate instance variables" do it "sets the appropriate instance variables" do
assigns(:success).should be_present expect(assigns(:success)).to be_present
end end
end end
@ -61,7 +61,7 @@ describe EmailController do
end end
it "sets the appropriate instance variables" do it "sets the appropriate instance variables" do
assigns(:success).should be_blank expect(assigns(:success)).to be_blank
end end
end end
@ -74,12 +74,12 @@ describe EmailController do
end end
it 'does not unsubscribe the user' do it 'does not unsubscribe the user' do
user.email_digests.should == true expect(user.email_digests).to eq(true)
end end
it 'sets the appropriate instance variables' do it 'sets the appropriate instance variables' do
assigns(:success).should be_blank expect(assigns(:success)).to be_blank
assigns(:different_user).should be_present expect(assigns(:different_user)).to be_present
end end
end end
@ -92,17 +92,17 @@ describe EmailController do
end end
it 'unsubscribes the user' do it 'unsubscribes the user' do
user.email_digests.should == false expect(user.email_digests).to eq(false)
end end
it 'sets the appropriate instance variables' do it 'sets the appropriate instance variables' do
assigns(:success).should be_present expect(assigns(:success)).to be_present
end end
end end
it "sets not_found when the key didn't match anything" do it "sets not_found when the key didn't match anything" do
get :unsubscribe, key: 'asdfasdf' get :unsubscribe, key: 'asdfasdf'
assigns(:not_found).should == true expect(assigns(:not_found)).to eq(true)
end end
end end

View File

@ -7,13 +7,13 @@ describe EmbedController do
it "is 404 without an embed_url" do it "is 404 without an embed_url" do
get :comments get :comments
response.should_not be_success expect(response).not_to be_success
end end
it "raises an error with a missing host" do it "raises an error with a missing host" do
SiteSetting.stubs(:embeddable_host).returns(nil) SiteSetting.stubs(:embeddable_host).returns(nil)
get :comments, embed_url: embed_url get :comments, embed_url: embed_url
response.should_not be_success expect(response).not_to be_success
end end
context "with a host" do context "with a host" do
@ -23,7 +23,7 @@ describe EmbedController do
it "raises an error with no referer" do it "raises an error with no referer" do
get :comments, embed_url: embed_url get :comments, embed_url: embed_url
response.should_not be_success expect(response).not_to be_success
end end
context "success" do context "success" do
@ -33,8 +33,8 @@ describe EmbedController do
end end
after do after do
response.should be_success expect(response).to be_success
response.headers['X-Frame-Options'].should == "ALLOWALL" expect(response.headers['X-Frame-Options']).to eq("ALLOWALL")
end end
it "tells the topic retriever to work when no previous embed is found" do it "tells the topic retriever to work when no previous embed is found" do

View File

@ -11,19 +11,19 @@ describe ExportCsvController do
it "enqueues export job" do it "enqueues export job" do
Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "user_archive", user_id: @user.id)) 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" xhr :post, :export_entity, entity: "user_archive", entity_type: "user"
response.should be_success expect(response).to be_success
end end
it "should not enqueue export job if rate limit is reached" do it "should not enqueue export job if rate limit is reached" do
Jobs::ExportCsvFile.any_instance.expects(:execute).never Jobs::ExportCsvFile.any_instance.expects(:execute).never
UserExport.create(export_type: "user", user_id: @user.id) UserExport.create(export_type: "user", user_id: @user.id)
xhr :post, :export_entity, entity: "user_archive", entity_type: "user" xhr :post, :export_entity, entity: "user_archive", entity_type: "user"
response.should_not be_success expect(response).not_to be_success
end end
it "returns 404 when normal user tries to export admin entity" do it "returns 404 when normal user tries to export admin entity" do
xhr :post, :export_entity, entity: "staff_action", entity_type: "admin" xhr :post, :export_entity, entity: "staff_action", entity_type: "admin"
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -36,18 +36,18 @@ describe ExportCsvController do
UserExport.expects(:get_download_path).with(file_name).returns(export) UserExport.expects(:get_download_path).with(file_name).returns(export)
subject.expects(:send_file).with(export) subject.expects(:send_file).with(export)
get :show, id: file_name get :show, id: file_name
response.should be_success expect(response).to be_success
end end
it "returns 404 when the user tries to export another user's csv file" do it "returns 404 when the user tries to export another user's csv file" do
get :show, id: export_filename get :show, id: export_filename
response.should be_not_found expect(response).to be_not_found
end end
it "returns 404 when the export file does not exist" do it "returns 404 when the export file does not exist" do
UserExport.expects(:get_download_path).returns(nil) UserExport.expects(:get_download_path).returns(nil)
get :show, id: export_filename get :show, id: export_filename
response.should be_not_found expect(response).to be_not_found
end end
end end
end end
@ -60,14 +60,14 @@ describe ExportCsvController do
it "enqueues export job" do it "enqueues export job" do
Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id)) 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" xhr :post, :export_entity, entity: "staff_action", entity_type: "admin"
response.should be_success expect(response).to be_success
end end
it "should not rate limit export for staff" do 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)) 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) UserExport.create(export_type: "admin", user_id: @admin.id)
xhr :post, :export_entity, entity: "staff_action", entity_type: "admin" xhr :post, :export_entity, entity: "staff_action", entity_type: "admin"
response.should be_success expect(response).to be_success
end end
end end
@ -80,13 +80,13 @@ describe ExportCsvController do
UserExport.expects(:get_download_path).with(file_name).returns(export) UserExport.expects(:get_download_path).with(file_name).returns(export)
subject.expects(:send_file).with(export) subject.expects(:send_file).with(export)
get :show, id: file_name get :show, id: file_name
response.should be_success expect(response).to be_success
end end
it "returns 404 when the export file does not exist" do it "returns 404 when the export file does not exist" do
UserExport.expects(:get_download_path).returns(nil) UserExport.expects(:get_download_path).returns(nil)
get :show, id: export_filename get :show, id: export_filename
response.should be_not_found expect(response).to be_not_found
end end
end end
end end

View File

@ -7,21 +7,21 @@ describe GroupsController do
it "ensures the group can be seen" do it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false) Guardian.any_instance.expects(:can_see?).with(group).returns(false)
xhr :get, :show, id: group.name xhr :get, :show, id: group.name
response.should_not be_success expect(response).not_to be_success
end end
it "responds with JSON" do it "responds with JSON" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true) Guardian.any_instance.expects(:can_see?).with(group).returns(true)
xhr :get, :show, id: group.name xhr :get, :show, id: group.name
response.should be_success expect(response).to be_success
::JSON.parse(response.body)['basic_group']['id'].should == group.id expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id)
end end
it "works even with an upper case group name" do it "works even with an upper case group name" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true) Guardian.any_instance.expects(:can_see?).with(group).returns(true)
xhr :get, :show, id: group.name.upcase xhr :get, :show, id: group.name.upcase
response.should be_success expect(response).to be_success
::JSON.parse(response.body)['basic_group']['id'].should == group.id expect(::JSON.parse(response.body)['basic_group']['id']).to eq(group.id)
end end
end end
@ -29,14 +29,14 @@ describe GroupsController do
it "ensures the group can be seen" do it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false) Guardian.any_instance.expects(:can_see?).with(group).returns(false)
xhr :get, :counts, group_id: group.name xhr :get, :counts, group_id: group.name
response.should_not be_success expect(response).not_to be_success
end end
it "performs the query and responds with JSON" do it "performs the query and responds with JSON" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true) Guardian.any_instance.expects(:can_see?).with(group).returns(true)
Group.any_instance.expects(:posts_for).returns(Group.none) Group.any_instance.expects(:posts_for).returns(Group.none)
xhr :get, :counts, group_id: group.name xhr :get, :counts, group_id: group.name
response.should be_success expect(response).to be_success
end end
end end
@ -44,14 +44,14 @@ describe GroupsController do
it "ensures the group can be seen" do it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false) Guardian.any_instance.expects(:can_see?).with(group).returns(false)
xhr :get, :posts, group_id: group.name xhr :get, :posts, group_id: group.name
response.should_not be_success expect(response).not_to be_success
end end
it "calls `posts_for` and responds with JSON" do it "calls `posts_for` and responds with JSON" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true) Guardian.any_instance.expects(:can_see?).with(group).returns(true)
Group.any_instance.expects(:posts_for).returns(Group.none) Group.any_instance.expects(:posts_for).returns(Group.none)
xhr :get, :posts, group_id: group.name xhr :get, :posts, group_id: group.name
response.should be_success expect(response).to be_success
end end
end end
@ -59,13 +59,13 @@ describe GroupsController do
it "ensures the group can be seen" do it "ensures the group can be seen" do
Guardian.any_instance.expects(:can_see?).with(group).returns(false) Guardian.any_instance.expects(:can_see?).with(group).returns(false)
xhr :get, :members, group_id: group.name xhr :get, :members, group_id: group.name
response.should_not be_success expect(response).not_to be_success
end end
it "calls `posts_for` and responds with JSON" do it "calls `posts_for` and responds with JSON" do
Guardian.any_instance.expects(:can_see?).with(group).returns(true) Guardian.any_instance.expects(:can_see?).with(group).returns(true)
xhr :get, :posts, group_id: group.name xhr :get, :posts, group_id: group.name
response.should be_success expect(response).to be_success
end end
# Pending until we fix group truncation # Pending until we fix group truncation
@ -74,14 +74,14 @@ describe GroupsController do
usernames = group.users.map{ |m| m['username'] }.sort usernames = group.users.map{ |m| m['username'] }.sort
xhr :get, :members, group_id: group.name, limit: 3 xhr :get, :members, group_id: group.name, limit: 3
response.should be_success expect(response).to be_success
members = JSON.parse(response.body) 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 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 = 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 end
end end

View File

@ -5,9 +5,9 @@ describe InvitesController do
context '.destroy' do context '.destroy' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
delete :destroy, email: 'jake@adventuretime.ooo' delete :destroy, email: 'jake@adventuretime.ooo'
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in' do context 'while logged in' do
@ -17,15 +17,15 @@ describe InvitesController do
it 'raises an error when the email is missing' 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 end
it "raises an error when the email cannot be found" do 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 end
it 'raises an error when the invite is not yours' do 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 end
it "destroys the invite" do it "destroys the invite" do
@ -39,9 +39,9 @@ describe InvitesController do
context '.create' do context '.create' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
post :create, email: 'jake@adventuretime.ooo' post :create, email: 'jake@adventuretime.ooo'
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in' do context 'while logged in' do
@ -50,7 +50,7 @@ describe InvitesController do
it "fails if you can't invite to the forum" do it "fails if you can't invite to the forum" do
log_in log_in
post :create, email: email post :create, email: email
response.should_not be_success expect(response).not_to be_success
end end
it "fails for normal user if invite email already exists" do 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 = Invite.invite_by_email("invite@example.com", user)
invite.reload invite.reload
post :create, email: invite.email post :create, email: invite.email
response.should_not be_success expect(response).not_to be_success
end end
it "allows admins to invite to groups" do it "allows admins to invite to groups" do
group = Fabricate(:group) group = Fabricate(:group)
log_in(:admin) log_in(:admin)
post :create, email: email, group_names: group.name post :create, email: email, group_names: group.name
response.should be_success expect(response).to be_success
Invite.find_by(email: email).invited_groups.count.should == 1 expect(Invite.find_by(email: email).invited_groups.count).to eq(1)
end end
it "allows admin to send multiple invites to same email" do 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 = Invite.invite_by_email("invite@example.com", user)
invite.reload invite.reload
post :create, email: invite.email post :create, email: invite.email
response.should be_success expect(response).to be_success
end end
end end
@ -88,11 +88,11 @@ describe InvitesController do
end end
it "redirects to the root" do it "redirects to the root" do
response.should redirect_to("/") expect(response).to redirect_to("/")
end end
it "should not change the session" do it "should not change the session" do
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
end end
@ -105,11 +105,11 @@ describe InvitesController do
end end
it "redirects to the root" do it "redirects to the root" do
response.should redirect_to("/") expect(response).to redirect_to("/")
end end
it "should not change the session" do it "should not change the session" do
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
end end
@ -133,11 +133,11 @@ describe InvitesController do
end end
it 'logs in the user' do it 'logs in the user' do
session[:current_user_id].should == user.id expect(session[:current_user_id]).to eq(user.id)
end end
it 'redirects to the first topic the user was invited to' do 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
end end
@ -179,9 +179,9 @@ describe InvitesController do
context '.create_disposable_invite' do context '.create_disposable_invite' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
post :create, email: 'jake@adventuretime.ooo' post :create, email: 'jake@adventuretime.ooo'
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in as normal user' do context 'while logged in as normal user' do
@ -190,7 +190,7 @@ describe InvitesController do
it "does not create disposable invitation" do it "does not create disposable invitation" do
log_in log_in
post :create_disposable_invite, email: user.email post :create_disposable_invite, email: user.email
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -202,29 +202,29 @@ describe InvitesController do
it "creates disposable invitation" do it "creates disposable invitation" do
post :create_disposable_invite, email: user.email post :create_disposable_invite, email: user.email
response.should be_success expect(response).to be_success
Invite.where(invited_by_id: user.id).count.should == 1 expect(Invite.where(invited_by_id: user.id).count).to eq(1)
end end
it "creates multiple disposable invitations" do it "creates multiple disposable invitations" do
post :create_disposable_invite, email: user.email, quantity: 10 post :create_disposable_invite, email: user.email, quantity: 10
response.should be_success expect(response).to be_success
Invite.where(invited_by_id: user.id).count.should == 10 expect(Invite.where(invited_by_id: user.id).count).to eq(10)
end end
it "allows group invite" do it "allows group invite" do
group = Fabricate(:group) group = Fabricate(:group)
post :create_disposable_invite, email: user.email, group_names: group.name post :create_disposable_invite, email: user.email, group_names: group.name
response.should be_success expect(response).to be_success
Invite.find_by(invited_by_id: user.id).invited_groups.count.should == 1 expect(Invite.find_by(invited_by_id: user.id).invited_groups.count).to eq(1)
end end
it "allows multiple group invite" do it "allows multiple group invite" do
group_1 = Fabricate(:group, name: "security") group_1 = Fabricate(:group, name: "security")
group_2 = Fabricate(:group, name: "support") group_2 = Fabricate(:group, name: "support")
post :create_disposable_invite, email: user.email, group_names: "security,support" post :create_disposable_invite, email: user.email, group_names: "security,support"
response.should be_success expect(response).to be_success
Invite.find_by(invited_by_id: user.id).invited_groups.count.should == 2 expect(Invite.find_by(invited_by_id: user.id).invited_groups.count).to eq(2)
end end
end end
@ -239,11 +239,11 @@ describe InvitesController do
end end
it "redirects to the root" do it "redirects to the root" do
response.should redirect_to("/") expect(response).to redirect_to("/")
end end
it "should not change the session" do it "should not change the session" do
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
end end
@ -271,7 +271,7 @@ describe InvitesController do
end end
it 'logs in user' do it 'logs in user' do
session[:current_user_id].should == user.id expect(session[:current_user_id]).to eq(user.id)
end end
end end
@ -283,9 +283,9 @@ describe InvitesController do
context '.resend_invite' do context '.resend_invite' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
delete :resend_invite, email: 'first_name@example.com' delete :resend_invite, email: 'first_name@example.com'
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in' do context 'while logged in' do
@ -294,15 +294,15 @@ describe InvitesController do
let(:another_invite) { Fabricate(:invite, email: 'last_name@example.com') } let(:another_invite) { Fabricate(:invite, email: 'last_name@example.com') }
it 'raises an error when the email is missing' do 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 end
it "raises an error when the email cannot be found" do 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 end
it 'raises an error when the invite is not yours' do 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 end
it "resends the invite" do it "resends the invite" do
@ -316,9 +316,9 @@ describe InvitesController do
context '.check_csv_chunk' do context '.check_csv_chunk' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
post :check_csv_chunk post :check_csv_chunk
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in' do context 'while logged in' do
@ -330,7 +330,7 @@ describe InvitesController do
it "fails if you can't bulk invite to the forum" do it "fails if you can't bulk invite to the forum" do
log_in log_in
post :check_csv_chunk, resumableChunkNumber: resumableChunkNumber, resumableCurrentChunkSize: resumableCurrentChunkSize.to_i, resumableIdentifier: resumableIdentifier, resumableFilename: resumableFilename 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
end end
@ -339,9 +339,9 @@ describe InvitesController do
context '.upload_csv_chunk' do context '.upload_csv_chunk' do
it 'requires you to be logged in' do it 'requires you to be logged in' do
lambda { expect {
post :upload_csv_chunk post :upload_csv_chunk
}.should raise_error(Discourse::NotLoggedIn) }.to raise_error(Discourse::NotLoggedIn)
end end
context 'while logged in' do context 'while logged in' do
@ -361,13 +361,13 @@ describe InvitesController do
it "fails if you can't bulk invite to the forum" do it "fails if you can't bulk invite to the forum" do
log_in 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 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 end
it "allows admins to bulk invite" do it "allows admins to bulk invite" do
log_in(:admin) 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 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
end end

View File

@ -16,7 +16,7 @@ describe ListController do
(Discourse.anonymous_filters - [:categories]).each do |filter| (Discourse.anonymous_filters - [:categories]).each do |filter|
context "#{filter}" do context "#{filter}" do
before { xhr :get, filter } before { xhr :get, filter }
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
end end
@ -30,9 +30,9 @@ describe ListController do
p = create_post p = create_post
xhr :get, :latest, format: :json, topic_ids: "#{p.topic_id}" 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 = JSON.parse(response.body)
parsed["topic_list"]["topics"].length.should == 1 expect(parsed["topic_list"]["topics"].length).to eq(1)
end end
end end
@ -43,8 +43,8 @@ describe ListController do
it 'renders RSS' do it 'renders RSS' do
get "#{filter}_feed", format: :rss get "#{filter}_feed", format: :rss
response.should be_success expect(response).to be_success
response.content_type.should == 'application/rss+xml' expect(response.content_type).to eq('application/rss+xml')
end end
end end
@ -62,7 +62,7 @@ describe ListController do
xhr :get, :category_latest, category: category.slug xhr :get, :category_latest, category: category.slug
end end
it { should_not respond_with(:success) } it { is_expected.not_to respond_with(:success) }
end end
context 'with access to see the category' do context 'with access to see the category' do
@ -70,7 +70,7 @@ describe ListController do
xhr :get, :category_latest, category: category.slug xhr :get, :category_latest, category: category.slug
end end
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context 'with a link that includes an id' do 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}" xhr :get, :category_latest, category: "#{category.id}-#{category.slug}"
end end
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context 'another category exists with a number at the beginning of its name' do 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 xhr :get, :category_latest, category: other_category.slug
end end
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
it 'uses the correct category' do it 'uses the correct category' do
assigns(:category).should == other_category expect(assigns(:category)).to eq(other_category)
end end
end end
@ -104,7 +104,7 @@ describe ListController do
xhr :get, :category_latest, parent_category: category.slug, category: sub_category.slug xhr :get, :category_latest, parent_category: category.slug, category: sub_category.slug
end end
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context 'when child is requested with the wrong parent' do 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 xhr :get, :category_latest, parent_category: 'not_the_right_slug', category: sub_category.slug
end end
it { should_not respond_with(:success) } it { is_expected.not_to respond_with(:success) }
end end
end end
@ -120,8 +120,8 @@ describe ListController do
describe 'feed' do describe 'feed' do
it 'renders RSS' do it 'renders RSS' do
get :category_feed, category: category.slug, format: :rss get :category_feed, category: category.slug, format: :rss
response.should be_success expect(response).to be_success
response.content_type.should == 'application/rss+xml' expect(response.content_type).to eq('application/rss+xml')
end end
end end
end end
@ -132,7 +132,7 @@ describe ListController do
it "should respond with a list" do it "should respond with a list" do
xhr :get, :topics_by, username: @user.username xhr :get, :topics_by, username: @user.username
response.should be_success expect(response).to be_success
end end
end end
@ -142,13 +142,13 @@ describe ListController do
it "raises an error when can_see_private_messages? is false " do it "raises an error when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(false) Guardian.any_instance.expects(:can_see_private_messages?).returns(false)
xhr :get, :private_messages, username: @user.username xhr :get, :private_messages, username: @user.username
response.should be_forbidden expect(response).to be_forbidden
end end
it "succeeds when can_see_private_messages? is false " do it "succeeds when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(true) Guardian.any_instance.expects(:can_see_private_messages?).returns(true)
xhr :get, :private_messages, username: @user.username xhr :get, :private_messages, username: @user.username
response.should be_success expect(response).to be_success
end end
end end
@ -158,13 +158,13 @@ describe ListController do
it "raises an error when can_see_private_messages? is false " do it "raises an error when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(false) Guardian.any_instance.expects(:can_see_private_messages?).returns(false)
xhr :get, :private_messages_sent, username: @user.username xhr :get, :private_messages_sent, username: @user.username
response.should be_forbidden expect(response).to be_forbidden
end end
it "succeeds when can_see_private_messages? is false " do it "succeeds when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(true) Guardian.any_instance.expects(:can_see_private_messages?).returns(true)
xhr :get, :private_messages_sent, username: @user.username xhr :get, :private_messages_sent, username: @user.username
response.should be_success expect(response).to be_success
end end
end end
@ -174,19 +174,19 @@ describe ListController do
it "raises an error when can_see_private_messages? is false " do it "raises an error when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(false) Guardian.any_instance.expects(:can_see_private_messages?).returns(false)
xhr :get, :private_messages_unread, username: @user.username xhr :get, :private_messages_unread, username: @user.username
response.should be_forbidden expect(response).to be_forbidden
end end
it "succeeds when can_see_private_messages? is false " do it "succeeds when can_see_private_messages? is false " do
Guardian.any_instance.expects(:can_see_private_messages?).returns(true) Guardian.any_instance.expects(:can_see_private_messages?).returns(true)
xhr :get, :private_messages_unread, username: @user.username xhr :get, :private_messages_unread, username: @user.username
response.should be_success expect(response).to be_success
end end
end end
context 'read' do context 'read' do
it 'raises an error when not logged in' 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 end
context 'when logged in' do context 'when logged in' do
@ -195,32 +195,32 @@ describe ListController do
xhr :get, :read xhr :get, :read
end end
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
end end
describe "best_periods_for" do describe "best_periods_for" do
it "returns yearly for more than 180 days" do it "returns yearly for more than 180 days" do
ListController.best_periods_for(nil).should == [:yearly] expect(ListController.best_periods_for(nil)).to eq([:yearly])
ListController.best_periods_for(180.days.ago).should == [:yearly] expect(ListController.best_periods_for(180.days.ago)).to eq([:yearly])
end end
it "includes monthly when less than 180 days and more than 35 days" do it "includes monthly when less than 180 days and more than 35 days" do
(35...180).each do |date| (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
end end
it "includes weekly when less than 35 days and more than 8 days" do it "includes weekly when less than 35 days and more than 8 days" do
(8...35).each do |date| (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
end end
it "includes daily when less than 8 days" do it "includes daily when less than 8 days" do
(0...8).each do |date| (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
end end

View File

@ -7,51 +7,51 @@ describe NotificationsController do
it 'should succeed for recent' do it 'should succeed for recent' do
xhr :get, :recent xhr :get, :recent
response.should be_success expect(response).to be_success
end end
it 'should succeed for history' do it 'should succeed for history' do
xhr :get, :history xhr :get, :history
response.should be_success expect(response).to be_success
end end
it 'should succeed for history' do it 'should succeed for history' do
xhr :get, :reset_new xhr :get, :reset_new
response.should be_success expect(response).to be_success
end end
it 'should mark notifications as viewed' do it 'should mark notifications as viewed' do
notification = Fabricate(:notification, user: user) notification = Fabricate(:notification, user: user)
user.reload.unread_notifications.should == 1 expect(user.reload.unread_notifications).to eq(1)
user.reload.total_unread_notifications.should == 1 expect(user.reload.total_unread_notifications).to eq(1)
xhr :get, :recent xhr :get, :recent
user.reload.unread_notifications.should == 0 expect(user.reload.unread_notifications).to eq(0)
user.reload.total_unread_notifications.should == 1 expect(user.reload.total_unread_notifications).to eq(1)
end end
it 'should not mark notifications as viewed if silent param is present' do it 'should not mark notifications as viewed if silent param is present' do
notification = Fabricate(:notification, user: user) notification = Fabricate(:notification, user: user)
user.reload.unread_notifications.should == 1 expect(user.reload.unread_notifications).to eq(1)
user.reload.total_unread_notifications.should == 1 expect(user.reload.total_unread_notifications).to eq(1)
xhr :get, :recent, silent: true xhr :get, :recent, silent: true
user.reload.unread_notifications.should == 1 expect(user.reload.unread_notifications).to eq(1)
user.reload.total_unread_notifications.should == 1 expect(user.reload.total_unread_notifications).to eq(1)
end end
it "updates the `read` status" do it "updates the `read` status" do
notification = Fabricate(:notification, user: user) notification = Fabricate(:notification, user: user)
user.reload.unread_notifications.should == 1 expect(user.reload.unread_notifications).to eq(1)
user.reload.total_unread_notifications.should == 1 expect(user.reload.total_unread_notifications).to eq(1)
xhr :put, :reset_new xhr :put, :reset_new
user.reload user.reload
user.reload.unread_notifications.should == 0 expect(user.reload.unread_notifications).to eq(0)
user.reload.total_unread_notifications.should == 0 expect(user.reload.total_unread_notifications).to eq(0)
end end
end end
context 'when not logged in' do context 'when not logged in' do
it 'should raise an error' 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
end end

View File

@ -19,11 +19,11 @@ describe OneboxController do
end end
it 'returns success' do it 'returns success' do
response.should be_success expect(response).to be_success
end end
it 'returns the onebox response in the body' do it 'returns the onebox response in the body' do
response.body.should == body expect(response.body).to eq(body)
end end
end end
@ -33,13 +33,13 @@ describe OneboxController do
it "returns 404 if the onebox is nil" do it "returns 404 if the onebox is nil" do
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(nil) Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(nil)
xhr :get, :show, url: url xhr :get, :show, url: url
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
it "returns 404 if the onebox is an empty string" do it "returns 404 if the onebox is an empty string" do
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(" \t ") Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(" \t ")
xhr :get, :show, url: url xhr :get, :show, url: url
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
end end

View File

@ -6,13 +6,13 @@ describe PermalinksController do
permalink = Fabricate(:permalink) permalink = Fabricate(:permalink)
Permalink.any_instance.stubs(:target_url).returns('/t/the-topic-slug/42') Permalink.any_instance.stubs(:target_url).returns('/t/the-topic-slug/42')
get :show, url: permalink.url get :show, url: permalink.url
response.should redirect_to('/t/the-topic-slug/42') expect(response).to redirect_to('/t/the-topic-slug/42')
response.status.should == 301 expect(response.status).to eq(301)
end end
it 'return 404 if permalink record does not exist' do it 'return 404 if permalink record does not exist' do
get :show, url: '/not/a/valid/url' get :show, url: '/not/a/valid/url'
response.status.should == 404 expect(response.status).to eq(404)
end end
end end

View File

@ -4,7 +4,7 @@ describe PostActionsController do
describe 'create' do describe 'create' do
it 'requires you to be logged in' 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 end
describe 'logged in' do describe 'logged in' do
@ -14,23 +14,23 @@ describe PostActionsController do
end end
it 'raises an error when the id is missing' do 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 end
it 'raises an error when the post_action_type_id index is missing' do 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 end
it "fails when the user doesn't have permission to see the post" do it "fails when the user doesn't have permission to see the post" do
Guardian.any_instance.expects(:can_see?).with(@post).returns(false) Guardian.any_instance.expects(:can_see?).with(@post).returns(false)
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like] xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
response.should be_forbidden expect(response).to be_forbidden
end end
it "fails when the user doesn't have permission to perform that action" do 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) 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] xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
response.should be_forbidden expect(response).to be_forbidden
end end
it 'allows us to create an post action on a post' do 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)) } let(:post) { Fabricate(:post, user: Fabricate(:coding_horror)) }
it 'requires you to be logged in' do 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 end
context 'logged in' do context 'logged in' do
let!(:user) { log_in } let!(:user) { log_in }
it 'raises an error when the post_action_type_id is missing' do 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 end
it "returns 404 when the post action type doesn't exist for that user" do 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 xhr :delete, :destroy, id: post.id, post_action_type_id: 1
response.code.should == '404' expect(response.code).to eq('404')
end end
context 'with a post_action record ' do context 'with a post_action record ' do
@ -89,18 +89,18 @@ describe PostActionsController do
it 'returns success' do it 'returns success' do
xhr :delete, :destroy, id: post.id, post_action_type_id: 1 xhr :delete, :destroy, id: post.id, post_action_type_id: 1
response.should be_success expect(response).to be_success
end end
it 'deletes the action' do it 'deletes the action' do
xhr :delete, :destroy, id: post.id, post_action_type_id: 1 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 end
it 'ensures it can be deleted' do it 'ensures it can be deleted' do
Guardian.any_instance.expects(:can_delete?).with(post_action).returns(false) Guardian.any_instance.expects(:can_delete?).with(post_action).returns(false)
xhr :delete, :destroy, id: post.id, post_action_type_id: 1 xhr :delete, :destroy, id: post.id, post_action_type_id: 1
response.should be_forbidden expect(response).to be_forbidden
end end
end end
@ -114,7 +114,7 @@ describe PostActionsController do
context "not logged in" do context "not logged in" do
it "should not allow them to clear flags" 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
end end
@ -122,13 +122,13 @@ describe PostActionsController do
let!(:user) { log_in(:moderator) } let!(:user) { log_in(:moderator) }
it "raises an error without a post_action_type_id" do 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 end
it "raises an error when the user doesn't have access" do it "raises an error when the user doesn't have access" do
Guardian.any_instance.expects(:can_defer_flags?).returns(false) Guardian.any_instance.expects(:can_defer_flags?).returns(false)
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] 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 end
context "success" do context "success" do
@ -139,13 +139,13 @@ describe PostActionsController do
it "delegates to defer_flags" do it "delegates to defer_flags" do
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] 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
it "works with a deleted post" do it "works with a deleted post" do
flagged_post.trash!(user) flagged_post.trash!(user)
xhr :post, :defer_flags, id: flagged_post.id, post_action_type_id: PostActionType.types[:spam] 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
end end
@ -159,32 +159,32 @@ describe PostActionsController do
let!(:post) { Fabricate(:post, user: log_in) } let!(:post) { Fabricate(:post, user: log_in) }
it 'raises an error without an id' do it 'raises an error without an id' do
lambda { expect {
xhr :get, :users, post_action_type_id: PostActionType.types[:like] xhr :get, :users, post_action_type_id: PostActionType.types[:like]
}.should raise_error(ActionController::ParameterMissing) }.to raise_error(ActionController::ParameterMissing)
end end
it 'raises an error without a post action type' do it 'raises an error without a post action type' do
lambda { expect {
xhr :get, :users, id: post.id xhr :get, :users, id: post.id
}.should raise_error(ActionController::ParameterMissing) }.to raise_error(ActionController::ParameterMissing)
end end
it "fails when the user doesn't have permission to see the post" do it "fails when the user doesn't have permission to see the post" do
Guardian.any_instance.expects(:can_see?).with(post).returns(false) Guardian.any_instance.expects(:can_see?).with(post).returns(false)
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like] xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
response.should be_forbidden expect(response).to be_forbidden
end end
it 'raises an error when the post action type cannot be seen' do 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) 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] xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
response.should be_forbidden expect(response).to be_forbidden
end end
it 'succeeds' do it 'succeeds' do
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like] xhr :get, :users, id: post.id, post_action_type_id: PostActionType.types[:like]
response.should be_success expect(response).to be_success
end end
end end

View File

@ -7,12 +7,12 @@ shared_examples 'finding and showing post' do
it 'ensures the user can see the post' do it 'ensures the user can see the post' do
Guardian.any_instance.expects(:can_see?).with(post).returns(false) Guardian.any_instance.expects(:can_see?).with(post).returns(false)
xhr :get, action, params xhr :get, action, params
response.should be_forbidden expect(response).to be_forbidden
end end
it 'succeeds' do it 'succeeds' do
xhr :get, action, params xhr :get, action, params
response.should be_success expect(response).to be_success
end end
context "deleted post" do 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 it "can't find deleted posts as an anonymous user" do
xhr :get, action, params xhr :get, action, params
response.status.should == 404 expect(response.status).to eq(404)
end end
it "can't find deleted posts as a regular user" do it "can't find deleted posts as a regular user" do
log_in(:user) log_in(:user)
xhr :get, action, params xhr :get, action, params
response.status.should == 404 expect(response.status).to eq(404)
end end
it "can find posts as a moderator" do it "can find posts as a moderator" do
log_in(:moderator) log_in(:moderator)
xhr :get, action, params xhr :get, action, params
response.should be_success expect(response).to be_success
end end
it "can find posts as a admin" do it "can find posts as a admin" do
log_in(:admin) log_in(:admin)
xhr :get, action, params xhr :get, action, params
response.should be_success expect(response).to be_success
end end
end end
end end
shared_examples 'action requires login' do |method, action, params| shared_examples 'action requires login' do |method, action, params|
it 'raises an exception when not logged in' do 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
end end
@ -61,10 +61,10 @@ describe PostsController do
it 'returns the cooked conent' do it 'returns the cooked conent' do
xhr :get, :cooked, id: 1234 xhr :get, :cooked, id: 1234
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json.should be_present expect(json).to be_present
json['cooked'].should == 'wat' expect(json['cooked']).to eq('wat')
end end
end end
@ -80,7 +80,7 @@ describe PostsController do
xhr :get, :raw_email, id: post.id xhr :get, :raw_email, id: post.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "can view raw email" do it "can view raw email" do
@ -88,9 +88,9 @@ describe PostsController do
xhr :get, :raw_email, id: post.id xhr :get, :raw_email, id: post.id
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['raw_email'].should == 'email_content' expect(json['raw_email']).to eq('email_content')
end end
end end
@ -108,10 +108,10 @@ describe PostsController do
new_post = create_post new_post = create_post
xhr :get, :show, {id: new_post.id} xhr :get, :show, {id: new_post.id}
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["topic_slug"].should == new_post.topic.slug expect(parsed["topic_slug"]).to eq(new_post.topic.slug)
parsed["moderator"].should == false expect(parsed["moderator"]).to eq(false)
parsed["username"].should == new_post.user.username expect(parsed["username"]).to eq(new_post.user.username)
parsed["cooked"].should == new_post.cooked expect(parsed["cooked"]).to eq(new_post.cooked)
end end
end end
@ -160,14 +160,14 @@ describe PostsController do
xhr :delete, :destroy, id: post.id xhr :delete, :destroy, id: post.id
response.status.should == 422 expect(response.status).to eq(422)
JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit')) expect(JSON.parse(response.body)['errors']).to include(I18n.t('too_late_to_edit'))
end end
it "raises an error when the user doesn't have permission to see the post" do 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) Guardian.any_instance.expects(:can_delete?).with(post).returns(false)
xhr :delete, :destroy, id: post.id xhr :delete, :destroy, id: post.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "uses a PostDestroyer" do 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 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) Guardian.any_instance.expects(:can_recover_post?).with(post).returns(false)
xhr :put, :recover, post_id: post.id xhr :put, :recover, post_id: post.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "recovers a post correctly" do it "recovers a post correctly" do
@ -201,7 +201,7 @@ describe PostsController do
PostDestroyer.new(user, post).destroy PostDestroyer.new(user, post).destroy
xhr :put, :recover, post_id: post.id xhr :put, :recover, post_id: post.id
post.reload post.reload
post.deleted_at.should == nil expect(post.deleted_at).to eq(nil)
end end
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) } 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 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 end
it "raises invalid parameters with missing ids" do 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 end
it "raises an error when the user doesn't have permission to delete the posts" do 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) Guardian.any_instance.expects(:can_delete?).with(instance_of(Post)).returns(false)
xhr :delete, :destroy_many, post_ids: [post1.id, post2.id] xhr :delete, :destroy_many, post_ids: [post1.id, post2.id]
response.should be_forbidden expect(response).to be_forbidden
end end
it "deletes the post" do it "deletes the post" do
@ -278,8 +278,8 @@ describe PostsController do
xhr :put, :update, update_params xhr :put, :update, update_params
response.status.should == 422 expect(response.status).to eq(422)
JSON.parse(response.body)['errors'].should include(I18n.t('too_late_to_edit')) expect(JSON.parse(response.body)['errors']).to include(I18n.t('too_late_to_edit'))
end end
it 'passes the image sizes through' do 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 it "raises an error when the post parameter is missing" do
update_params.delete(:post) update_params.delete(:post)
lambda { expect {
xhr :put, :update, update_params xhr :put, :update, update_params
}.should raise_error(ActionController::ParameterMissing) }.to raise_error(ActionController::ParameterMissing)
end end
it "raises an error when the user doesn't have permission to see the post" do 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) Guardian.any_instance.expects(:can_edit?).with(post).at_least_once.returns(false)
xhr :put, :update, update_params xhr :put, :update, update_params
response.should be_forbidden expect(response).to be_forbidden
end end
it "calls revise with valid parameters" do 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 Guardian.any_instance.expects(:can_see?).with(post).returns(false).once
xhr :put, :bookmark, post_id: post.id, bookmarked: 'true' xhr :put, :bookmark, post_id: post.id, bookmarked: 'true'
response.should be_forbidden expect(response).to be_forbidden
end end
it 'creates a bookmark' do it 'creates a bookmark' do
@ -361,7 +361,7 @@ describe PostsController do
xhr :put, :wiki, post_id: post.id, wiki: 'true' xhr :put, :wiki, post_id: post.id, wiki: 'true'
response.should be_forbidden expect(response).to be_forbidden
end end
it "can wiki a post" do it "can wiki a post" do
@ -370,7 +370,7 @@ describe PostsController do
xhr :put, :wiki, post_id: post.id, wiki: 'true' xhr :put, :wiki, post_id: post.id, wiki: 'true'
post.reload post.reload
post.wiki.should == true expect(post.wiki).to eq(true)
end end
it "can unwiki a post" do it "can unwiki a post" do
@ -380,7 +380,7 @@ describe PostsController do
xhr :put, :wiki, post_id: wikied_post.id, wiki: 'false' xhr :put, :wiki, post_id: wikied_post.id, wiki: 'false'
wikied_post.reload wikied_post.reload
wikied_post.wiki.should == false expect(wikied_post.wiki).to eq(false)
end end
end end
@ -400,7 +400,7 @@ describe PostsController do
xhr :put, :post_type, post_id: post.id, post_type: 2 xhr :put, :post_type, post_id: post.id, post_type: 2
response.should be_forbidden expect(response).to be_forbidden
end end
it "can change the post type" do 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 xhr :put, :post_type, post_id: post.id, post_type: 2
post.reload post.reload
post.post_type.should == 2 expect(post.post_type).to eq(2)
end end
end end
@ -429,7 +429,7 @@ describe PostsController do
xhr :put, :rebake, post_id: post.id xhr :put, :rebake, post_id: post.id
response.should be_forbidden expect(response).to be_forbidden
end end
it "can rebake the post" do it "can rebake the post" do
@ -437,7 +437,7 @@ describe PostsController do
xhr :put, :rebake, post_id: post.id xhr :put, :rebake, post_id: post.id
response.should be_success expect(response).to be_success
end end
end end
@ -457,13 +457,13 @@ describe PostsController do
master_key = ApiKey.create_master_key.key master_key = ApiKey.create_master_key.key
xhr :post, :create, {api_username: user.username, api_key: master_key, raw: raw, title: title, wpid: 1} 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 original = response.body
xhr :post, :create, {api_username: user.username_lower, api_key: master_key, raw: raw, title: title, wpid: 2} 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
end end
@ -474,19 +474,19 @@ describe PostsController do
let(:new_post) { Fabricate.build(:post, user: user) } let(:new_post) { Fabricate.build(:post, user: user) }
it "raises an exception without a raw parameter" do 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 end
it 'calls the post creator' do it 'calls the post creator' do
PostCreator.any_instance.expects(:create).returns(new_post) PostCreator.any_instance.expects(:create).returns(new_post)
xhr :post, :create, {raw: 'test'} xhr :post, :create, {raw: 'test'}
response.should be_success expect(response).to be_success
end end
it 'returns JSON of the post' do it 'returns JSON of the post' do
PostCreator.any_instance.expects(:create).returns(new_post) PostCreator.any_instance.expects(:create).returns(new_post)
xhr :post, :create, {raw: 'test'} xhr :post, :create, {raw: 'test'}
::JSON.parse(response.body).should be_present expect(::JSON.parse(response.body)).to be_present
end end
it 'protects against dupes' do it 'protects against dupes' do
@ -494,10 +494,10 @@ describe PostsController do
title = "this is a title #{SecureRandom.hash}" title = "this is a title #{SecureRandom.hash}"
xhr :post, :create, {raw: raw, title: title, wpid: 1} 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} xhr :post, :create, {raw: raw, title: title, wpid: 2}
response.should_not be_success expect(response).not_to be_success
end end
context "errors" do context "errors" do
@ -513,7 +513,7 @@ describe PostsController do
it "does not succeed" do it "does not succeed" do
xhr :post, :create, {raw: 'test'} xhr :post, :create, {raw: 'test'}
User.any_instance.expects(:flag_linked_posts_as_spam).never User.any_instance.expects(:flag_linked_posts_as_spam).never
response.should_not be_success expect(response).not_to be_success
end end
it "it triggers flag_linked_posts_as_spam when the post creator returns spam" do 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 it "ensures anonymous cannot see the revisions" do
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_forbidden expect(response).to be_forbidden
end end
it "ensures regular user cannot see the revisions" do it "ensures regular user cannot see the revisions" do
u = log_in(:user) u = log_in(:user)
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_forbidden expect(response).to be_forbidden
end end
it "ensures staff can see the revisions" do it "ensures staff can see the revisions" do
log_in(:admin) log_in(:admin)
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_success expect(response).to be_success
end end
it "ensures poster can see the revisions" do it "ensures poster can see the revisions" do
@ -639,13 +639,13 @@ describe PostsController do
post = Fabricate(:post, user: user, version: 3) post = Fabricate(:post, user: user, version: 3)
pr = Fabricate(:post_revision, user: user, post: post) pr = Fabricate(:post_revision, user: user, post: post)
xhr :get, :revisions, post_id: pr.post_id, revision: pr.number xhr :get, :revisions, post_id: pr.post_id, revision: pr.number
response.should be_success expect(response).to be_success
end end
it "ensures trust level 4 can see the revisions" do it "ensures trust level 4 can see the revisions" do
log_in(:trust_level_4) log_in(:trust_level_4)
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_success expect(response).to be_success
end end
end end
@ -656,7 +656,7 @@ describe PostsController do
it "ensures anyone can see the revisions" do it "ensures anyone can see the revisions" do
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_success expect(response).to be_success
end end
end end
@ -670,7 +670,7 @@ describe PostsController do
it "also work on deleted post" do it "also work on deleted post" do
xhr :get, :revisions, post_id: deleted_post_revision.post_id, revision: deleted_post_revision.number 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
end end
@ -684,7 +684,7 @@ describe PostsController do
it "also work on deleted topic" do it "also work on deleted topic" do
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
response.should be_success expect(response).to be_success
end end
end end
@ -696,15 +696,15 @@ describe PostsController do
it "raises an error when you can't see the post" do it "raises an error when you can't see the post" do
Guardian.any_instance.expects(:can_see?).with(post).returns(false) Guardian.any_instance.expects(:can_see?).with(post).returns(false)
xhr :get, :expand_embed, id: post.id xhr :get, :expand_embed, id: post.id
response.should_not be_success expect(response).not_to be_success
end end
it "retrieves the body when you can see the post" do it "retrieves the body when you can see the post" do
Guardian.any_instance.expects(:can_see?).with(post).returns(true) Guardian.any_instance.expects(:can_see?).with(post).returns(true)
TopicEmbed.expects(:expanded_for).with(post).returns("full content") TopicEmbed.expects(:expanded_for).with(post).returns("full content")
xhr :get, :expand_embed, id: post.id xhr :get, :expand_embed, id: post.id
response.should be_success expect(response).to be_success
::JSON.parse(response.body)['cooked'].should == "full content" expect(::JSON.parse(response.body)['cooked']).to eq("full content")
end end
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 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) Guardian.any_instance.expects(:can_see_flagged_posts?).returns(false)
xhr :get, :flagged_posts, username: "system" xhr :get, :flagged_posts, username: "system"
response.should be_forbidden expect(response).to be_forbidden
end end
it "can see the flagged posts when authorized" do it "can see the flagged posts when authorized" do
Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true) Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true)
xhr :get, :flagged_posts, username: "system" xhr :get, :flagged_posts, username: "system"
response.should be_success expect(response).to be_success
end end
it "only shows agreed and deferred flags" do 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) Guardian.any_instance.expects(:can_see_flagged_posts?).returns(true)
xhr :get, :flagged_posts, username: user.username 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
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 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) Guardian.any_instance.expects(:can_see_deleted_posts?).returns(false)
xhr :get, :deleted_posts, username: "system" xhr :get, :deleted_posts, username: "system"
response.should be_forbidden expect(response).to be_forbidden
end end
it "can see the deleted posts when authorized" do it "can see the deleted posts when authorized" do
Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true) Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true)
xhr :get, :deleted_posts, username: "system" xhr :get, :deleted_posts, username: "system"
response.should be_success expect(response).to be_success
end end
it "only shows posts deleted by other users" do 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) Guardian.any_instance.expects(:can_see_deleted_posts?).returns(true)
xhr :get, :deleted_posts, username: user.username xhr :get, :deleted_posts, username: user.username
response.should be_success expect(response).to be_success
data = JSON.parse(response.body) data = JSON.parse(response.body)
data.length.should == 1 expect(data.length).to eq(1)
data[0]["id"].should == post_deleted_by_admin.id expect(data[0]["id"]).to eq(post_deleted_by_admin.id)
data[0]["deleted_by"]["id"].should == admin.id expect(data[0]["deleted_by"]["id"]).to eq(admin.id)
end end
end end

View File

@ -7,13 +7,13 @@ describe RobotsTxtController do
it "returns index when indexing is allowed" do it "returns index when indexing is allowed" do
SiteSetting.stubs(:allow_index_in_robots_txt).returns(true) SiteSetting.stubs(:allow_index_in_robots_txt).returns(true)
get :index get :index
response.should render_template :index expect(response).to render_template :index
end end
it "returns noindex when indexing is disallowed" do it "returns noindex when indexing is disallowed" do
SiteSetting.stubs(:allow_index_in_robots_txt).returns(false) SiteSetting.stubs(:allow_index_in_robots_txt).returns(false)
get :index get :index
response.should render_template :no_index expect(response).to render_template :no_index
end end
end end

View File

@ -12,11 +12,11 @@ describe SearchController do
my_post = Fabricate(:post, raw: 'this is my really awesome post') my_post = Fabricate(:post, raw: 'this is my really awesome post')
xhr :get, :query, term: 'awesome', include_blurb: true xhr :get, :query, term: 'awesome', include_blurb: true
response.should be_success expect(response).to be_success
data = JSON.parse(response.body) data = JSON.parse(response.body)
data['posts'][0]['id'].should == my_post.id expect(data['posts'][0]['id']).to eq(my_post.id)
data['posts'][0]['blurb'].should == 'this is my really awesome post' expect(data['posts'][0]['blurb']).to eq('this is my really awesome post')
data['topics'][0]['id'].should == my_post.topic_id expect(data['topics'][0]['id']).to eq(my_post.topic_id)
end end
end end
@ -64,15 +64,15 @@ describe SearchController do
context "search context" do context "search context" do
it "raises an error with an invalid context type" do it "raises an error with an invalid context type" do
lambda { expect {
xhr :get, :query, term: 'test', search_context: {type: 'security', id: 'hole'} xhr :get, :query, term: 'test', search_context: {type: 'security', id: 'hole'}
}.should raise_error(Discourse::InvalidParameters) }.to raise_error(Discourse::InvalidParameters)
end end
it "raises an error with a missing id" do it "raises an error with a missing id" do
lambda { expect {
xhr :get, :query, term: 'test', search_context: {type: 'user'} xhr :get, :query, term: 'test', search_context: {type: 'user'}
}.should raise_error(Discourse::InvalidParameters) }.to raise_error(Discourse::InvalidParameters)
end end
context "with a user" do 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 it "raises an error if the user can't see the context" do
Guardian.any_instance.expects(:can_see?).with(user).returns(false) Guardian.any_instance.expects(:can_see?).with(user).returns(false)
xhr :get, :query, term: 'test', search_context: {type: 'user', id: user.username} xhr :get, :query, term: 'test', search_context: {type: 'user', id: user.username}
response.should_not be_success expect(response).not_to be_success
end end

View File

@ -8,15 +8,15 @@ describe SessionController do
it "does not work when not in development mode" do it "does not work when not in development mode" do
Rails.env.stubs(:development?).returns(false) Rails.env.stubs(:development?).returns(false)
get :become, session_id: user.username get :become, session_id: user.username
response.should_not be_redirect expect(response).not_to be_redirect
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it "works in developmenet mode" do it "works in developmenet mode" do
Rails.env.stubs(:development?).returns(true) Rails.env.stubs(:development?).returns(true)
get :become, session_id: user.username get :become, session_id: user.username
response.should be_redirect expect(response).to be_redirect
session[:current_user_id].should == user.id expect(session[:current_user_id]).to eq(user.id)
end end
end end
@ -58,11 +58,11 @@ describe SessionController do
get :sso_login, Rack::Utils.parse_query(sso.payload) 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 = Discourse.current_user_provider.new(request.env).current_user
logged_on_user.email.should == user.email expect(logged_on_user.email).to eq(user.email)
logged_on_user.single_sign_on_record.external_id.should == "abc" expect(logged_on_user.single_sign_on_record.external_id).to eq("abc")
logged_on_user.single_sign_on_record.external_username.should == 'sam' expect(logged_on_user.single_sign_on_record.external_username).to eq('sam')
end end
it 'allows you to create an admin account' do 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) get :sso_login, Rack::Utils.parse_query(sso.payload)
logged_on_user = Discourse.current_user_provider.new(request.env).current_user 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 end
@ -92,24 +92,24 @@ describe SessionController do
sso.custom_fields["shop_name"] = "Sam" sso.custom_fields["shop_name"] = "Sam"
get :sso_login, Rack::Utils.parse_query(sso.payload) 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 logged_on_user = Discourse.current_user_provider.new(request.env).current_user
# ensure nothing is transient # ensure nothing is transient
logged_on_user = User.find(logged_on_user.id) logged_on_user = User.find(logged_on_user.id)
logged_on_user.admin.should == false expect(logged_on_user.admin).to eq(false)
logged_on_user.email.should == 'bob@bob.com' expect(logged_on_user.email).to eq('bob@bob.com')
logged_on_user.name.should == 'Sam Saffron' expect(logged_on_user.name).to eq('Sam Saffron')
logged_on_user.username.should == 'sam' expect(logged_on_user.username).to eq('sam')
logged_on_user.single_sign_on_record.external_id.should == "666" expect(logged_on_user.single_sign_on_record.external_id).to eq("666")
logged_on_user.single_sign_on_record.external_username.should == 'sam' expect(logged_on_user.single_sign_on_record.external_username).to eq('sam')
logged_on_user.active.should == true expect(logged_on_user.active).to eq(true)
logged_on_user.custom_fields["shop_url"].should == "http://my_shop.com" expect(logged_on_user.custom_fields["shop_url"]).to eq("http://my_shop.com")
logged_on_user.custom_fields["shop_name"].should == "Sam" expect(logged_on_user.custom_fields["shop_name"]).to eq("Sam")
logged_on_user.custom_fields["bla"].should == nil expect(logged_on_user.custom_fields["bla"]).to eq(nil)
end end
it 'allows login to existing account with valid nonce' do 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) get :sso_login, Rack::Utils.parse_query(sso.payload)
user.single_sign_on_record.reload 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 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 # nonce is bad now
get :sso_login, Rack::Utils.parse_query(sso.payload) get :sso_login, Rack::Utils.parse_query(sso.payload)
response.code.should == '500' expect(response.code).to eq('500')
end end
it 'can act as an SSO provider' do it 'can act as an SSO provider' do
@ -148,7 +148,7 @@ describe SessionController do
get :sso_provider, Rack::Utils.parse_query(sso.payload) 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) user = Fabricate(:user, password: "frogs", active: true, admin: true)
EmailToken.update_all(confirmed: true) EmailToken.update_all(confirmed: true)
@ -156,18 +156,18 @@ describe SessionController do
xhr :post, :create, login: user.username, password: "frogs", format: :json xhr :post, :create, login: user.username, password: "frogs", format: :json
location = response.header["Location"] location = response.header["Location"]
location.should =~ /^http:\/\/somewhere.over.rainbow\/sso/ expect(location).to match(/^http:\/\/somewhere.over.rainbow\/sso/)
payload = location.split("?")[1] payload = location.split("?")[1]
sso2 = SingleSignOn.parse(payload, "topsecret") sso2 = SingleSignOn.parse(payload, "topsecret")
sso2.email.should == user.email expect(sso2.email).to eq(user.email)
sso2.name.should == user.name expect(sso2.name).to eq(user.name)
sso2.username.should == user.username expect(sso2.username).to eq(user.username)
sso2.external_id.should == user.id.to_s expect(sso2.external_id).to eq(user.id.to_s)
sso2.admin.should == true expect(sso2.admin).to eq(true)
sso2.moderator.should == false expect(sso2.moderator).to eq(false)
end end
@ -196,18 +196,18 @@ describe SessionController do
it 'stores the external attributes' do it 'stores the external attributes' do
get :sso_login, Rack::Utils.parse_query(@sso.payload) get :sso_login, Rack::Utils.parse_query(@sso.payload)
@user.single_sign_on_record.reload @user.single_sign_on_record.reload
@user.single_sign_on_record.external_username.should == @sso.username expect(@user.single_sign_on_record.external_username).to eq(@sso.username)
@user.single_sign_on_record.external_email.should == @sso.email expect(@user.single_sign_on_record.external_email).to eq(@sso.email)
@user.single_sign_on_record.external_name.should == @sso.name expect(@user.single_sign_on_record.external_name).to eq(@sso.name)
end end
it 'overrides attributes' do it 'overrides attributes' do
get :sso_login, Rack::Utils.parse_query(@sso.payload) get :sso_login, Rack::Utils.parse_query(@sso.payload)
logged_on_user = Discourse.current_user_provider.new(request.env).current_user logged_on_user = Discourse.current_user_provider.new(request.env).current_user
logged_on_user.username.should == @suggested_username expect(logged_on_user.username).to eq(@suggested_username)
logged_on_user.email.should == "#{@reversed_username}@garbage.org" expect(logged_on_user.email).to eq("#{@reversed_username}@garbage.org")
logged_on_user.name.should == @suggested_name expect(logged_on_user.name).to eq(@suggested_name)
end end
it 'does not change matching attributes for an existing account' do 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) get :sso_login, Rack::Utils.parse_query(@sso.payload)
logged_on_user = Discourse.current_user_provider.new(request.env).current_user logged_on_user = Discourse.current_user_provider.new(request.env).current_user
logged_on_user.username.should == @user.username expect(logged_on_user.username).to eq(@user.username)
logged_on_user.name.should == @user.name expect(logged_on_user.name).to eq(@user.name)
logged_on_user.email.should == @user.email expect(logged_on_user.email).to eq(@user.email)
end end
it 'does not change attributes for unchanged external attributes' do 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) get :sso_login, Rack::Utils.parse_query(@sso.payload)
logged_on_user = Discourse.current_user_provider.new(request.env).current_user logged_on_user = Discourse.current_user_provider.new(request.env).current_user
logged_on_user.username.should == @user.username expect(logged_on_user.username).to eq(@user.username)
logged_on_user.email.should == @user.email expect(logged_on_user.email).to eq(@user.email)
logged_on_user.name.should == @user.name expect(logged_on_user.name).to eq(@user.name)
end end
end end
end end
@ -249,13 +249,13 @@ describe SessionController do
end end
it "raises an error when the login isn't present" do 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 end
describe 'invalid password' do describe 'invalid password' do
it "should return an error with an invalid password" do it "should return an error with an invalid password" do
xhr :post, :create, login: user.username, password: 'sssss' 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
end end
@ -263,7 +263,7 @@ describe SessionController do
it "should return an error with an invalid password if too long" do it "should return an error with an invalid password if too long" do
User.any_instance.expects(:confirm_password?).never User.any_instance.expects(:confirm_password?).never
xhr :post, :create, login: user.username, password: ('s' * (User.max_password_length + 1)) 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
end end
@ -272,7 +272,7 @@ describe SessionController do
User.any_instance.stubs(:suspended?).returns(true) User.any_instance.stubs(:suspended?).returns(true)
User.any_instance.stubs(:suspended_till).returns(2.days.from_now) User.any_instance.stubs(:suspended_till).returns(2.days.from_now)
xhr :post, :create, login: user.username, password: 'myawesomepassword' 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
end end
@ -290,9 +290,9 @@ describe SessionController do
user.reload user.reload
session[:current_user_id].should == user.id expect(session[:current_user_id]).to eq(user.id)
user.auth_token.should be_present expect(user.auth_token).to be_present
cookies[:_t].should == user.auth_token expect(cookies[:_t]).to eq(user.auth_token)
end end
end end
@ -300,7 +300,7 @@ describe SessionController do
it 'fails' do it 'fails' do
SiteSetting.stubs(:enable_local_logins).returns(false) SiteSetting.stubs(:enable_local_logins).returns(false)
xhr :post, :create, login: user.username, password: 'myawesomepassword' xhr :post, :create, login: user.username, password: 'myawesomepassword'
response.status.to_i.should == 500 expect(response.status.to_i).to eq(500)
end end
end end
@ -311,7 +311,7 @@ describe SessionController do
end end
it 'sets a session id' do 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 end
@ -321,7 +321,7 @@ describe SessionController do
end end
it 'sets a session id' do 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 end
@ -331,12 +331,12 @@ describe SessionController do
it "strips spaces from the username" do it "strips spaces from the username" do
xhr :post, :create, login: username, password: 'myawesomepassword' 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 end
it "strips spaces from the email" do it "strips spaces from the email" do
xhr :post, :create, login: email, password: 'myawesomepassword' 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
end end
@ -351,7 +351,7 @@ describe SessionController do
end end
it "doesn't log in the user" do it "doesn't log in the user" do
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it "shows the 'not approved' error message" do it "shows the 'not approved' error message" do
@ -368,7 +368,7 @@ describe SessionController do
end end
it 'sets a session id' do 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 end
end end
@ -384,22 +384,22 @@ describe SessionController do
User.any_instance.stubs(:admin?).returns(true) User.any_instance.stubs(:admin?).returns(true)
ActionDispatch::Request.any_instance.stubs(:remote_ip).returns(permitted_ip_address) ActionDispatch::Request.any_instance.stubs(:remote_ip).returns(permitted_ip_address)
xhr :post, :create, login: user.username, password: 'myawesomepassword' 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
it 'returns an error for admin not at the ip address' do it 'returns an error for admin not at the ip address' do
User.any_instance.stubs(:admin?).returns(true) User.any_instance.stubs(:admin?).returns(true)
ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12") ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12")
xhr :post, :create, login: user.username, password: 'myawesomepassword' 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
session[:current_user_id].should_not == user.id expect(session[:current_user_id]).not_to eq(user.id)
end end
it 'is successful for non-admin not at the ip address' do it 'is successful for non-admin not at the ip address' do
User.any_instance.stubs(:admin?).returns(false) User.any_instance.stubs(:admin?).returns(false)
ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12") ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("111.234.23.12")
xhr :post, :create, login: user.username, password: 'myawesomepassword' 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 end
end end
@ -411,7 +411,7 @@ describe SessionController do
it "doesn't log in the user" do it "doesn't log in the user" do
post_login post_login
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it "shows the 'not activated' error message" do it "shows the 'not activated' error message" do
@ -441,24 +441,24 @@ describe SessionController do
end end
it 'removes the session variable' do it 'removes the session variable' do
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it 'removes the auth token cookie' do it 'removes the auth token cookie' do
cookies[:_t].should be_blank expect(cookies[:_t]).to be_blank
end end
end end
describe '.forgot_password' do describe '.forgot_password' do
it 'raises an error without a username parameter' 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 end
context 'for a non existant username' do context 'for a non existant username' do
it "doesn't generate a new token for a made up 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 end
it "doesn't enqueue an email" do it "doesn't enqueue an email" do
@ -473,11 +473,11 @@ describe SessionController do
it "returns a 500 if local logins are disabled" do it "returns a 500 if local logins are disabled" do
SiteSetting.enable_local_logins = false SiteSetting.enable_local_logins = false
xhr :post, :forgot_password, login: user.username xhr :post, :forgot_password, login: user.username
response.code.to_i.should == 500 expect(response.code.to_i).to eq(500)
end end
it "generates a new token for a made up username" do 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 end
it "enqueues an email" do it "enqueues an email" do
@ -490,7 +490,7 @@ describe SessionController do
let(:user) { Discourse.system_user } let(:user) { Discourse.system_user }
it 'generates no token for system username' do 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 end
it 'enqueues no email' do it 'enqueues no email' do
@ -504,7 +504,7 @@ describe SessionController do
context "when not logged in" do context "when not logged in" do
it "retuns 404" do it "retuns 404" do
xhr :get, :current xhr :get, :current
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -513,10 +513,10 @@ describe SessionController do
it "returns the JSON for the user" do it "returns the JSON for the user" do
xhr :get, :current xhr :get, :current
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['current_user'].should be_present expect(json['current_user']).to be_present
json['current_user']['id'].should == user.id expect(json['current_user']['id']).to eq(user.id)
end end
end end
end end

View File

@ -22,10 +22,10 @@ describe SiteCustomizationsController do
) )
get :show, key: SiteCustomization::ENABLED_KEY, format: :css, target: 'mobile' 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 get :show, key: SiteCustomization::ENABLED_KEY, format: :css
response.body.should =~ /\.b1.*\.b2/m expect(response.body).to match(/\.b1.*\.b2/m)
end end
it 'can deliver specific css' do it 'can deliver specific css' do
@ -37,9 +37,9 @@ describe SiteCustomizationsController do
) )
get :show, key: c.key, format: :css, target: 'mobile' 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 get :show, key: c.key, format: :css
response.body.should =~ /\.b1/ expect(response.body).to match(/\.b1/)
end end
end end

View File

@ -17,12 +17,12 @@ describe StaticController do
end end
it 'renders the static file if present' do it 'renders the static file if present' do
response.should be_success expect(response).to be_success
end end
it "renders the file" do it "renders the file" do
response.should render_template('static/show') expect(response).to render_template('static/show')
assigns(:page).should == 'faq' expect(assigns(:page)).to eq('faq')
end end
end end
@ -33,7 +33,7 @@ describe StaticController do
context "when #{setting_name} site setting is NOT set" do context "when #{setting_name} site setting is NOT set" do
it "renders the #{id} page" do it "renders the #{id} page" do
expect(subject).to render_template("static/show") expect(subject).to render_template("static/show")
assigns(:page).should == id expect(assigns(:page)).to eq(id)
end end
end end
@ -50,20 +50,20 @@ describe StaticController do
context "with a missing file" do context "with a missing file" do
it "should respond 404" do it "should respond 404" do
xhr :get, :show, id: 'does-not-exist' xhr :get, :show, id: 'does-not-exist'
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
end end
it 'should redirect to / when logged in and path is /login' do it 'should redirect to / when logged in and path is /login' do
log_in log_in
xhr :get, :show, id: 'login' xhr :get, :show, id: 'login'
response.should redirect_to '/' expect(response).to redirect_to '/'
end end
it "should display the login template when login is required" do it "should display the login template when login is required" do
SiteSetting.stubs(:login_required).returns(true) SiteSetting.stubs(:login_required).returns(true)
xhr :get, :show, id: 'login' xhr :get, :show, id: 'login'
response.should be_success expect(response).to be_success
end end
end end

View File

@ -10,37 +10,37 @@ describe TopicsController do
it "returns the JSON in the format our wordpress plugin needs" do it "returns the JSON in the format our wordpress plugin needs" do
xhr :get, :wordpress, topic_id: topic.id, best: 3 xhr :get, :wordpress, topic_id: topic.id, best: 3
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json.should be_present expect(json).to be_present
# The JSON has the data the wordpress plugin needs # The JSON has the data the wordpress plugin needs
json['id'].should == topic.id expect(json['id']).to eq(topic.id)
json['posts_count'].should == 2 expect(json['posts_count']).to eq(2)
json['filtered_posts_count'].should == 2 expect(json['filtered_posts_count']).to eq(2)
# Posts # Posts
json['posts'].size.should == 1 expect(json['posts'].size).to eq(1)
post = json['posts'][0] post = json['posts'][0]
post['id'].should == p2.id expect(post['id']).to eq(p2.id)
post['username'].should == user.username expect(post['username']).to eq(user.username)
post['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}" expect(post['avatar_template']).to eq("#{Discourse.base_url_no_prefix}#{user.avatar_template}")
post['name'].should == user.name expect(post['name']).to eq(user.name)
post['created_at'].should be_present expect(post['created_at']).to be_present
post['cooked'].should == p2.cooked expect(post['cooked']).to eq(p2.cooked)
# Participants # Participants
json['participants'].size.should == 1 expect(json['participants'].size).to eq(1)
participant = json['participants'][0] participant = json['participants'][0]
participant['id'].should == user.id expect(participant['id']).to eq(user.id)
participant['username'].should == user.username expect(participant['username']).to eq(user.username)
participant['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}" expect(participant['avatar_template']).to eq("#{Discourse.base_url_no_prefix}#{user.avatar_template}")
end end
end end
context 'move_posts' do context 'move_posts' do
it 'needs you to be logged in' 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 end
describe 'moving to a new topic' do describe 'moving to a new topic' do
@ -49,13 +49,13 @@ describe TopicsController do
let(:topic) { p1.topic } let(:topic) { p1.topic }
it "raises an error without postIds" do 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 end
it "raises an error when the user doesn't have permission to move the posts" do 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) Guardian.any_instance.expects(:can_move_posts?).returns(false)
xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [1,2,3] 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 end
context 'success' do context 'success' do
@ -67,10 +67,10 @@ describe TopicsController do
end end
it "returns success" do it "returns success" do
response.should be_success expect(response).to be_success
result = ::JSON.parse(response.body) result = ::JSON.parse(response.body)
result['success'].should == true expect(result['success']).to eq(true)
result['url'].should be_present expect(result['url']).to be_present
end end
end end
@ -83,10 +83,10 @@ describe TopicsController do
end end
it "returns JSON with a false success" do it "returns JSON with a false success" do
response.should be_success expect(response).to be_success
result = ::JSON.parse(response.body) result = ::JSON.parse(response.body)
result['success'].should == false expect(result['success']).to eq(false)
result['url'].should be_blank expect(result['url']).to be_blank
end end
end end
end end
@ -127,10 +127,10 @@ describe TopicsController do
end end
it "returns success" do it "returns success" do
response.should be_success expect(response).to be_success
result = ::JSON.parse(response.body) result = ::JSON.parse(response.body)
result['success'].should == true expect(result['success']).to eq(true)
result['url'].should be_present expect(result['url']).to be_present
end end
end end
@ -143,10 +143,10 @@ describe TopicsController do
end end
it "returns JSON with a false success" do it "returns JSON with a false success" do
response.should be_success expect(response).to be_success
result = ::JSON.parse(response.body) result = ::JSON.parse(response.body)
result['success'].should == false expect(result['success']).to eq(false)
result['url'].should be_blank expect(result['url']).to be_blank
end end
end end
end end
@ -154,7 +154,7 @@ describe TopicsController do
context "merge_topic" do context "merge_topic" do
it 'needs you to be logged in' 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 end
describe 'moving to a new topic' do describe 'moving to a new topic' do
@ -163,13 +163,13 @@ describe TopicsController do
let(:topic) { p1.topic } let(:topic) { p1.topic }
it "raises an error without destination_topic_id" do 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 end
it "raises an error when the user doesn't have permission to merge" do it "raises an error when the user doesn't have permission to merge" do
Guardian.any_instance.expects(:can_move_posts?).returns(false) Guardian.any_instance.expects(:can_move_posts?).returns(false)
xhr :post, :merge_topic, topic_id: 111, destination_topic_id: 345 xhr :post, :merge_topic, topic_id: 111, destination_topic_id: 345
response.should be_forbidden expect(response).to be_forbidden
end end
let(:dest_topic) { Fabricate(:topic) } let(:dest_topic) { Fabricate(:topic) }
@ -183,10 +183,10 @@ describe TopicsController do
end end
it "returns success" do it "returns success" do
response.should be_success expect(response).to be_success
result = ::JSON.parse(response.body) result = ::JSON.parse(response.body)
result['success'].should == true expect(result['success']).to eq(true)
result['url'].should be_present expect(result['url']).to be_present
end end
end end
@ -197,14 +197,14 @@ describe TopicsController do
context 'change_post_owners' do context 'change_post_owners' do
it 'needs you to be logged in' 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 end
describe 'forbidden to moderators' do describe 'forbidden to moderators' do
let!(:moderator) { log_in(:moderator) } let!(:moderator) { log_in(:moderator) }
it 'correctly denies' do it 'correctly denies' do
xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] 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
end end
@ -213,7 +213,7 @@ describe TopicsController do
it 'correctly denies' do it 'correctly denies' do
xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] 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
end end
@ -224,21 +224,21 @@ describe TopicsController do
let(:p1) { Fabricate(:post, topic_id: topic.id) } let(:p1) { Fabricate(:post, topic_id: topic.id) }
it "raises an error with a parameter missing" do 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) expect { xhr :post, :change_post_owners, topic_id: 111, post_ids: [1,2,3] }.to 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, username: 'user_a' }.to raise_error(ActionController::ParameterMissing)
end end
it "calls PostRevisor" do it "calls PostRevisor" do
PostRevisor.any_instance.expects(:revise!) PostRevisor.any_instance.expects(:revise!)
xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] 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 end
it "changes the user" do it "changes the user" do
old_user = p1.user old_user = p1.user
xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id]
p1.reload p1.reload
old_user.should_not == p1.user expect(old_user).not_to eq(p1.user)
end end
# Make sure that p1.reload isn't changing the user for us # Make sure that p1.reload isn't changing the user for us
@ -246,8 +246,8 @@ describe TopicsController do
old_user = p1.user old_user = p1.user
# xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id] # xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id]
p1.reload p1.reload
p1.user.should_not == nil expect(p1.user).not_to eq(nil)
old_user.should == p1.user expect(old_user).to eq(p1.user)
end end
let(:p2) { Fabricate(:post, topic_id: topic.id) } 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] xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id, p2.id]
p1.reload p1.reload
p2.reload p2.reload
p1.user.should_not == nil expect(p1.user).not_to eq(nil)
p1.user.should == p2.user expect(p1.user).to eq(p2.user)
end end
end end
end end
@ -268,21 +268,21 @@ describe TopicsController do
let(:raw) { 'this body is long enough to search for' } let(:raw) { 'this body is long enough to search for' }
it "requires a title" do 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 end
it "requires a raw body" do 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 end
it "raises an error if the title length is below the minimum" do it "raises an error if the title length is below the minimum" do
SiteSetting.stubs(:min_title_similar_length).returns(100) 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 end
it "raises an error if the body length is below the minimum" do it "raises an error if the body length is below the minimum" do
SiteSetting.stubs(:min_body_similar_length).returns(100) 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 end
describe "minimum_topics_similar" do describe "minimum_topics_similar" do
@ -326,7 +326,7 @@ describe TopicsController do
context 'clear_pin' do context 'clear_pin' do
it 'needs you to be logged in' 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 end
context 'when logged in' do context 'when logged in' do
@ -336,7 +336,7 @@ describe TopicsController do
it "fails when the user can't see the topic" do it "fails when the user can't see the topic" do
Guardian.any_instance.expects(:can_see?).with(topic).returns(false) Guardian.any_instance.expects(:can_see?).with(topic).returns(false)
xhr :put, :clear_pin, topic_id: topic.id xhr :put, :clear_pin, topic_id: topic.id
response.should_not be_success expect(response).not_to be_success
end end
describe 'when the user can see the topic' do describe 'when the user can see the topic' do
@ -347,7 +347,7 @@ describe TopicsController do
it "succeeds" do it "succeeds" do
xhr :put, :clear_pin, topic_id: topic.id xhr :put, :clear_pin, topic_id: topic.id
response.should be_success expect(response).to be_success
end end
end end
@ -357,7 +357,7 @@ describe TopicsController do
context 'status' do context 'status' do
it 'needs you to be logged in' 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 end
describe 'when logged in' do describe 'when logged in' do
@ -369,19 +369,19 @@ describe TopicsController do
it "raises an exception if you can't change it" do it "raises an exception if you can't change it" do
Guardian.any_instance.expects(:can_moderate?).with(@topic).returns(false) Guardian.any_instance.expects(:can_moderate?).with(@topic).returns(false)
xhr :put, :status, topic_id: @topic.id, status: 'visible', enabled: 'true' xhr :put, :status, topic_id: @topic.id, status: 'visible', enabled: 'true'
response.should be_forbidden expect(response).to be_forbidden
end end
it 'requires the status parameter' do 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 end
it 'requires the enabled parameter' do 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 end
it 'raises an error with a status not in the whitelist' do 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 end
it 'calls update_status on the forum topic with false' do it 'calls update_status on the forum topic with false' do
@ -401,7 +401,7 @@ describe TopicsController do
context 'delete_timings' do context 'delete_timings' do
it 'needs you to be logged in' 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 end
context 'when logged in' do context 'when logged in' do
@ -424,11 +424,11 @@ describe TopicsController do
describe 'mute/unmute' do describe 'mute/unmute' do
it 'needs you to be logged in' 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 end
it 'needs you to be logged in' do 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 end
describe 'when logged in' do describe 'when logged in' do
@ -442,7 +442,7 @@ describe TopicsController do
describe 'recover' do describe 'recover' do
it "won't allow us to recover a topic when we're not logged in" 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 end
describe 'when logged in' do 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 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) Guardian.any_instance.expects(:can_recover_topic?).with(topic).returns(false)
xhr :put, :recover, topic_id: topic.id xhr :put, :recover, topic_id: topic.id
response.should be_forbidden expect(response).to be_forbidden
end end
end end
@ -464,7 +464,7 @@ describe TopicsController do
it 'succeeds' do it 'succeeds' do
PostDestroyer.any_instance.expects(:recover) PostDestroyer.any_instance.expects(:recover)
xhr :put, :recover, topic_id: topic.id xhr :put, :recover, topic_id: topic.id
response.should be_success expect(response).to be_success
end end
end end
end end
@ -473,7 +473,7 @@ describe TopicsController do
describe 'delete' do describe 'delete' do
it "won't allow us to delete a topic when we're not logged in" 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 end
describe 'when logged in' do 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 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) Guardian.any_instance.expects(:can_delete?).with(topic).returns(false)
xhr :delete, :destroy, id: topic.id xhr :delete, :destroy, id: topic.id
response.should be_forbidden expect(response).to be_forbidden
end end
end end
@ -495,7 +495,7 @@ describe TopicsController do
it 'succeeds' do it 'succeeds' do
PostDestroyer.any_instance.expects(:destroy) PostDestroyer.any_instance.expects(:destroy)
xhr :delete, :destroy, id: topic.id xhr :delete, :destroy, id: topic.id
response.should be_success expect(response).to be_success
end end
end end
@ -508,18 +508,18 @@ describe TopicsController do
it "returns JSON for the slug" do it "returns JSON for the slug" do
xhr :get, :id_for_slug, slug: topic.slug xhr :get, :id_for_slug, slug: topic.slug
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json.should be_present expect(json).to be_present
json['topic_id'].should == topic.id expect(json['topic_id']).to eq(topic.id)
json['url'].should == topic.url expect(json['url']).to eq(topic.url)
json['slug'].should == topic.slug expect(json['slug']).to eq(topic.slug)
end end
it "returns invalid access if the user can't see the topic" do it "returns invalid access if the user can't see the topic" do
Guardian.any_instance.expects(:can_see?).with(topic).returns(false) Guardian.any_instance.expects(:can_see?).with(topic).returns(false)
xhr :get, :id_for_slug, slug: topic.slug xhr :get, :id_for_slug, slug: topic.slug
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -531,12 +531,12 @@ describe TopicsController do
it 'shows a topic correctly' do it 'shows a topic correctly' do
xhr :get, :show, topic_id: topic.id, slug: topic.slug xhr :get, :show, topic_id: topic.id, slug: topic.slug
response.should be_success expect(response).to be_success
end end
it 'return 404 for an invalid page' do it 'return 404 for an invalid page' do
xhr :get, :show, topic_id: topic.id, slug: topic.slug, page: 2 xhr :get, :show, topic_id: topic.id, slug: topic.slug, page: 2
response.code.should == "404" expect(response.code).to eq("404")
end end
it 'can find a topic given a slug in the id param' do it 'can find a topic given a slug in the id param' do
@ -572,14 +572,14 @@ describe TopicsController do
end end
it 'records a view' do 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 end
it 'records incoming links' do it 'records incoming links' do
user = Fabricate(:user) user = Fabricate(:user)
get :show, topic_id: topic.id, slug: topic.slug, u: user.username get :show, topic_id: topic.id, slug: topic.slug, u: user.username
IncomingLink.count.should == 1 expect(IncomingLink.count).to eq(1)
end end
it 'records redirects' do it 'records redirects' do
@ -590,7 +590,7 @@ describe TopicsController do
get :show, topic_id: topic.id, slug: topic.slug get :show, topic_id: topic.id, slug: topic.slug
link = IncomingLink.first link = IncomingLink.first
link.referer.should == 'http://twitter.com' expect(link.referer).to eq('http://twitter.com')
end end
it 'tracks a visit for all html requests' do it 'tracks a visit for all html requests' do
@ -602,7 +602,7 @@ describe TopicsController do
context 'consider for a promotion' do context 'consider for a promotion' do
let!(:user) { log_in(:coding_horror) } let!(:user) { log_in(:coding_horror) }
let(:promotion) do let(:promotion) do
result = mock result = double
Promotion.stubs(:new).with(user).returns(result) Promotion.stubs(:new).with(user).returns(result)
result result
end end
@ -662,7 +662,7 @@ describe TopicsController do
expect(response).to be_successful expect(response).to be_successful
topic.reload topic.reload
# free test, only costs a reload # free test, only costs a reload
topic.views.should == 1 expect(topic.views).to eq(1)
end end
it 'returns 403 for an invalid key' do it 'returns 403 for an invalid key' do
@ -678,14 +678,14 @@ describe TopicsController do
it 'renders rss of the topic' do it 'renders rss of the topic' do
get :feed, topic_id: topic.id, slug: 'foo', format: :rss get :feed, topic_id: topic.id, slug: 'foo', format: :rss
response.should be_success expect(response).to be_success
response.content_type.should == 'application/rss+xml' expect(response.content_type).to eq('application/rss+xml')
end end
end end
describe 'update' do describe 'update' do
it "won't allow us to update a topic when we're not logged in" 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 end
describe 'when logged in' do 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 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) Guardian.any_instance.expects(:can_edit?).with(@topic).returns(false)
xhr :put, :update, topic_id: @topic.id, slug: @topic.title xhr :put, :update, topic_id: @topic.id, slug: @topic.title
response.should be_forbidden expect(response).to be_forbidden
end end
end end
@ -709,14 +709,14 @@ describe TopicsController do
it 'succeeds' do it 'succeeds' do
xhr :put, :update, topic_id: @topic.id, slug: @topic.title xhr :put, :update, topic_id: @topic.id, slug: @topic.title
response.should be_success expect(response).to be_success
::JSON.parse(response.body)['basic_topic'].should be_present expect(::JSON.parse(response.body)['basic_topic']).to be_present
end end
it 'allows a change of title' do 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' xhr :put, :update, topic_id: @topic.id, slug: @topic.title, title: 'This is a new title for the topic'
@topic.reload @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 end
it 'triggers a change of category' do it 'triggers a change of category' do
@ -732,7 +732,7 @@ describe TopicsController do
it "returns errors when the rate limit is exceeded" do it "returns errors when the rate limit is exceeded" do
EditRateLimiter.any_instance.expects(:performed!).raises(RateLimiter::LimitExceeded.new(60)) 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' 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 end
it "returns errors with invalid categories" do it "returns errors with invalid categories" do
@ -755,7 +755,7 @@ describe TopicsController do
it "can add a category to an uncategorized topic" do it "can add a category to an uncategorized topic" do
Topic.any_instance.expects(:change_category_to_id).with(456).returns(true) 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 xhr :put, :update, topic_id: @topic.id, slug: @topic.title, category_id: 456
response.should be_success expect(response).to be_success
end end
end end
@ -773,17 +773,17 @@ describe TopicsController do
xhr :post, :invite, topic_id: topic.id, email: 'hiro@from.heros', group_ids: "#{group.id}" 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') invite = Invite.find_by(email: 'hiro@from.heros')
groups = invite.groups.to_a groups = invite.groups.to_a
groups.count.should == 1 expect(groups.count).to eq(1)
groups[0].id.should == group.id expect(groups[0].id).to eq(group.id)
end end
end end
it "won't allow us to invite toa topic when we're not logged in" do 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 end
describe 'when logged in' do describe 'when logged in' do
@ -792,13 +792,13 @@ describe TopicsController do
end end
it 'requires an email parameter' do 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 end
describe 'without permission' do describe 'without permission' do
it "raises an exception when the user doesn't have permission to invite to the topic" 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' xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo'
response.should be_forbidden expect(response).to be_forbidden
end end
end end
@ -810,15 +810,15 @@ describe TopicsController do
it 'should work as expected' do it 'should work as expected' do
xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo' xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo'
response.should be_success expect(response).to be_success
::JSON.parse(response.body).should == {'success' => 'OK'} expect(::JSON.parse(response.body)).to eq({'success' => 'OK'})
Invite.where(invited_by_id: admin.id).count.should == 1 expect(Invite.where(invited_by_id: admin.id).count).to eq(1)
end end
it 'should fail on shoddy email' do it 'should fail on shoddy email' do
xhr :post, :invite, topic_id: @topic.id, user: 'i_am_not_an_email' xhr :post, :invite, topic_id: @topic.id, user: 'i_am_not_an_email'
response.should_not be_success expect(response).not_to be_success
::JSON.parse(response.body).should == {'failed' => 'FAILED'} expect(::JSON.parse(response.body)).to eq({'failed' => 'FAILED'})
end end
end end
@ -830,15 +830,15 @@ describe TopicsController do
describe 'autoclose' do describe 'autoclose' do
it 'needs you to be logged in' 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 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 end
it 'needs you to be an admin or mod' do it 'needs you to be an admin or mod' do
user = log_in user = log_in
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false 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 end
describe 'when logged in' do describe 'when logged in' do
@ -851,8 +851,8 @@ describe TopicsController do
Topic.any_instance.expects(:set_auto_close).with("24", @admin) 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 xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: '24', auto_close_based_on_last_post: true
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json.should have_key('auto_close_at') expect(json).to have_key('auto_close_at')
json.should have_key('auto_close_hours') expect(json).to have_key('auto_close_hours')
end end
it "can remove a topic's auto close time" do 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 it 'needs you to be a staff member' do
log_in log_in
xhr :put, :make_banner, topic_id: 99 xhr :put, :make_banner, topic_id: 99
response.should be_forbidden expect(response).to be_forbidden
end end
describe 'when logged in' do describe 'when logged in' do
@ -878,7 +878,7 @@ describe TopicsController do
Topic.any_instance.expects(:make_banner!) Topic.any_instance.expects(:make_banner!)
xhr :put, :make_banner, topic_id: topic.id xhr :put, :make_banner, topic_id: topic.id
response.should be_success expect(response).to be_success
end end
end end
@ -890,7 +890,7 @@ describe TopicsController do
it 'needs you to be a staff member' do it 'needs you to be a staff member' do
log_in log_in
xhr :put, :remove_banner, topic_id: 99 xhr :put, :remove_banner, topic_id: 99
response.should be_forbidden expect(response).to be_forbidden
end end
describe 'when logged in' do describe 'when logged in' do
@ -900,7 +900,7 @@ describe TopicsController do
Topic.any_instance.expects(:remove_banner!) Topic.any_instance.expects(:remove_banner!)
xhr :put, :remove_banner, topic_id: topic.id xhr :put, :remove_banner, topic_id: topic.id
response.should be_success expect(response).to be_success
end end
end end
@ -909,7 +909,7 @@ describe TopicsController do
describe "bulk" do describe "bulk" do
it 'needs you to be logged in' 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 end
describe "when logged in" do describe "when logged in" do
@ -918,15 +918,15 @@ describe TopicsController do
let(:topic_ids) { [1,2,3] } let(:topic_ids) { [1,2,3] }
it "requires a list of topic_ids or filter" do 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 end
it "requires an operation param" do 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 end
it "requires a type field for the operation param" do 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 end
it "delegates work to `TopicsBulkAction`" do it "delegates work to `TopicsBulkAction`" do
@ -941,7 +941,7 @@ describe TopicsController do
describe 'reset_new' do describe 'reset_new' do
it 'needs you to be logged in' 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 end
let(:user) { log_in(:user) } let(:user) { log_in(:user) }
@ -953,7 +953,7 @@ describe TopicsController do
xhr :put, :reset_new xhr :put, :reset_new
user.reload 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 end

View File

@ -5,7 +5,7 @@ describe UploadsController do
context '.create' do context '.create' do
it 'requires you to be logged in' 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 end
context 'logged in' do context 'logged in' do
@ -43,12 +43,12 @@ describe UploadsController do
it 'is successful with an image' do it 'is successful with an image' do
xhr :post, :create, file: logo xhr :post, :create, file: logo
response.status.should eq 200 expect(response.status).to eq 200
end end
it 'is successful with an attachment' do it 'is successful with an attachment' do
xhr :post, :create, file: text_file xhr :post, :create, file: text_file
response.status.should eq 200 expect(response.status).to eq 200
end end
it 'correctly sets retain_hours for admins' do it 'correctly sets retain_hours for admins' do
@ -56,7 +56,7 @@ describe UploadsController do
xhr :post, :create, file: logo, retain_hours: 100 xhr :post, :create, file: logo, retain_hours: 100
url = JSON.parse(response.body)["url"] url = JSON.parse(response.body)["url"]
id = url.split("/")[3].to_i id = url.split("/")[3].to_i
Upload.find(id).retain_hours.should == 100 expect(Upload.find(id).retain_hours).to eq(100)
end end
context 'with a big file' do context 'with a big file' do
@ -65,7 +65,7 @@ describe UploadsController do
it 'rejects the upload' do it 'rejects the upload' do
xhr :post, :create, file: text_file xhr :post, :create, file: text_file
response.status.should eq 422 expect(response.status).to eq 422
end end
end end
@ -78,7 +78,7 @@ describe UploadsController do
it 'rejects the upload' do it 'rejects the upload' do
xhr :post, :create, file: text_file xhr :post, :create, file: text_file
response.status.should eq 422 expect(response.status).to eq 422
end end
end end
@ -89,12 +89,12 @@ describe UploadsController do
it 'is successful with an image' do it 'is successful with an image' do
xhr :post, :create, file: logo xhr :post, :create, file: logo
response.status.should eq 200 expect(response.status).to eq 200
end end
it 'is successful with an attachment' do it 'is successful with an attachment' do
xhr :post, :create, file: text_file xhr :post, :create, file: text_file
response.status.should eq 200 expect(response.status).to eq 200
end end
end end
@ -105,12 +105,12 @@ describe UploadsController do
it 'is successful' do it 'is successful' do
xhr :post, :create, files: files xhr :post, :create, files: files
response.should be_success expect(response).to be_success
end end
it 'takes the first file' do it 'takes the first file' do
xhr :post, :create, files: files xhr :post, :create, files: files
response.body.should match /logo-dev.png/ expect(response.body).to match /logo-dev.png/
end end
end end
@ -126,7 +126,7 @@ describe UploadsController do
Discourse.stubs(:store).returns(store) Discourse.stubs(:store).returns(store)
Upload.expects(:find_by).never Upload.expects(:find_by).never
get :show, site: "default", id: 1, sha: "1234567890abcdef", extension: "pdf" get :show, site: "default", id: 1, sha: "1234567890abcdef", extension: "pdf"
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
it "returns 404 when the upload doens't exist" do 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) Upload.expects(:find_by).with(sha1: "1234567890abcdef").returns(nil)
get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf" get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf"
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
it 'uses send_file' do 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 it "returns 404 when an anonymous user tries to download a file" do
Upload.expects(:find_by).never Upload.expects(:find_by).never
get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf" get :show, site: "default", id: 2, sha: "1234567890abcdef", extension: "pdf"
response.response_code.should == 404 expect(response.response_code).to eq(404)
end end
end end

View File

@ -13,14 +13,14 @@ describe UserActionsController do
xhr :get, :index, username: post.user.username xhr :get, :index, username: post.user.username
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
actions = parsed["user_actions"] actions = parsed["user_actions"]
actions.length.should == 1 expect(actions.length).to eq(1)
action = actions[0] action = actions[0]
action["acting_name"].should == post.user.name expect(action["acting_name"]).to eq(post.user.name)
action["email"].should == nil expect(action["email"]).to eq(nil)
action["post_number"].should == 1 expect(action["post_number"]).to eq(1)
end end
end end
end end

View File

@ -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) 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 xhr :get, :index, badge_id: badge.id
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["topics"].should == nil expect(parsed["topics"]).to eq(nil)
parsed["user_badges"][0]["post_id"].should == nil expect(parsed["user_badges"][0]["post_id"]).to eq(nil)
end end
end end
@ -28,25 +28,25 @@ describe UserBadgesController do
it 'returns user_badges for a user' do it 'returns user_badges for a user' do
xhr :get, :username, username: user.username xhr :get, :username, username: user.username
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["user_badges"].length.should == 1 expect(parsed["user_badges"].length).to eq(1)
end end
it 'returns user_badges for a badge' do it 'returns user_badges for a badge' do
xhr :get, :index, badge_id: badge.id xhr :get, :index, badge_id: badge.id
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) parsed = JSON.parse(response.body)
parsed["user_badges"].length.should == 1 expect(parsed["user_badges"].length).to eq(1)
end end
it 'includes counts when passed the aggregate argument' do it 'includes counts when passed the aggregate argument' do
xhr :get, :username, username: user.username, grouped: true xhr :get, :username, username: user.username, grouped: true
response.status.should == 200 expect(response.status).to eq(200)
parsed = JSON.parse(response.body) 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
end end
@ -58,7 +58,7 @@ describe UserBadgesController do
it 'does not allow regular users to grant badges' do it 'does not allow regular users to grant badges' do
log_in_user Fabricate(:user) log_in_user Fabricate(:user)
xhr :post, :create, badge_id: badge.id, username: user.username xhr :post, :create, badge_id: badge.id, username: user.username
response.status.should == 403 expect(response.status).to eq(403)
end end
it 'grants badges from staff' do it 'grants badges from staff' do
@ -66,26 +66,26 @@ describe UserBadgesController do
log_in_user admin log_in_user admin
StaffActionLogger.any_instance.expects(:log_badge_grant).once StaffActionLogger.any_instance.expects(:log_badge_grant).once
xhr :post, :create, badge_id: badge.id, username: user.username 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 = UserBadge.find_by(user: user, badge: badge)
user_badge.should be_present expect(user_badge).to be_present
user_badge.granted_by.should eq(admin) expect(user_badge.granted_by).to eq(admin)
end end
it 'does not grant badges from regular api calls' do it 'does not grant badges from regular api calls' do
Fabricate(:api_key, user: user) Fabricate(:api_key, user: user)
xhr :post, :create, badge_id: badge.id, username: user.username, api_key: user.api_key.key 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 end
it 'grants badges from master api calls' do it 'grants badges from master api calls' do
api_key = Fabricate(:api_key) api_key = Fabricate(:api_key)
StaffActionLogger.any_instance.expects(:log_badge_grant).never 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" 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 = UserBadge.find_by(user: user, badge: badge)
user_badge.should be_present expect(user_badge).to be_present
user_badge.granted_by.should eq(Discourse.system_user) expect(user_badge.granted_by).to eq(Discourse.system_user)
end end
end end
@ -94,15 +94,15 @@ describe UserBadgesController do
it 'checks that the user is authorized to revoke a badge' do it 'checks that the user is authorized to revoke a badge' do
xhr :delete, :destroy, id: user_badge.id xhr :delete, :destroy, id: user_badge.id
response.status.should == 403 expect(response.status).to eq(403)
end end
it 'revokes the badge' do it 'revokes the badge' do
log_in :admin log_in :admin
StaffActionLogger.any_instance.expects(:log_badge_revoke).once StaffActionLogger.any_instance.expects(:log_badge_revoke).once
xhr :delete, :destroy, id: user_badge.id xhr :delete, :destroy, id: user_badge.id
response.status.should == 200 expect(response.status).to eq(200)
UserBadge.find_by(id: user_badge.id).should == nil expect(UserBadge.find_by(id: user_badge.id)).to eq(nil)
end end
end end
end end

View File

@ -7,28 +7,28 @@ describe UsersController do
it 'returns success' do it 'returns success' do
xhr :get, :show, username: user.username, format: :json xhr :get, :show, username: user.username, format: :json
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) json = JSON.parse(response.body)
json["user"]["has_title_badges"].should == false expect(json["user"]["has_title_badges"]).to eq(false)
end end
it "returns not found when the username doesn't exist" do it "returns not found when the username doesn't exist" do
xhr :get, :show, username: 'madeuppity' xhr :get, :show, username: 'madeuppity'
response.should_not be_success expect(response).not_to be_success
end end
it 'returns not found when the user is inactive' do it 'returns not found when the user is inactive' do
inactive = Fabricate(:user, active: false) inactive = Fabricate(:user, active: false)
xhr :get, :show, username: inactive.username xhr :get, :show, username: inactive.username
response.should_not be_success expect(response).not_to be_success
end end
it "raises an error on invalid access" do it "raises an error on invalid access" do
Guardian.any_instance.expects(:can_see?).with(user).returns(false) Guardian.any_instance.expects(:can_see?).with(user).returns(false)
xhr :get, :show, username: user.username xhr :get, :show, username: user.username
response.should be_forbidden expect(response).to be_forbidden
end end
context "fetching a user by external_id" do context "fetching a user by external_id" do
@ -36,33 +36,33 @@ describe UsersController do
it "returns fetch for a matching external_id" do it "returns fetch for a matching external_id" do
xhr :get, :show, external_id: '997' xhr :get, :show, external_id: '997'
response.should be_success expect(response).to be_success
end end
it "returns not found when external_id doesn't match" do it "returns not found when external_id doesn't match" do
xhr :get, :show, external_id: '99' xhr :get, :show, external_id: '99'
response.should_not be_success expect(response).not_to be_success
end end
end end
end end
describe '.user_preferences_redirect' do describe '.user_preferences_redirect' do
it 'requires the user to be logged in' 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 end
it "redirects to their profile when logged in" do it "redirects to their profile when logged in" do
user = log_in user = log_in
get :user_preferences_redirect 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
end end
describe '.authorize_email' do describe '.authorize_email' do
it 'errors out for invalid tokens' do it 'errors out for invalid tokens' do
get :authorize_email, token: 'asdfasdf' get :authorize_email, token: 'asdfasdf'
response.should be_success expect(response).to be_success
flash[:error].should be_present expect(flash[:error]).to be_present
end end
context 'valid token' do context 'valid token' do
@ -71,9 +71,9 @@ describe UsersController do
email_token = user.email_tokens.create(email: user.email) email_token = user.email_tokens.create(email: user.email)
get :authorize_email, token: email_token.token get :authorize_email, token: email_token.token
response.should be_success expect(response).to be_success
flash[:error].should be_blank expect(flash[:error]).to be_blank
session[:current_user_id].should be_present expect(session[:current_user_id]).to be_present
end end
end end
end end
@ -90,11 +90,11 @@ describe UsersController do
end end
it 'return success' do it 'return success' do
response.should be_success expect(response).to be_success
end end
it 'sets a flash error' do it 'sets a flash error' do
flash[:error].should be_present expect(flash[:error]).to be_present
end end
end end
@ -123,7 +123,7 @@ describe UsersController do
it "raises an error if the honeypot is invalid" do it "raises an error if the honeypot is invalid" do
UsersController.any_instance.stubs(:honeypot_or_challenge_fails?).returns(true) UsersController.any_instance.stubs(:honeypot_or_challenge_fails?).returns(true)
put :perform_account_activation, token: 'asdfasdf' put :perform_account_activation, token: 'asdfasdf'
response.should_not be_success expect(response).not_to be_success
end end
end end
@ -135,19 +135,19 @@ describe UsersController do
end end
it 'returns success' do it 'returns success' do
response.should be_success expect(response).to be_success
end end
it "doesn't set an error" do it "doesn't set an error" do
flash[:error].should be_blank expect(flash[:error]).to be_blank
end end
it 'logs in as the user' do it 'logs in as the user' do
session[:current_user_id].should be_present expect(session[:current_user_id]).to be_present
end end
it "doesn't set @needs_approval" do it "doesn't set @needs_approval" do
assigns[:needs_approval].should be_blank expect(assigns[:needs_approval]).to be_blank
end end
end end
@ -159,19 +159,19 @@ describe UsersController do
end end
it 'returns success' do it 'returns success' do
response.should be_success expect(response).to be_success
end end
it 'sets @needs_approval' do it 'sets @needs_approval' do
assigns[:needs_approval].should be_present expect(assigns[:needs_approval]).to be_present
end end
it "doesn't set an error" do it "doesn't set an error" do
flash[:error].should be_blank expect(flash[:error]).to be_blank
end end
it "doesn't log the user in" do 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
end end
@ -182,30 +182,30 @@ describe UsersController do
let(:new_email) { 'bubblegum@adventuretime.ooo' } let(:new_email) { 'bubblegum@adventuretime.ooo' }
it "requires you to be logged in" do 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 end
context 'when logged in' do context 'when logged in' do
let!(:user) { log_in } let!(:user) { log_in }
it 'raises an error without an email parameter' do 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 end
it "raises an error if you can't edit the user's email" do 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) Guardian.any_instance.expects(:can_edit_email?).with(user).returns(false)
xhr :put, :change_email, username: user.username, email: new_email xhr :put, :change_email, username: user.username, email: new_email
response.should be_forbidden expect(response).to be_forbidden
end end
context 'when the new email address is taken' do context 'when the new email address is taken' do
let!(:other_user) { Fabricate(:coding_horror) } let!(:other_user) { Fabricate(:coding_horror) }
it 'raises an error' do 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 end
it 'raises an error if there is whitespace too' do 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
end end
@ -213,14 +213,14 @@ describe UsersController do
let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com')} let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com')}
it 'raises an error' do 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
end end
context 'success' do context 'success' do
it 'has an email token' 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 end
it 'enqueues an email authorization' do it 'enqueues an email authorization' do
@ -239,7 +239,7 @@ describe UsersController do
it "returns success" do it "returns success" do
SiteSetting.login_required = true SiteSetting.login_required = true
get :password_reset, token: 'asdfasdf' get :password_reset, token: 'asdfasdf'
response.should be_success expect(response).to be_success
end end
end end
@ -249,10 +249,10 @@ describe UsersController do
end end
it 'disallows login' do it 'disallows login' do
flash[:error].should be_present expect(flash[:error]).to be_present
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
assigns[:invalid_token].should == nil expect(assigns[:invalid_token]).to eq(nil)
response.should be_success expect(response).to be_success
end end
end end
@ -262,10 +262,10 @@ describe UsersController do
end end
it 'disallows login' do it 'disallows login' do
flash[:error].should be_present expect(flash[:error]).to be_present
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
assigns[:invalid_token].should == true expect(assigns[:invalid_token]).to eq(true)
response.should be_success expect(response).to be_success
end end
end end
@ -276,8 +276,8 @@ describe UsersController do
get :password_reset, token: token get :password_reset, token: token
put :password_reset, token: token, password: 'newpassword' put :password_reset, token: token, password: 'newpassword'
response.should be_success expect(response).to be_success
flash[:error].should be_blank expect(flash[:error]).to be_blank
end end
end end
@ -289,27 +289,27 @@ describe UsersController do
it "fails when the password is blank" do it "fails when the password is blank" do
put :password_reset, token: token, password: '' put :password_reset, token: token, password: ''
assigns(:user).errors.should be_present expect(assigns(:user).errors).to be_present
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it "fails when the password is too long" do it "fails when the password is too long" do
put :password_reset, token: token, password: ('x' * (User.max_password_length + 1)) put :password_reset, token: token, password: ('x' * (User.max_password_length + 1))
assigns(:user).errors.should be_present expect(assigns(:user).errors).to be_present
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
it "logs in the user" do it "logs in the user" do
put :password_reset, token: token, password: 'newpassword' put :password_reset, token: token, password: 'newpassword'
assigns(:user).errors.should be_blank expect(assigns(:user).errors).to be_blank
session[:current_user_id].should be_present expect(session[:current_user_id]).to be_present
end end
it "doesn't log in the user when not approved" do it "doesn't log in the user when not approved" do
SiteSetting.expects(:must_approve_users?).returns(true) SiteSetting.expects(:must_approve_users?).returns(true)
put :password_reset, token: token, password: 'newpassword' put :password_reset, token: token, password: 'newpassword'
assigns(:user).errors.should be_blank expect(assigns(:user).errors).to be_blank
session[:current_user_id].should be_blank expect(session[:current_user_id]).to be_blank
end end
end end
end end
@ -345,8 +345,8 @@ describe UsersController do
SiteSetting.stubs(:allow_new_registrations).returns(false) SiteSetting.stubs(:allow_new_registrations).returns(false)
post_user post_user
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['success'].should == false expect(json['success']).to eq(false)
json['message'].should be_present expect(json['message']).to be_present
end end
it 'creates a user correctly' do it 'creates a user correctly' do
@ -358,7 +358,7 @@ describe UsersController do
expect(JSON.parse(response.body)['active']).to be_falsey expect(JSON.parse(response.body)['active']).to be_falsey
# should save user_created_message in session # should save user_created_message in session
session["user_created_message"].should be_present expect(session["user_created_message"]).to be_present
end end
context "and 'must approve users' site setting is enabled" do context "and 'must approve users' site setting is enabled" do
@ -394,7 +394,7 @@ describe UsersController do
post_user post_user
# should save user_created_message in session # should save user_created_message in session
session["user_created_message"].should be_present expect(session["user_created_message"]).to be_present
end end
it "shows the 'active' message" do it "shows the 'active' message" do
@ -408,7 +408,7 @@ describe UsersController do
it "should be logged in" do it "should be logged in" do
User.any_instance.expects(:enqueue_welcome_message) User.any_instance.expects(:enqueue_welcome_message)
post_user post_user
session[:current_user_id].should be_present expect(session[:current_user_id]).to be_present
end end
it 'indicates the user is active in the response' do it 'indicates the user is active in the response' do
@ -421,8 +421,8 @@ describe UsersController do
SiteSetting.stubs(:allow_new_registrations).returns(false) SiteSetting.stubs(:allow_new_registrations).returns(false)
post_user post_user
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['success'].should == false expect(json['success']).to eq(false)
json['message'].should be_present expect(json['message']).to be_present
end end
context 'authentication records for' do context 'authentication records for' do
@ -448,16 +448,16 @@ describe UsersController do
before { post_user } before { post_user }
it 'should succeed' do it 'should succeed' do
should respond_with(:success) is_expected.to respond_with(:success)
end end
it 'has the proper JSON' do it 'has the proper JSON' do
json = JSON::parse(response.body) json = JSON::parse(response.body)
json["success"].should == true expect(json["success"]).to eq(true)
end end
it 'should not result in an active account' do 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
end end
@ -476,10 +476,10 @@ describe UsersController do
it 'should say it was successful' do it 'should say it was successful' do
xhr :post, :create, create_params xhr :post, :create, create_params
json = JSON::parse(response.body) json = JSON::parse(response.body)
json["success"].should == true expect(json["success"]).to eq(true)
# should not change the session # should not change the session
session["user_created_message"].should be_blank expect(session["user_created_message"]).to be_blank
end end
end end
@ -520,10 +520,10 @@ describe UsersController do
it 'should report failed' do it 'should report failed' do
xhr :post, :create, create_params xhr :post, :create, create_params
json = JSON::parse(response.body) json = JSON::parse(response.body)
json["success"].should_not == true expect(json["success"]).not_to eq(true)
# should not change the session # should not change the session
session["user_created_message"].should be_blank expect(session["user_created_message"]).to be_blank
end end
end end
@ -580,25 +580,25 @@ describe UsersController do
it "should succeed without the optional field" do it "should succeed without the optional field" do
xhr :post, :create, create_params xhr :post, :create, create_params
response.should be_success expect(response).to be_success
inserted = User.where(email: @user.email).first inserted = User.where(email: @user.email).first
inserted.should be_present expect(inserted).to be_present
inserted.custom_fields.should be_present expect(inserted.custom_fields).to be_present
inserted.custom_fields["user_field_#{user_field.id}"].should == 'value1' expect(inserted.custom_fields["user_field_#{user_field.id}"]).to eq('value1')
inserted.custom_fields["user_field_#{another_field.id}"].should == 'value2' expect(inserted.custom_fields["user_field_#{another_field.id}"]).to eq('value2')
inserted.custom_fields["user_field_#{optional_field.id}"].should be_blank expect(inserted.custom_fields["user_field_#{optional_field.id}"]).to be_blank
end end
it "should succeed with the optional field" do it "should succeed with the optional field" do
create_params[:user_fields][optional_field.id.to_s] = 'value3' create_params[:user_fields][optional_field.id.to_s] = 'value3'
xhr :post, :create, create_params.merge(create_params) 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 = User.where(email: @user.email).first
inserted.should be_present expect(inserted).to be_present
inserted.custom_fields.should be_present expect(inserted.custom_fields).to be_present
inserted.custom_fields["user_field_#{user_field.id}"].should == 'value1' expect(inserted.custom_fields["user_field_#{user_field.id}"]).to eq('value1')
inserted.custom_fields["user_field_#{another_field.id}"].should == 'value2' expect(inserted.custom_fields["user_field_#{another_field.id}"]).to eq('value2')
inserted.custom_fields["user_field_#{optional_field.id}"].should == 'value3' expect(inserted.custom_fields["user_field_#{optional_field.id}"]).to eq('value3')
end end
end end
@ -608,7 +608,7 @@ describe UsersController do
context '.username' do context '.username' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do context 'while logged in' do
@ -616,29 +616,29 @@ describe UsersController do
let(:new_username) { "#{user.username}1234" } let(:new_username) { "#{user.username}1234" }
it 'raises an error without a new_username param' do 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 end
it 'raises an error when you don\'t have permission to change the username' do 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) Guardian.any_instance.expects(:can_edit_username?).with(user).returns(false)
xhr :put, :username, username: user.username, new_username: new_username xhr :put, :username, username: user.username, new_username: new_username
response.should be_forbidden expect(response).to be_forbidden
end end
it 'raises an error when change_username fails' do it 'raises an error when change_username fails' do
User.any_instance.expects(:change_username).with(new_username).returns(false) 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 end
it 'should succeed when the change_username returns true' do it 'should succeed when the change_username returns true' do
User.any_instance.expects(:change_username).with(new_username).returns(true) User.any_instance.expects(:change_username).with(new_username).returns(true)
xhr :put, :username, username: user.username, new_username: new_username xhr :put, :username, username: user.username, new_username: new_username
response.should be_success expect(response).to be_success
end end
it 'should return a JSON response with the updated username' do it 'should return a JSON response with the updated username' do
xhr :put, :username, username: user.username, new_username: new_username 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
end end
@ -646,36 +646,36 @@ describe UsersController do
context '.check_username' do context '.check_username' do
it 'raises an error without any parameters' 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 end
shared_examples 'when username is unavailable' do shared_examples 'when username is unavailable' do
it 'should return success' do it 'should return success' do
response.should be_success expect(response).to be_success
end end
it 'should return available as false in the JSON' do 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 end
it 'should return a suggested username' do 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
end end
shared_examples 'when username is available' do shared_examples 'when username is available' do
it 'should return success' do it 'should return success' do
response.should be_success expect(response).to be_success
end end
it 'should return available in the JSON' do 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
end end
it 'returns nothing when given an email param but no username' do it 'returns nothing when given an email param but no username' do
xhr :get, :check_username, email: 'dood@example.com' xhr :get, :check_username, email: 'dood@example.com'
response.should be_success expect(response).to be_success
end end
context 'username is available' do context 'username is available' do
@ -695,15 +695,15 @@ describe UsersController do
shared_examples 'checking an invalid username' do shared_examples 'checking an invalid username' do
it 'should return success' do it 'should return success' do
response.should be_success expect(response).to be_success
end end
it 'should not return an available key' do 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 end
it 'should return an error message' do 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
end end
@ -714,7 +714,7 @@ describe UsersController do
include_examples 'checking an invalid username' include_examples 'checking an invalid username'
it 'should return the invalid characters message' do 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
end end
@ -725,7 +725,7 @@ describe UsersController do
include_examples 'checking an invalid username' include_examples 'checking an invalid username'
it 'should return the "too long" message' do 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
end end
@ -787,7 +787,7 @@ describe UsersController do
xhr :get, :invited, username: inviter.username, filter: 'billybob' xhr :get, :invited, username: inviter.username, filter: 'billybob'
invites = JSON.parse(response.body)['invites'] 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') expect(invites.first).to include('email' => 'billybob@example.com')
end end
@ -809,7 +809,7 @@ describe UsersController do
xhr :get, :invited, username: inviter.username, filter: 'billybob' xhr :get, :invited, username: inviter.username, filter: 'billybob'
invites = JSON.parse(response.body)['invites'] 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') expect(invites.first).to include('email' => 'billybob@example.com')
end end
@ -835,7 +835,7 @@ describe UsersController do
xhr :get, :invited, username: inviter.username xhr :get, :invited, username: inviter.username
invites = JSON.parse(response.body)['invites'] invites = JSON.parse(response.body)['invites']
invites.size.should == 1 expect(invites.size).to eq(1)
expect(invites.first).to include('email' => invite.email) expect(invites.first).to include('email' => invite.email)
end end
end end
@ -856,7 +856,7 @@ describe UsersController do
xhr :get, :invited, username: inviter.username xhr :get, :invited, username: inviter.username
invites = JSON.parse(response.body)['invites'] invites = JSON.parse(response.body)['invites']
invites.size.should == 1 expect(invites.size).to eq(1)
expect(invites.first).to include("email" => invite.email) expect(invites.first).to include("email" => invite.email)
end end
end end
@ -890,7 +890,7 @@ describe UsersController do
xhr :get, :invited, username: inviter.username xhr :get, :invited, username: inviter.username
invites = JSON.parse(response.body)['invites'] invites = JSON.parse(response.body)['invites']
invites.size.should == 1 expect(invites.size).to eq(1)
expect(invites.first).to include('email' => invite.email) expect(invites.first).to include('email' => invite.email)
end end
end end
@ -933,8 +933,8 @@ describe UsersController do
it "cannot be updated to blank" do it "cannot be updated to blank" do
put :update, username: user.username, name: 'Jim Tom', user_fields: { user_field.id.to_s => '' } put :update, username: user.username, name: 'Jim Tom', user_fields: { user_field.id.to_s => '' }
response.should_not be_success expect(response).not_to be_success
user.user_fields[user_field.id.to_s].should_not == 'happy' expect(user.user_fields[user_field.id.to_s]).not_to eq('happy')
end end
end end
@ -984,15 +984,15 @@ describe UsersController do
it "sets the user's card image to the badge" do it "sets the user's card image to the badge" do
log_in_user user log_in_user user
xhr :put, :update_card_badge, user_badge_id: user_badge.id, username: user.username 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" badge.update_attributes image: "wat.com/wat.jpg"
xhr :put, :update_card_badge, user_badge_id: user_badge.id, username: user.username 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 # Can set to nothing
xhr :put, :update_card_badge, username: user.username 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
end end
@ -1004,16 +1004,16 @@ describe UsersController do
it "sets the user's title to the badge name if it is titleable" do it "sets the user's title to the badge name if it is titleable" do
log_in_user user log_in_user user
xhr :put, :badge_title, user_badge_id: user_badge.id, username: user.username 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 badge.update_attributes allow_title: true
xhr :put, :badge_title, user_badge_id: user_badge.id, username: user.username xhr :put, :badge_title, user_badge_id: user_badge.id, username: user.username
user.reload.title.should == badge.name expect(user.reload.title).to eq(badge.name)
user.user_profile.badge_granted_title.should == true expect(user.user_profile.badge_granted_title).to eq(true)
user.title = "testing" user.title = "testing"
user.save user.save
user.user_profile.reload user.user_profile.reload
user.user_profile.badge_granted_title.should == false expect(user.user_profile.badge_granted_title).to eq(false)
end end
end end
@ -1030,23 +1030,23 @@ describe UsersController do
it "searches when provided the term only" do it "searches when provided the term only" do
xhr :post, :search_users, term: user.name.split(" ").last xhr :post, :search_users, term: user.name.split(" ").last
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) 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 end
it "searches when provided the topic only" do it "searches when provided the topic only" do
xhr :post, :search_users, topic_id: topic.id xhr :post, :search_users, topic_id: topic.id
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) 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 end
it "searches when provided the term and topic" do it "searches when provided the term and topic" do
xhr :post, :search_users, term: user.name.split(" ").last, topic_id: topic.id 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 = 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 end
context "when `enable_names` is true" do context "when `enable_names` is true" do
@ -1057,7 +1057,7 @@ describe UsersController do
it "returns names" do it "returns names" do
xhr :post, :search_users, term: user.name xhr :post, :search_users, term: user.name
json = JSON.parse(response.body) 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
end end
@ -1069,7 +1069,7 @@ describe UsersController do
it "returns names" do it "returns names" do
xhr :post, :search_users, term: user.name xhr :post, :search_users, term: user.name
json = JSON.parse(response.body) 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
end end
@ -1116,7 +1116,7 @@ describe UsersController do
describe '.upload_user_image' do describe '.upload_user_image' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do context 'while logged in' do
@ -1130,7 +1130,7 @@ describe UsersController do
end end
it 'raises an error without a image_type param' do 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 end
describe "with uploaded file" do 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 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) Guardian.any_instance.expects(:can_edit?).with(user).returns(false)
xhr :post, :upload_user_image, username: user.username, image_type: "avatar" xhr :post, :upload_user_image, username: user.username, image_type: "avatar"
response.should be_forbidden expect(response).to be_forbidden
end end
it 'rejects large images' do it 'rejects large images' do
SiteSetting.stubs(:max_image_size_kb).returns(1) SiteSetting.stubs(:max_image_size_kb).returns(1)
xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar" 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 end
it 'rejects unauthorized images' do it 'rejects unauthorized images' do
SiteSetting.stubs(:authorized_extensions).returns(".txt") SiteSetting.stubs(:authorized_extensions).returns(".txt")
xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar" 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 end
it 'is successful for avatars' do 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" xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "avatar"
# returns the url, width and height of the uploaded image # returns the url, width and height of the uploaded image
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
json['upload_id'].should == upload.id expect(json['upload_id']).to eq(upload.id)
end end
it 'is successful for profile backgrounds' do 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" xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "profile_background"
user.reload 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 # returns the url, width and height of the uploaded image
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
end end
it 'is successful for card backgrounds' do 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" xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "card_background"
user.reload 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 # returns the url, width and height of the uploaded image
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
end end
end end
@ -1210,13 +1210,13 @@ describe UsersController do
it 'rejects large images' do it 'rejects large images' do
SiteSetting.stubs(:max_image_size_kb).returns(1) SiteSetting.stubs(:max_image_size_kb).returns(1)
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" 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 end
it 'rejects unauthorized images' do it 'rejects unauthorized images' do
SiteSetting.stubs(:authorized_extensions).returns(".txt") SiteSetting.stubs(:authorized_extensions).returns(".txt")
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" 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 end
it 'is successful for avatars' do it 'is successful for avatars' do
@ -1225,10 +1225,10 @@ describe UsersController do
# enqueues the user_image generator job # enqueues the user_image generator job
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "avatar" xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "avatar"
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
json['upload_id'].should == upload.id expect(json['upload_id']).to eq(upload.id)
end end
it 'is successful for profile backgrounds' do it 'is successful for profile backgrounds' do
@ -1236,13 +1236,13 @@ describe UsersController do
Upload.expects(:create_for).returns(upload) Upload.expects(:create_for).returns(upload)
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background" xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "profile_background"
user.reload 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 # returns the url, width and height of the uploaded image
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
end end
it 'is successful for card backgrounds' do it 'is successful for card backgrounds' do
@ -1250,19 +1250,19 @@ describe UsersController do
Upload.expects(:create_for).returns(upload) Upload.expects(:create_for).returns(upload)
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "card_background" xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "card_background"
user.reload 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 # returns the url, width and height of the uploaded image
json = JSON.parse(response.body) json = JSON.parse(response.body)
json['url'].should == "/uploads/default/1/1234567890123456.png" expect(json['url']).to eq("/uploads/default/1/1234567890123456.png")
json['width'].should == 100 expect(json['width']).to eq(100)
json['height'].should == 200 expect(json['height']).to eq(200)
end end
end end
it "should handle malformed urls" do it "should handle malformed urls" do
xhr :post, :upload_user_image, username: user.username, file: "foobar", image_type: "profile_background" 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
end end
@ -1274,7 +1274,7 @@ describe UsersController do
describe '.pick_avatar' do describe '.pick_avatar' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do 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 it 'raises an error when you don\'t have permission to toggle the avatar' do
another_user = Fabricate(:user) another_user = Fabricate(:user)
xhr :put, :pick_avatar, username: another_user.username, upload_id: 1 xhr :put, :pick_avatar, username: another_user.username, upload_id: 1
response.should be_forbidden expect(response).to be_forbidden
end end
it 'it successful' do it 'it successful' do
xhr :put, :pick_avatar, username: user.username, upload_id: 111 xhr :put, :pick_avatar, username: user.username, upload_id: 111
user.reload.uploaded_avatar_id.should == 111 expect(user.reload.uploaded_avatar_id).to eq(111)
response.should be_success expect(response).to be_success
xhr :put, :pick_avatar, username: user.username xhr :put, :pick_avatar, username: user.username
user.reload.uploaded_avatar_id.should == nil expect(user.reload.uploaded_avatar_id).to eq(nil)
response.should be_success expect(response).to be_success
end end
it 'returns success' do it 'returns success' do
xhr :put, :pick_avatar, username: user.username, upload_id: 111 xhr :put, :pick_avatar, username: user.username, upload_id: 111
user.reload.uploaded_avatar_id.should == 111 expect(user.reload.uploaded_avatar_id).to eq(111)
response.should be_success expect(response).to be_success
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
json['success'].should == "OK" expect(json['success']).to eq("OK")
end end
end end
@ -1311,7 +1311,7 @@ describe UsersController do
describe '.destroy_user_image' do describe '.destroy_user_image' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do 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 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) Guardian.any_instance.expects(:can_edit?).with(user).returns(false)
xhr :delete, :destroy_user_image, username: user.username, image_type: 'profile_background' xhr :delete, :destroy_user_image, username: user.username, image_type: 'profile_background'
response.should be_forbidden expect(response).to be_forbidden
end end
it "requires the `image_type` param" do 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 end
it "only allows certain `image_types`" do 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 end
it 'can clear the profile background' do it 'can clear the profile background' do
xhr :delete, :destroy_user_image, image_type: 'profile_background', username: user.username xhr :delete, :destroy_user_image, image_type: 'profile_background', username: user.username
user.reload.user_profile.profile_background.should == "" expect(user.reload.user_profile.profile_background).to eq("")
response.should be_success expect(response).to be_success
end end
end end
@ -1343,7 +1343,7 @@ describe UsersController do
describe '.destroy' do describe '.destroy' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do context 'while logged in' do
@ -1353,20 +1353,20 @@ describe UsersController do
Guardian.any_instance.stubs(:can_delete_user?).returns(false) Guardian.any_instance.stubs(:can_delete_user?).returns(false)
UserDestroyer.any_instance.expects(:destroy).never UserDestroyer.any_instance.expects(:destroy).never
xhr :delete, :destroy, username: user.username xhr :delete, :destroy, username: user.username
response.should be_forbidden expect(response).to be_forbidden
end end
it "raises an error when you try to delete someone else's account" do it "raises an error when you try to delete someone else's account" do
UserDestroyer.any_instance.expects(:destroy).never UserDestroyer.any_instance.expects(:destroy).never
xhr :delete, :destroy, username: Fabricate(:user).username xhr :delete, :destroy, username: Fabricate(:user).username
response.should be_forbidden expect(response).to be_forbidden
end end
it "deletes your account when you're allowed to" do it "deletes your account when you're allowed to" do
Guardian.any_instance.stubs(:can_delete_user?).returns(true) Guardian.any_instance.stubs(:can_delete_user?).returns(true)
UserDestroyer.any_instance.expects(:destroy).with(user, anything).returns(user) UserDestroyer.any_instance.expects(:destroy).with(user, anything).returns(user)
xhr :delete, :destroy, username: user.username xhr :delete, :destroy, username: user.username
response.should be_success expect(response).to be_success
end end
end end
end end
@ -1375,8 +1375,8 @@ describe UsersController do
it "returns 404 if the user is not logged in" do it "returns 404 if the user is not logged in" do
get :my_redirect, path: "wat" get :my_redirect, path: "wat"
response.should_not be_success expect(response).not_to be_success
response.should_not be_redirect expect(response).not_to be_redirect
end end
context "when the user is logged in" do context "when the user is logged in" do
@ -1384,17 +1384,17 @@ describe UsersController do
it "will not redirect to an invalid path" do it "will not redirect to an invalid path" do
get :my_redirect, path: "wat/..password.txt" get :my_redirect, path: "wat/..password.txt"
response.should_not be_redirect expect(response).not_to be_redirect
end end
it "will redirect to an valid path" do it "will redirect to an valid path" do
get :my_redirect, path: "preferences" get :my_redirect, path: "preferences"
response.should be_redirect expect(response).to be_redirect
end end
it "permits forward slashes" do it "permits forward slashes" do
get :my_redirect, path: "activity/posts" get :my_redirect, path: "activity/posts"
response.should be_redirect expect(response).to be_redirect
end end
end end
end end
@ -1402,7 +1402,7 @@ describe UsersController do
describe '.check_emails' do describe '.check_emails' do
it 'raises an error when not logged in' 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 end
context 'while logged in' do 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 it "raises an error when you aren't allowed to check emails" do
Guardian.any_instance.expects(:can_check_emails?).returns(false) Guardian.any_instance.expects(:can_check_emails?).returns(false)
xhr :put, :check_emails, username: Fabricate(:user).username xhr :put, :check_emails, username: Fabricate(:user).username
response.should be_forbidden expect(response).to be_forbidden
end end
it "returns both email and associated_accounts when you're allowed to see them" do it "returns both email and associated_accounts when you're allowed to see them" do
Guardian.any_instance.expects(:can_check_emails?).returns(true) Guardian.any_instance.expects(:can_check_emails?).returns(true)
xhr :put, :check_emails, username: Fabricate(:user).username xhr :put, :check_emails, username: Fabricate(:user).username
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) json = JSON.parse(response.body)
json["email"].should be_present expect(json["email"]).to be_present
json["associated_accounts"].should be_present expect(json["associated_accounts"]).to be_present
end end
it "works on inactive users" do it "works on inactive users" do
inactive_user = Fabricate(:user, active: false) inactive_user = Fabricate(:user, active: false)
Guardian.any_instance.expects(:can_check_emails?).returns(true) Guardian.any_instance.expects(:can_check_emails?).returns(true)
xhr :put, :check_emails, username: inactive_user.username xhr :put, :check_emails, username: inactive_user.username
response.should be_success expect(response).to be_success
json = JSON.parse(response.body) json = JSON.parse(response.body)
json["email"].should be_present expect(json["email"]).to be_present
json["associated_accounts"].should be_present expect(json["associated_accounts"]).to be_present
end end
end end