mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Convert specs to RSpec 2.99.2 syntax with Transpec
This conversion is done by Transpec 3.1.0 with the following command: transpec * 424 conversions from: obj.should to: expect(obj).to * 325 conversions from: == expected to: eq(expected) * 38 conversions from: obj.should_not to: expect(obj).not_to * 15 conversions from: =~ /pattern/ to: match(/pattern/) * 9 conversions from: it { should ... } to: it { is_expected.to ... } * 5 conversions from: lambda { }.should_not to: expect { }.not_to * 4 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: -> { }.should to: expect { }.to * 2 conversions from: -> { }.should_not to: expect { }.not_to * 1 conversion from: === expected to: be === expected * 1 conversion from: =~ [1, 2] to: match_array([1, 2]) For more details: https://github.com/yujinakayama/transpec#supported-conversions
This commit is contained in:
@ -11,8 +11,8 @@ describe Admin::PluginsController do
|
||||
|
||||
it 'should return JSON' do
|
||||
xhr :get, :index
|
||||
response.should be_success
|
||||
::JSON.parse(response.body).has_key?('plugins').should == true
|
||||
expect(response).to be_success
|
||||
expect(::JSON.parse(response.body).has_key?('plugins')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3,12 +3,12 @@ require 'spec_helper'
|
||||
describe DirectoryItemsController do
|
||||
|
||||
it "requires a `period` param" do
|
||||
->{ xhr :get, :index }.should raise_error
|
||||
expect{ xhr :get, :index }.to raise_error
|
||||
end
|
||||
|
||||
it "requires a proper `period` param" do
|
||||
xhr :get, :index, period: 'eviltrout'
|
||||
response.should_not be_success
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ describe DirectoryItemsController do
|
||||
|
||||
it "succeeds" do
|
||||
xhr :get, :index, period: 'all'
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
end
|
||||
end
|
||||
@ -35,20 +35,20 @@ describe DirectoryItemsController do
|
||||
|
||||
it "succeeds with a valid value" do
|
||||
xhr :get, :index, period: 'all'
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
|
||||
json.should be_present
|
||||
json['directory_items'].should be_present
|
||||
json['total_rows_directory_items'].should be_present
|
||||
json['load_more_directory_items'].should be_present
|
||||
expect(json).to be_present
|
||||
expect(json['directory_items']).to be_present
|
||||
expect(json['total_rows_directory_items']).to be_present
|
||||
expect(json['load_more_directory_items']).to be_present
|
||||
end
|
||||
|
||||
it "fails when the directory is disabled" do
|
||||
SiteSetting.enable_user_directory = false
|
||||
|
||||
xhr :get, :index, period: 'all'
|
||||
response.should_not be_success
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -91,10 +91,10 @@ describe GroupsController do
|
||||
Guardian.any_instance.stubs(:can_edit?).with(group).returns(false)
|
||||
|
||||
xhr :put, :add_members, group_id: group.name, usernames: "bob"
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
|
||||
xhr :delete, :remove_member, group_id: group.name, username: "bob"
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "cannot add members to automatic groups" do
|
||||
@ -102,7 +102,7 @@ describe GroupsController do
|
||||
auto_group = Fabricate(:group, name: "auto_group", automatic: true)
|
||||
|
||||
xhr :put, :add_members, group_id: group.name, usernames: "bob"
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
@ -119,42 +119,42 @@ describe GroupsController do
|
||||
user2 = Fabricate(:user)
|
||||
xhr :put, :add_members, group_id: group.name, usernames: user2.username
|
||||
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
group.users.count.should eq(2)
|
||||
expect(group.users.count).to eq(2)
|
||||
end
|
||||
|
||||
it "succeeds silently when adding non-existent users" do
|
||||
xhr :put, :add_members, group_id: group.name, usernames: "nosuchperson"
|
||||
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
group.users.count.should eq(1)
|
||||
expect(group.users.count).to eq(1)
|
||||
end
|
||||
|
||||
it "succeeds silently when adding duplicate users" do
|
||||
xhr :put, :add_members, group_id: group.name, usernames: @user1.username
|
||||
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
group.users.should eq([@user1])
|
||||
expect(group.users).to eq([@user1])
|
||||
end
|
||||
|
||||
it "can make incremental deletes" do
|
||||
xhr :delete, :remove_member, group_id: group.name, username: @user1.username
|
||||
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
group.users.count.should eq(0)
|
||||
expect(group.users.count).to eq(0)
|
||||
end
|
||||
|
||||
it "succeeds silently when removing non-members" do
|
||||
user2 = Fabricate(:user)
|
||||
xhr :delete, :remove_member, group_id: group.name, username: user2.username
|
||||
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
group.reload
|
||||
group.users.count.should eq(1)
|
||||
expect(group.users.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -851,8 +851,8 @@ describe PostsController do
|
||||
it "can be viewed by anonymous" do
|
||||
post = Fabricate(:post, raw: "123456789")
|
||||
xhr :get, :markdown_id, id: post.id
|
||||
response.should be_success
|
||||
response.body.should == "123456789"
|
||||
expect(response).to be_success
|
||||
expect(response.body).to eq("123456789")
|
||||
end
|
||||
end
|
||||
|
||||
@ -862,8 +862,8 @@ describe PostsController do
|
||||
post = Fabricate(:post, topic: topic, post_number: 1, raw: "123456789")
|
||||
post.save
|
||||
xhr :get, :markdown_num, topic_id: topic.id, post_number: 1
|
||||
response.should be_success
|
||||
response.body.should == "123456789"
|
||||
expect(response).to be_success
|
||||
expect(response.body).to eq("123456789")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -874,13 +874,13 @@ describe PostsController do
|
||||
|
||||
it "redirects to the topic" do
|
||||
xhr :get, :short_link, post_id: post.id
|
||||
response.should be_redirect
|
||||
expect(response).to be_redirect
|
||||
end
|
||||
|
||||
it "returns a 403 when access is denied" do
|
||||
Guardian.any_instance.stubs(:can_see?).returns(false)
|
||||
xhr :get, :short_link, post_id: post.id
|
||||
response.should be_forbidden
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -967,10 +967,10 @@ describe TopicsController do
|
||||
PostAction.act(user, post2, bookmark)
|
||||
|
||||
xhr :put, :bookmark, topic_id: post.topic_id
|
||||
PostAction.where(user_id: user.id, post_action_type: bookmark).count.should == 2
|
||||
expect(PostAction.where(user_id: user.id, post_action_type: bookmark).count).to eq(2)
|
||||
|
||||
xhr :put, :remove_bookmarks, topic_id: post.topic_id
|
||||
PostAction.where(user_id: user.id, post_action_type: bookmark).count.should == 0
|
||||
expect(PostAction.where(user_id: user.id, post_action_type: bookmark).count).to eq(0)
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -674,48 +674,48 @@ describe UsersController do
|
||||
|
||||
it 'raises an error without a new_username param' do
|
||||
expect { xhr :put, :username, username: user.username }.to raise_error(ActionController::ParameterMissing)
|
||||
user.reload.username.should == old_username
|
||||
expect(user.reload.username).to eq(old_username)
|
||||
end
|
||||
|
||||
it 'raises an error when you don\'t have permission to change the username' do
|
||||
Guardian.any_instance.expects(:can_edit_username?).with(user).returns(false)
|
||||
xhr :put, :username, username: user.username, new_username: new_username
|
||||
expect(response).to be_forbidden
|
||||
user.reload.username.should == old_username
|
||||
expect(user.reload.username).to eq(old_username)
|
||||
end
|
||||
|
||||
# Bad behavior, this should give a real JSON error, not an InvalidParameters
|
||||
it 'raises an error when change_username fails' do
|
||||
User.any_instance.expects(:save).returns(false)
|
||||
expect { xhr :put, :username, username: user.username, new_username: new_username }.to raise_error(Discourse::InvalidParameters)
|
||||
user.reload.username.should == old_username
|
||||
expect(user.reload.username).to eq(old_username)
|
||||
end
|
||||
|
||||
it 'should succeed in normal circumstances' do
|
||||
xhr :put, :username, username: user.username, new_username: new_username
|
||||
response.should be_success
|
||||
user.reload.username.should == new_username
|
||||
expect(response).to be_success
|
||||
expect(user.reload.username).to eq(new_username)
|
||||
end
|
||||
|
||||
skip 'should fail if the user is old', 'ensure_can_edit_username! is not throwing' do
|
||||
# Older than the change period and >1 post
|
||||
user.created_at = Time.now - (SiteSetting.username_change_period + 1).days
|
||||
user.stubs(:post_count).returns(200)
|
||||
Guardian.new(user).can_edit_username?(user).should == false
|
||||
expect(Guardian.new(user).can_edit_username?(user)).to eq(false)
|
||||
|
||||
xhr :put, :username, username: user.username, new_username: new_username
|
||||
|
||||
response.should be_forbidden
|
||||
user.reload.username.should == old_username
|
||||
expect(response).to be_forbidden
|
||||
expect(user.reload.username).to eq(old_username)
|
||||
end
|
||||
|
||||
it 'should create a staff action log when a staff member changes the username' do
|
||||
acting_user = Fabricate(:admin)
|
||||
log_in_user(acting_user)
|
||||
xhr :put, :username, username: user.username, new_username: new_username
|
||||
response.should be_success
|
||||
UserHistory.where(action: UserHistory.actions[:change_username], target_user_id: user.id, acting_user_id: acting_user.id).should be_present
|
||||
user.reload.username.should == new_username
|
||||
expect(response).to be_success
|
||||
expect(UserHistory.where(action: UserHistory.actions[:change_username], target_user_id: user.id, acting_user_id: acting_user.id)).to be_present
|
||||
expect(user.reload.username).to eq(new_username)
|
||||
end
|
||||
|
||||
it 'should return a JSON response with the updated username' do
|
||||
|
Reference in New Issue
Block a user