REFACTOR: category hashtags controller specs to requests (#5936)

This commit is contained in:
OsamaSayegh 2018-06-07 08:09:23 +03:00 committed by Guo Xiang Tan
parent 9975f9751e
commit 30be1b0d2b

View File

@ -4,14 +4,15 @@ describe CategoryHashtagsController do
describe "check" do
describe "logged in" do
before do
log_in(:user)
sign_in(Fabricate(:user))
end
it 'only returns the categories that are valid' do
category = Fabricate(:category)
get :check, params: { category_slugs: [category.slug, 'none'] }, format: :json
get "/category_hashtags/check.json", params: { category_slugs: [category.slug, 'none'] }
expect(response.status).to eq(200)
expect(JSON.parse(response.body)).to eq(
"valid" => [{ "slug" => category.hashtag_slug, "url" => category.url_with_id }]
)
@ -21,21 +22,22 @@ describe CategoryHashtagsController do
group = Fabricate(:group)
private_category = Fabricate(:private_category, group: group)
get :check, params: { category_slugs: [private_category.slug] }, format: :json
get "/category_hashtags/check.json", params: { category_slugs: [private_category.slug] }
expect(response.status).to eq(200)
expect(JSON.parse(response.body)).to eq("valid" => [])
end
it 'returns restricted categories for an admin' do
admin = log_in(:admin)
admin = sign_in(Fabricate(:admin))
group = Fabricate(:group)
group.add(admin)
private_category = Fabricate(:private_category, group: group)
get :check,
params: { category_slugs: [private_category.slug] },
format: :json
get "/category_hashtags/check.json",
params: { category_slugs: [private_category.slug] }
expect(response.status).to eq(200)
expect(JSON.parse(response.body)).to eq(
"valid" => [{ "slug" => private_category.hashtag_slug, "url" => private_category.url_with_id }]
)
@ -44,7 +46,7 @@ describe CategoryHashtagsController do
describe "not logged in" do
it 'raises an exception' do
get :check, params: { category_slugs: [] }, format: :json
get "/category_hashtags/check.json", params: { category_slugs: [] }
expect(response.status).to eq(403)
end
end