mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 15:04:59 +08:00
REFACTOR: category hashtags controller specs to requests (#5936)
This commit is contained in:
parent
9975f9751e
commit
30be1b0d2b
|
@ -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
|
Loading…
Reference in New Issue
Block a user