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

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