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
@@ -5,13 +5,13 @@ describe Admin::AdminController do
context 'index' do
it 'needs you to be logged in' do
lambda { xhr :get, :index }.should raise_error(Discourse::NotLoggedIn)
expect { xhr :get, :index }.to raise_error(Discourse::NotLoggedIn)
end
it "raises an error if you aren't an admin" do
user = log_in
xhr :get, :index
response.should be_forbidden
expect(response).to be_forbidden
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ApiController do
it "is a subclass of AdminController" do
(Admin::ApiController < Admin::AdminController).should == true
expect(Admin::ApiController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -11,7 +11,7 @@ describe Admin::ApiController do
context '.index' do
it "succeeds" do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
end
@@ -20,8 +20,8 @@ describe Admin::ApiController do
it "returns 404 when there is no key" do
xhr :put, :regenerate_key, id: 1234
response.should_not be_success
response.status.should == 404
expect(response).not_to be_success
expect(response.status).to eq(404)
end
it "delegates to the api key's `regenerate!` method" do
@@ -35,8 +35,8 @@ describe Admin::ApiController do
it "returns 404 when there is no key" do
xhr :delete, :revoke_key, id: 1234
response.should_not be_success
response.status.should == 404
expect(response).not_to be_success
expect(response.status).to eq(404)
end
it "delegates to the api key's `regenerate!` method" do
@@ -47,9 +47,9 @@ describe Admin::ApiController do
context '.create_master_key' do
it "creates a record" do
lambda {
expect {
xhr :post, :create_master_key
}.should change(ApiKey, :count).by(1)
}.to change(ApiKey, :count).by(1)
end
end
@@ -3,7 +3,7 @@ require "spec_helper"
describe Admin::BackupsController do
it "is a subclass of AdminController" do
(Admin::BackupsController < Admin::AdminController).should == true
expect(Admin::BackupsController < Admin::AdminController).to eq(true)
end
let(:backup_filename) { "2014-02-10-065935.tar.gz" }
@@ -28,7 +28,7 @@ describe Admin::BackupsController do
xhr :get, :index, format: :html
response.should be_success
expect(response).to be_success
end
end
@@ -40,11 +40,11 @@ describe Admin::BackupsController do
xhr :get, :index, format: :json
response.should be_success
expect(response).to be_success
json = JSON.parse(response.body)
json[0]["filename"].should == "backup1"
json[1]["filename"].should == "backup2"
expect(json[0]["filename"]).to eq("backup1")
expect(json[1]["filename"]).to eq("backup2")
end
end
@@ -58,7 +58,7 @@ describe Admin::BackupsController do
xhr :get, :status
response.should be_success
expect(response).to be_success
end
end
@@ -70,7 +70,7 @@ describe Admin::BackupsController do
xhr :post, :create, { with_uploads: false }
response.should be_success
expect(response).to be_success
end
end
@@ -82,7 +82,7 @@ describe Admin::BackupsController do
xhr :delete, :cancel
response.should be_success
expect(response).to be_success
end
end
@@ -99,8 +99,8 @@ describe Admin::BackupsController do
get :show, id: backup_filename
response.headers['Content-Length'].should == 5
response.headers['Content-Disposition'].should =~ /attachment; filename/
expect(response.headers['Content-Length']).to eq(5)
expect(response.headers['Content-Disposition']).to match(/attachment; filename/)
end
it "returns 404 when the backup does not exist" do
@@ -108,7 +108,7 @@ describe Admin::BackupsController do
get :show, id: backup_filename
response.should be_not_found
expect(response).to be_not_found
end
end
@@ -121,14 +121,14 @@ describe Admin::BackupsController do
Backup.expects(:[]).with(backup_filename).returns(b)
b.expects(:remove)
xhr :delete, :destroy, id: backup_filename
response.should be_success
expect(response).to be_success
end
it "doesn't remove the backup if not found" do
Backup.expects(:[]).with(backup_filename).returns(nil)
b.expects(:remove).never
xhr :delete, :destroy, id: backup_filename
response.should_not be_success
expect(response).not_to be_success
end
end
@@ -144,7 +144,7 @@ describe Admin::BackupsController do
xhr :get, :logs, format: :html
response.should be_success
expect(response).to be_success
end
end
@@ -155,7 +155,7 @@ describe Admin::BackupsController do
xhr :post, :restore, id: backup_filename
response.should be_success
expect(response).to be_success
end
end
@@ -167,7 +167,7 @@ describe Admin::BackupsController do
xhr :get, :rollback
response.should be_success
expect(response).to be_success
end
end
@@ -179,7 +179,7 @@ describe Admin::BackupsController do
xhr :put, :readonly, enable: true
response.should be_success
expect(response).to be_success
end
it "disables readonly mode" do
@@ -187,7 +187,7 @@ describe Admin::BackupsController do
xhr :put, :readonly, enable: false
response.should be_success
expect(response).to be_success
end
end
@@ -9,7 +9,7 @@ describe Admin::BadgesController do
context 'index' do
it 'returns badge index' do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
end
@@ -30,46 +30,46 @@ describe Admin::BadgesController do
groupings2 = BadgeGrouping.all.order(:position).to_a
groupings2.map{|g| g.name}.should == names
(groupings.map(&:id) - groupings2.map{|g| g.id}).compact.should be_blank
expect(groupings2.map{|g| g.name}).to eq(names)
expect((groupings.map(&:id) - groupings2.map{|g| g.id}).compact).to be_blank
::JSON.parse(response.body)["badge_groupings"].length.should == groupings2.length
expect(::JSON.parse(response.body)["badge_groupings"].length).to eq(groupings2.length)
end
end
context '.badge_types' do
it 'returns success' do
xhr :get, :badge_types
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :badge_types
::JSON.parse(response.body)["badge_types"].should be_present
expect(::JSON.parse(response.body)["badge_types"]).to be_present
end
end
context '.destroy' do
it 'returns success' do
xhr :delete, :destroy, id: badge.id
response.should be_success
expect(response).to be_success
end
it 'deletes the badge' do
xhr :delete, :destroy, id: badge.id
Badge.where(id: badge.id).count.should eq(0)
expect(Badge.where(id: badge.id).count).to eq(0)
end
end
context '.update' do
it 'returns success' do
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: false, enabled: true
response.should be_success
expect(response).to be_success
end
it 'updates the badge' do
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: true, enabled: true
badge.reload.name.should eq('123456')
expect(badge.reload.name).to eq('123456')
end
end
end
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ColorSchemesController do
it "is a subclass of AdminController" do
(described_class < Admin::AdminController).should == true
expect(described_class < Admin::AdminController).to eq(true)
end
context "while logged in as an admin" do
@@ -20,33 +20,33 @@ describe Admin::ColorSchemesController do
describe "index" do
it "returns success" do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
it "returns JSON" do
Fabricate(:color_scheme)
xhr :get, :index
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
describe "create" do
it "returns success" do
xhr :post, :create, valid_params
response.should be_success
expect(response).to be_success
end
it "returns JSON" do
xhr :post, :create, valid_params
::JSON.parse(response.body)['id'].should be_present
expect(::JSON.parse(response.body)['id']).to be_present
end
it "returns failure with invalid params" do
params = valid_params
params[:color_scheme][:colors][0][:hex] = 'cool color please'
xhr :post, :create, valid_params
response.should_not be_success
::JSON.parse(response.body)['errors'].should be_present
expect(response).not_to be_success
expect(::JSON.parse(response.body)['errors']).to be_present
end
end
@@ -56,13 +56,13 @@ describe Admin::ColorSchemesController do
it "returns success" do
ColorSchemeRevisor.expects(:revise).returns(existing)
xhr :put, :update, valid_params.merge(id: existing.id)
response.should be_success
expect(response).to be_success
end
it "returns JSON" do
ColorSchemeRevisor.expects(:revise).returns(existing)
xhr :put, :update, valid_params.merge(id: existing.id)
::JSON.parse(response.body)['id'].should be_present
expect(::JSON.parse(response.body)['id']).to be_present
end
it "returns failure with invalid params" do
@@ -71,8 +71,8 @@ describe Admin::ColorSchemesController do
params[:color_scheme][:colors][0][:name] = color_scheme.colors.first.name
params[:color_scheme][:colors][0][:hex] = 'cool color please'
xhr :put, :update, params
response.should_not be_success
::JSON.parse(response.body)['errors'].should be_present
expect(response).not_to be_success
expect(::JSON.parse(response.body)['errors']).to be_present
end
end
@@ -83,7 +83,7 @@ describe Admin::ColorSchemesController do
expect {
xhr :delete, :destroy, id: existing.id
}.to change { ColorScheme.count }.by(-1)
response.should be_success
expect(response).to be_success
end
end
end
@@ -8,7 +8,7 @@ describe Admin::DashboardController do
end
it "is a subclass of AdminController" do
(Admin::DashboardController < Admin::AdminController).should == true
expect(Admin::DashboardController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -17,7 +17,7 @@ describe Admin::DashboardController do
context '.index' do
it 'should be successful' do
xhr :get, :index
response.should be_successful
expect(response).to be_successful
end
context 'version checking is enabled' do
@@ -28,7 +28,7 @@ describe Admin::DashboardController do
it 'returns discourse version info' do
xhr :get, :index
json = JSON.parse(response.body)
json['version_check'].should be_present
expect(json['version_check']).to be_present
end
end
@@ -40,7 +40,7 @@ describe Admin::DashboardController do
it 'does not return discourse version info' do
xhr :get, :index
json = JSON.parse(response.body)
json['version_check'].should_not be_present
expect(json['version_check']).not_to be_present
end
end
end
@@ -49,7 +49,7 @@ describe Admin::DashboardController do
it 'should be successful' do
AdminDashboardData.stubs(:fetch_problems).returns([])
xhr :get, :problems
response.should be_successful
expect(response).to be_successful
end
context 'when there are no problems' do
@@ -60,7 +60,7 @@ describe Admin::DashboardController do
it 'returns an empty array' do
xhr :get, :problems
json = JSON.parse(response.body)
json['problems'].size.should == 0
expect(json['problems'].size).to eq(0)
end
end
@@ -72,9 +72,9 @@ describe Admin::DashboardController do
it 'returns an array of strings' do
xhr :get, :problems
json = JSON.parse(response.body)
json['problems'].size.should == 2
json['problems'][0].should be_a(String)
json['problems'][1].should be_a(String)
expect(json['problems'].size).to eq(2)
expect(json['problems'][0]).to be_a(String)
expect(json['problems'][1]).to be_a(String)
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::EmailController do
it "is a subclass of AdminController" do
(Admin::EmailController < Admin::AdminController).should == true
expect(Admin::EmailController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -33,7 +33,7 @@ describe Admin::EmailController do
end
subject { response }
it { should be_success }
it { is_expected.to be_success }
end
context '.skipped' do
@@ -42,12 +42,12 @@ describe Admin::EmailController do
end
subject { response }
it { should be_success }
it { is_expected.to be_success }
end
context '.test' do
it 'raises an error without the email parameter' do
lambda { xhr :post, :test }.should raise_error(ActionController::ParameterMissing)
expect { xhr :post, :test }.to raise_error(ActionController::ParameterMissing)
end
context 'with an email address' do
@@ -62,7 +62,7 @@ describe Admin::EmailController do
context '.preview_digest' do
it 'raises an error without the last_seen_at parameter' do
lambda { xhr :get, :preview_digest }.should raise_error(ActionController::ParameterMissing)
expect { xhr :get, :preview_digest }.to raise_error(ActionController::ParameterMissing)
end
it "previews the digest" do
@@ -10,7 +10,7 @@ describe Admin::EmojisController do
end
it "is a subclass of AdminController" do
(Admin::EmojisController < Admin::AdminController).should == true
expect(Admin::EmojisController < Admin::AdminController).to eq(true)
end
context "when logged in" do
@@ -20,10 +20,10 @@ describe Admin::EmojisController do
it "returns a list of custom emojis" do
Emoji.expects(:custom).returns([custom_emoji])
xhr :get, :index
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json[0]['name'].should == custom_emoji.name
json[0]['url'].should == custom_emoji.url
expect(json[0]['name']).to eq(custom_emoji.name)
expect(json[0]['url']).to eq(custom_emoji.url)
end
end
@@ -34,7 +34,7 @@ describe Admin::EmojisController do
context 'name already exist' do
it "throws an error" do
xhr :post, :create, { name: "hello", file: "" }
response.should_not be_success
expect(response).not_to be_success
end
end
@@ -42,7 +42,7 @@ describe Admin::EmojisController do
it "throws an error" do
Emoji.expects(:create_for).returns(nil)
xhr :post, :create, { name: "garbage", file: "" }
response.should_not be_success
expect(response).not_to be_success
end
end
@@ -57,10 +57,10 @@ describe Admin::EmojisController do
it "creates a custom emoji" do
Emoji.expects(:create_for).returns(custom_emoji2)
xhr :post, :create, { name: "hello2", file: ""}
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['name'].should == custom_emoji2.name
json['url'].should == custom_emoji2.url
expect(json['name']).to eq(custom_emoji2.name)
expect(json['url']).to eq(custom_emoji2.url)
end
end
@@ -71,7 +71,7 @@ describe Admin::EmojisController do
custom_emoji.expects(:remove)
Emoji.expects(:custom).returns([custom_emoji])
xhr :delete, :destroy, id: "hello"
response.should be_success
expect(response).to be_success
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::FlagsController do
it "is a subclass of AdminController" do
(Admin::FlagsController < Admin::AdminController).should == true
expect(Admin::FlagsController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -16,8 +16,8 @@ describe Admin::FlagsController do
xhr :get, :index
data = ::JSON.parse(response.body)
data["users"].should == []
data["posts"].should == []
expect(data["users"]).to eq([])
expect(data["posts"]).to eq([])
end
it 'returns a valid json payload when some thing is flagged' do
@@ -7,7 +7,7 @@ describe Admin::GroupsController do
end
it "is a subclass of AdminController" do
(Admin::GroupsController < Admin::AdminController).should == true
expect(Admin::GroupsController < Admin::AdminController).to eq(true)
end
context ".index" do
@@ -18,15 +18,15 @@ describe Admin::GroupsController do
group.save
xhr :get, :index
response.status.should == 200
::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }.should == [{
expect(response.status).to eq(200)
expect(::JSON.parse(response.body).keep_if {|r| r["id"] == group.id }).to eq([{
"id"=>group.id,
"name"=>group.name,
"user_count"=>1,
"automatic"=>false,
"alias_level"=>0,
"visible"=>true
}]
}])
end
end
@@ -36,12 +36,12 @@ describe Admin::GroupsController do
it "strip spaces on the group name" do
xhr :post, :create, name: " bob "
response.status.should == 200
expect(response.status).to eq(200)
groups = Group.where(name: "bob").to_a
groups.count.should == 1
groups[0].name.should == "bob"
expect(groups.count).to eq(1)
expect(groups[0].name).to eq("bob")
end
end
@@ -50,11 +50,11 @@ describe Admin::GroupsController do
it "ignore name change on automatic group" do
xhr :put, :update, id: 1, name: "WAT", visible: "true"
response.should be_success
expect(response).to be_success
group = Group.find(1)
group.name.should_not == "WAT"
group.visible.should == true
expect(group.name).not_to eq("WAT")
expect(group.visible).to eq(true)
end
end
@@ -64,15 +64,15 @@ describe Admin::GroupsController do
it "returns a 422 if the group is automatic" do
group = Fabricate(:group, automatic: true)
xhr :delete, :destroy, id: group.id
response.status.should == 422
Group.where(id: group.id).count.should == 1
expect(response.status).to eq(422)
expect(Group.where(id: group.id).count).to eq(1)
end
it "is able to destroy a non-automatic group" do
group = Fabricate(:group)
xhr :delete, :destroy, id: group.id
response.status.should == 200
Group.where(id: group.id).count.should == 0
expect(response.status).to eq(200)
expect(Group.where(id: group.id).count).to eq(0)
end
end
@@ -83,7 +83,7 @@ describe Admin::GroupsController do
Group.expects(:refresh_automatic_groups!).returns(true)
xhr :post, :refresh_automatic_groups
response.status.should == 200
expect(response.status).to eq(200)
end
end
@@ -92,7 +92,7 @@ describe Admin::GroupsController do
it "cannot add members to automatic groups" do
xhr :put, :add_members, group_id: 1, usernames: "l77t"
response.status.should == 422
expect(response.status).to eq(422)
end
it "is able to add several members to a group" do
@@ -102,9 +102,9 @@ describe Admin::GroupsController do
xhr :put, :add_members, group_id: group.id, usernames: [user1.username, user2.username].join(",")
response.should be_success
expect(response).to be_success
group.reload
group.users.count.should == 2
expect(group.users.count).to eq(2)
end
end
@@ -113,7 +113,7 @@ describe Admin::GroupsController do
it "cannot remove members from automatic groups" do
xhr :put, :remove_member, group_id: 1, user_id: 42
response.status.should == 422
expect(response.status).to eq(422)
end
it "is able to remove a member" do
@@ -124,9 +124,9 @@ describe Admin::GroupsController do
xhr :delete, :remove_member, group_id: group.id, user_id: user.id
response.should be_success
expect(response).to be_success
group.reload
group.users.count.should == 0
expect(group.users.count).to eq(0)
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ImpersonateController do
it "is a subclass of AdminController" do
(Admin::ImpersonateController < Admin::AdminController).should == true
expect(Admin::ImpersonateController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -13,25 +13,25 @@ describe Admin::ImpersonateController do
context 'index' do
it 'returns success' do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
end
context 'create' do
it 'requires a username_or_email parameter' do
-> { xhr :put, :create }.should raise_error(ActionController::ParameterMissing)
expect { xhr :put, :create }.to raise_error(ActionController::ParameterMissing)
end
it 'returns 404 when that user does not exist' do
xhr :post, :create, username_or_email: 'hedonismbot'
response.status.should == 404
expect(response.status).to eq(404)
end
it "raises an invalid access error if the user can't be impersonated" do
Guardian.any_instance.expects(:can_impersonate?).with(user).returns(false)
xhr :post, :create, username_or_email: user.email
response.should be_forbidden
expect(response).to be_forbidden
end
context 'success' do
@@ -43,17 +43,17 @@ describe Admin::ImpersonateController do
it "changes the current user session id" do
xhr :post, :create, username_or_email: user.username
session[:current_user_id].should == user.id
expect(session[:current_user_id]).to eq(user.id)
end
it "returns success" do
xhr :post, :create, username_or_email: user.email
response.should be_success
expect(response).to be_success
end
it "also works with an email address" do
xhr :post, :create, username_or_email: user.email
session[:current_user_id].should == user.id
expect(session[:current_user_id]).to eq(user.id)
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ReportsController do
it "is a subclass of AdminController" do
(Admin::ReportsController < Admin::AdminController).should == true
expect(Admin::ReportsController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -23,7 +23,7 @@ describe Admin::ReportsController do
it "returns 404" do
xhr :get, :show, type: invalid_id
response.status.should == 404
expect(response.status).to eq(404)
end
end
@@ -36,7 +36,7 @@ describe Admin::ReportsController do
end
it "renders the report as JSON" do
response.status.should == 404
expect(response.status).to eq(404)
end
end
@@ -47,11 +47,11 @@ describe Admin::ReportsController do
end
it "renders the report as JSON" do
response.should be_success
expect(response).to be_success
end
it "renders the report as JSON" do
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ScreenedEmailsController do
it "is a subclass of AdminController" do
(Admin::ScreenedEmailsController < Admin::AdminController).should == true
expect(Admin::ScreenedEmailsController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -13,10 +13,10 @@ describe Admin::ScreenedEmailsController do
end
subject { response }
it { should be_success }
it { is_expected.to be_success }
it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array)
expect(::JSON.parse(subject.body)).to be_a(Array)
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ScreenedIpAddressesController do
it "is a subclass of AdminController" do
(Admin::ScreenedIpAddressesController < Admin::AdminController).should == true
expect(Admin::ScreenedIpAddressesController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -12,8 +12,8 @@ describe Admin::ScreenedIpAddressesController do
it 'returns JSON' do
xhr :get, :index
response.should be_success
JSON.parse(response.body).should be_a(Array)
expect(response).to be_success
expect(JSON.parse(response.body)).to be_a(Array)
end
end
@@ -32,11 +32,11 @@ describe Admin::ScreenedIpAddressesController do
SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(3)
xhr :post, :roll_up
response.should be_success
expect(response).to be_success
subnet = ScreenedIpAddress.where(ip_address: "1.2.3.0/24").first
subnet.should be_present
subnet.match_count.should == 3
expect(subnet).to be_present
expect(subnet.match_count).to eq(3)
end
it "rolls up 1.2.*.* entries" do
@@ -52,11 +52,11 @@ describe Admin::ScreenedIpAddressesController do
SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(5)
xhr :post, :roll_up
response.should be_success
expect(response).to be_success
subnet = ScreenedIpAddress.where(ip_address: "1.2.0.0/16").first
subnet.should be_present
subnet.match_count.should == 6
expect(subnet).to be_present
expect(subnet.match_count).to eq(6)
end
end
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::ScreenedUrlsController do
it "is a subclass of AdminController" do
(Admin::ScreenedUrlsController < Admin::AdminController).should == true
expect(Admin::ScreenedUrlsController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -13,10 +13,10 @@ describe Admin::ScreenedUrlsController do
end
subject { response }
it { should be_success }
it { is_expected.to be_success }
it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array)
expect(::JSON.parse(subject.body)).to be_a(Array)
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteCustomizationsController do
it "is a subclass of AdminController" do
(Admin::UsersController < Admin::AdminController).should == true
expect(Admin::UsersController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -15,24 +15,24 @@ describe Admin::SiteCustomizationsController do
it 'returns success' do
SiteCustomization.create!(name: 'my name', user_id: Fabricate(:user).id, header: "my awesome header", stylesheet: "my awesome css")
xhr :get, :index
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
context ' .create' do
it 'returns success' do
xhr :post, :create, site_customization: {name: 'my test name'}
response.should be_success
expect(response).to be_success
end
it 'returns json' do
xhr :post, :create, site_customization: {name: 'my test name'}
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
it 'logs the change' do
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteSettingsController do
it "is a subclass of AdminController" do
(Admin::SiteSettingsController < Admin::AdminController).should == true
expect(Admin::SiteSettingsController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -14,12 +14,12 @@ describe Admin::SiteSettingsController do
context 'index' do
it 'returns success' do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteTextController do
it "is a subclass of AdminController" do
(Admin::SiteTextController < Admin::AdminController).should == true
expect(Admin::SiteTextController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -16,12 +16,12 @@ describe Admin::SiteTextController do
it 'returns success' do
xhr :get, :show, id: text_type
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :show, id: text_type
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::SiteTextTypesController do
it "is a subclass of AdminController" do
(Admin::SiteTextTypesController < Admin::AdminController).should == true
expect(Admin::SiteTextTypesController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -14,12 +14,12 @@ describe Admin::SiteTextTypesController do
context ' .index' do
it 'returns success' do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
end
end
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Admin::StaffActionLogsController do
it "is a subclass of AdminController" do
(Admin::StaffActionLogsController < Admin::AdminController).should == true
expect(Admin::StaffActionLogsController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
@@ -13,10 +13,10 @@ describe Admin::StaffActionLogsController do
end
subject { response }
it { should be_success }
it { is_expected.to be_success }
it 'returns JSON' do
::JSON.parse(subject.body).should be_a(Array)
expect(::JSON.parse(subject.body)).to be_a(Array)
end
end
end
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::UserFieldsController do
it "is a subclass of AdminController" do
(Admin::UserFieldsController < Admin::AdminController).should == true
expect(Admin::UserFieldsController < Admin::AdminController).to eq(true)
end
context "when logged in" do
@@ -11,10 +11,10 @@ describe Admin::UserFieldsController do
context '.create' do
it "creates a user field" do
-> {
expect {
xhr :post, :create, {user_field: {name: 'hello', description: 'hello desc', field_type: 'text'} }
response.should be_success
}.should change(UserField, :count).by(1)
expect(response).to be_success
}.to change(UserField, :count).by(1)
end
end
@@ -23,9 +23,9 @@ describe Admin::UserFieldsController do
it "returns a list of user fields" do
xhr :get, :index
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['user_fields'].should be_present
expect(json['user_fields']).to be_present
end
end
@@ -33,10 +33,10 @@ describe Admin::UserFieldsController do
let!(:user_field) { Fabricate(:user_field) }
it "deletes the user field" do
-> {
expect {
xhr :delete, :destroy, id: user_field.id
response.should be_success
}.should change(UserField, :count).by(-1)
expect(response).to be_success
}.to change(UserField, :count).by(-1)
end
end
@@ -45,10 +45,10 @@ describe Admin::UserFieldsController do
it "updates the user field" do
xhr :put, :update, id: user_field.id, user_field: {name: 'fraggle', field_type: 'confirm', description: 'muppet'}
response.should be_success
expect(response).to be_success
user_field.reload
user_field.name.should == 'fraggle'
user_field.field_type.should == 'confirm'
expect(user_field.name).to eq('fraggle')
expect(user_field.field_type).to eq('confirm')
end
end
end
+60 -60
View File
@@ -4,7 +4,7 @@ require_dependency 'single_sign_on'
describe Admin::UsersController do
it 'is a subclass of AdminController' do
(Admin::UsersController < Admin::AdminController).should == true
expect(Admin::UsersController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -15,12 +15,12 @@ describe Admin::UsersController do
context '.index' do
it 'returns success' do
xhr :get, :index
response.should be_success
expect(response).to be_success
end
it 'returns JSON' do
xhr :get, :index
::JSON.parse(response.body).should be_present
expect(::JSON.parse(response.body)).to be_present
end
context 'when showing emails' do
@@ -29,17 +29,17 @@ describe Admin::UsersController do
xhr :get, :index, show_emails: "true"
data = ::JSON.parse(response.body)
data.each do |user|
user["email"].should be_present
expect(user["email"]).to be_present
end
end
it "logs only 1 enty" do
UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 0
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(0)
xhr :get, :index, show_emails: "true"
data = ::JSON.parse(response.body)
UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 1
expect(UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count).to eq(1)
end
end
@@ -49,14 +49,14 @@ describe Admin::UsersController do
context 'an existing user' do
it 'returns success' do
xhr :get, :show, id: @user.username
response.should be_success
expect(response).to be_success
end
end
context 'an existing user' do
it 'returns success' do
xhr :get, :show, id: 'foobar'
response.should_not be_success
expect(response).not_to be_success
end
end
end
@@ -111,7 +111,7 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_approve?).with(evil_trout).returns(false)
xhr :put, :approve, user_id: evil_trout.id
response.should be_forbidden
expect(response).to be_forbidden
end
it 'calls approve' do
@@ -129,13 +129,13 @@ describe Admin::UsersController do
it 'raises an error unless the user can revoke access' do
Guardian.any_instance.expects(:can_revoke_admin?).with(@another_admin).returns(false)
xhr :put, :revoke_admin, user_id: @another_admin.id
response.should be_forbidden
expect(response).to be_forbidden
end
it 'updates the admin flag' do
xhr :put, :revoke_admin, user_id: @another_admin.id
@another_admin.reload
@another_admin.should_not be_admin
expect(@another_admin).not_to be_admin
end
end
@@ -147,18 +147,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_grant_admin?).with(@another_user).returns(false)
xhr :put, :grant_admin, user_id: @another_user.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_admin, user_id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
it 'updates the admin flag' do
xhr :put, :grant_admin, user_id: @another_user.id
@another_user.reload
@another_user.should be_admin
expect(@another_user).to be_admin
end
end
@@ -170,18 +170,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_change_primary_group?).with(@another_user).returns(false)
xhr :put, :primary_group, user_id: @another_user.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 404 if the user doesn't exist" do
xhr :put, :primary_group, user_id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
it "changes the user's primary group" do
xhr :put, :primary_group, user_id: @another_user.id, primary_group_id: 2
@another_user.reload
@another_user.primary_group_id.should == 2
expect(@another_user.primary_group_id).to eq(2)
end
end
@@ -193,20 +193,20 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_change_trust_level?).with(@another_user).returns(false)
xhr :put, :trust_level, user_id: @another_user.id
response.should_not be_success
expect(response).not_to be_success
end
it "returns a 404 if the username doesn't exist" do
xhr :put, :trust_level, user_id: 123123
response.should_not be_success
expect(response).not_to be_success
end
it "upgrades the user's trust level" do
StaffActionLogger.any_instance.expects(:log_trust_level_change).with(@another_user, @another_user.trust_level, 2).once
xhr :put, :trust_level, user_id: @another_user.id, level: 2
@another_user.reload
@another_user.trust_level.should == 2
response.should be_success
expect(@another_user.trust_level).to eq(2)
expect(response).to be_success
end
it "raises no error when demoting a user below their current trust level (locks trust level)" do
@@ -217,9 +217,9 @@ describe Admin::UsersController do
stat.save!
@another_user.update_attributes(trust_level: TrustLevel[1])
xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel[0]
response.should be_success
expect(response).to be_success
@another_user.reload
@another_user.trust_level_locked.should == true
expect(@another_user.trust_level_locked).to eq(true)
end
end
@@ -231,13 +231,13 @@ describe Admin::UsersController do
it 'raises an error unless the user can revoke access' do
Guardian.any_instance.expects(:can_revoke_moderation?).with(@moderator).returns(false)
xhr :put, :revoke_moderation, user_id: @moderator.id
response.should be_forbidden
expect(response).to be_forbidden
end
it 'updates the moderator flag' do
xhr :put, :revoke_moderation, user_id: @moderator.id
@moderator.reload
@moderator.moderator.should_not == true
expect(@moderator.moderator).not_to eq(true)
end
end
@@ -249,18 +249,18 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_grant_moderation?).with(@another_user).returns(false)
xhr :put, :grant_moderation, user_id: @another_user.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 404 if the username doesn't exist" do
xhr :put, :grant_moderation, user_id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
it 'updates the moderator flag' do
xhr :put, :grant_moderation, user_id: @another_user.id
@another_user.reload
@another_user.moderator.should == true
expect(@another_user.moderator).to eq(true)
end
end
@@ -283,10 +283,10 @@ describe Admin::UsersController do
Guardian.any_instance.stubs(:can_delete_user?).returns(true)
UserDestroyer.any_instance.stubs(:destroy).returns(true)
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['success'].to_i.should == 2
json['failed'].to_i.should == 0
expect(json['success'].to_i).to eq(2)
expect(json['failed'].to_i).to eq(0)
end
context 'failures' do
@@ -298,19 +298,19 @@ describe Admin::UsersController do
UserDestroyer.any_instance.stubs(:destroy).with(reject_me, anything).returns(false)
UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true)
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['success'].to_i.should == 1
json['failed'].to_i.should == 1
expect(json['success'].to_i).to eq(1)
expect(json['failed'].to_i).to eq(1)
end
it 'reports failure due to a user still having posts' do
UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError)
xhr :delete, :reject_bulk, users: [reject_me.id]
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['success'].to_i.should == 0
json['failed'].to_i.should == 1
expect(json['success'].to_i).to eq(0)
expect(json['failed'].to_i).to eq(1)
end
end
end
@@ -323,12 +323,12 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_delete_user?).with(@delete_me).returns(false)
xhr :delete, :destroy, id: @delete_me.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 403 if the user doesn't exist" do
xhr :delete, :destroy, id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
context "user has post" do
@@ -343,13 +343,13 @@ describe Admin::UsersController do
it "returns an error" do
xhr :delete, :destroy, id: @delete_me.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "doesn't return an error if delete_posts == true" do
UserDestroyer.any_instance.expects(:destroy).with(@user, has_entry('delete_posts' => true)).returns(true)
xhr :delete, :destroy, id: @delete_me.id, delete_posts: true
response.should be_success
expect(response).to be_success
end
end
@@ -367,9 +367,9 @@ describe Admin::UsersController do
it "returns success" do
xhr :put, :activate, user_id: @reg_user.id
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['success'].should == "OK"
expect(json['success']).to eq("OK")
end
end
@@ -380,14 +380,14 @@ describe Admin::UsersController do
it "returns success" do
xhr :put, :log_out, user_id: @reg_user.id
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json['success'].should == "OK"
expect(json['success']).to eq("OK")
end
it "returns 404 when user_id does not exist" do
xhr :put, :log_out, user_id: 123123
response.should_not be_success
expect(response).not_to be_success
end
end
@@ -400,12 +400,12 @@ describe Admin::UsersController do
Guardian.any_instance.expects(:can_block_user?).with(@reg_user).returns(false)
UserBlocker.expects(:block).never
xhr :put, :block, user_id: @reg_user.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 403 if the user doesn't exist" do
xhr :put, :block, user_id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
it "punishes the user for spamming" do
@@ -422,12 +422,12 @@ describe Admin::UsersController do
it "raises an error when the user doesn't have permission" do
Guardian.any_instance.expects(:can_unblock_user?).with(@reg_user).returns(false)
xhr :put, :unblock, user_id: @reg_user.id
response.should be_forbidden
expect(response).to be_forbidden
end
it "returns a 403 if the user doesn't exist" do
xhr :put, :unblock, user_id: 123123
response.should be_forbidden
expect(response).to be_forbidden
end
it "punishes the user for spamming" do
@@ -462,20 +462,20 @@ describe Admin::UsersController do
it 'should invite admin' do
Jobs.expects(:enqueue).with(:user_email, anything).returns(true)
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
response.should be_success
expect(response).to be_success
u = User.find_by(email: 'bill@bill.com')
u.name.should == "Bill"
u.username.should == "bill22"
u.admin.should == true
expect(u.name).to eq("Bill")
expect(u.username).to eq("bill22")
expect(u.admin).to eq(true)
end
it "doesn't send the email with send_email falsy" do
Jobs.expects(:enqueue).with(:user_email, anything).never
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0'
response.should be_success
expect(response).to be_success
json = ::JSON.parse(response.body)
json["password_url"].should be_present
expect(json["password_url"]).to be_present
end
end
@@ -507,12 +507,12 @@ describe Admin::UsersController do
sso.email = "bob2@bob.com"
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
response.should be_success
expect(response).to be_success
user.reload
user.email.should == "bob2@bob.com"
user.name.should == "Bill"
user.username.should == "Hokli"
expect(user.email).to eq("bob2@bob.com")
expect(user.name).to eq("Bill")
expect(user.username).to eq("Hokli")
end
@@ -11,7 +11,7 @@ describe Admin::VersionsController do
end
it "is a subclass of AdminController" do
(Admin::VersionsController < Admin::AdminController).should == true
expect(Admin::VersionsController < Admin::AdminController).to eq(true)
end
context 'while logged in as an admin' do
@@ -21,16 +21,16 @@ describe Admin::VersionsController do
describe 'show' do
subject { xhr :get, :show }
it { should be_success }
it { is_expected.to be_success }
it 'should return the currently available version' do
json = JSON.parse(subject.body)
json['latest_version'].should == '1.2.33'
expect(json['latest_version']).to eq('1.2.33')
end
it "should return the installed version" do
json = JSON.parse(subject.body)
json['installed_version'].should == Discourse::VERSION::STRING
expect(json['installed_version']).to eq(Discourse::VERSION::STRING)
end
end
end