Move new controller specs to reqeusts folder.
This commit is contained in:
parent
68b8acbcfa
commit
8779490ce4
|
@ -1,116 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Managing a topic's status update", type: :request do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
context 'when a user is not logged in' do
|
||||
it 'should return the right response' do
|
||||
expect do
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: '24',
|
||||
status_type: TopicTimer.types[1]
|
||||
end.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when does not have permission' do
|
||||
it 'should return the right response' do
|
||||
sign_in(user)
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: '24',
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
expect(JSON.parse(response.body)["error_type"]).to eq('invalid_access')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when logged in as an admin' do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it 'should be able to create a topic status update' do
|
||||
time = 24
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 24,
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
topic_status_update = TopicTimer.last
|
||||
|
||||
expect(topic_status_update.topic).to eq(topic)
|
||||
|
||||
expect(topic_status_update.execute_at)
|
||||
.to be_within(1.second).of(24.hours.from_now)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(DateTime.parse(json['execute_at']))
|
||||
.to be_within(1.seconds).of(DateTime.parse(topic_status_update.execute_at.to_s))
|
||||
|
||||
expect(json['duration']).to eq(topic_status_update.duration)
|
||||
expect(json['closed']).to eq(topic.reload.closed)
|
||||
end
|
||||
|
||||
it 'should be able to delete a topic status update' do
|
||||
Fabricate(:topic_timer, topic: topic)
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: nil,
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response).to be_success
|
||||
expect(topic.reload.public_topic_timer).to eq(nil)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json['execute_at']).to eq(nil)
|
||||
expect(json['duration']).to eq(nil)
|
||||
expect(json['closed']).to eq(topic.closed)
|
||||
end
|
||||
|
||||
describe 'publishing topic to category in the future' do
|
||||
it 'should be able to create the topic status update' do
|
||||
SiteSetting.queue_jobs = true
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 24,
|
||||
status_type: TopicTimer.types[3],
|
||||
category_id: topic.category_id
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
topic_status_update = TopicTimer.last
|
||||
|
||||
expect(topic_status_update.topic).to eq(topic)
|
||||
|
||||
expect(topic_status_update.execute_at)
|
||||
.to be_within(1.second).of(24.hours.from_now)
|
||||
|
||||
expect(topic_status_update.status_type)
|
||||
.to eq(TopicTimer.types[:publish_to_category])
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json['category_id']).to eq(topic.category_id)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'invalid status type' do
|
||||
it 'should raise the right error' do
|
||||
expect do
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 10,
|
||||
status_type: 'something'
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Admin::AdminController" do
|
||||
RSpec.describe Admin::AdminController do
|
||||
it "should return the right response if user isn't a staff" do
|
||||
expect do
|
||||
get "/admin", api_key: 'asdiasiduga'
|
|
@ -1,13 +1,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Managing Backups" do
|
||||
RSpec.describe Admin::BackupsController do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
describe 'rolling back a restore' do
|
||||
describe '#rollback' do
|
||||
it 'should rollback the restore' do
|
||||
BackupRestore.expects(:rollback!)
|
||||
|
||||
|
@ -22,7 +22,7 @@ RSpec.describe "Managing Backups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'cancelling a backup' do
|
||||
describe '#cancel' do
|
||||
it "should cancel an backup" do
|
||||
BackupRestore.expects(:cancel!)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Managing custom emojis" do
|
||||
RSpec.describe Admin::EmojisController do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:upload) { Fabricate(:upload) }
|
||||
|
||||
|
@ -8,12 +8,14 @@ RSpec.describe "Managing custom emojis" do
|
|||
sign_in(admin)
|
||||
end
|
||||
|
||||
describe "creating a custom emoji" do
|
||||
describe "#create" do
|
||||
describe 'when upload is invalid' do
|
||||
it 'should publish the right error' do
|
||||
message = MessageBus.track_publish do
|
||||
post("/admin/customize/emojis.json", name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/fake.jpg"))
|
||||
post("/admin/customize/emojis.json",
|
||||
name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/fake.jpg")
|
||||
)
|
||||
end.find { |m| m.channel == "/uploads/emoji" }
|
||||
|
||||
expect(message.channel).to eq("/uploads/emoji")
|
||||
|
@ -26,8 +28,10 @@ RSpec.describe "Managing custom emojis" do
|
|||
CustomEmoji.create!(name: 'test', upload: upload)
|
||||
|
||||
message = MessageBus.track_publish do
|
||||
post("/admin/customize/emojis.json", name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png"))
|
||||
post("/admin/customize/emojis.json",
|
||||
name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
||||
)
|
||||
end.find { |m| m.channel == "/uploads/emoji" }
|
||||
|
||||
expect(message.channel).to eq("/uploads/emoji")
|
||||
|
@ -42,8 +46,10 @@ RSpec.describe "Managing custom emojis" do
|
|||
Emoji.expects(:clear_cache)
|
||||
|
||||
message = MessageBus.track_publish do
|
||||
post("/admin/customize/emojis.json", name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png"))
|
||||
post("/admin/customize/emojis.json",
|
||||
name: 'test',
|
||||
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
||||
)
|
||||
end.find { |m| m.channel == "/uploads/emoji" }
|
||||
|
||||
custom_emoji = CustomEmoji.last
|
||||
|
@ -57,7 +63,7 @@ RSpec.describe "Managing custom emojis" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'deleting a custom emoji' do
|
||||
describe '#destroy' do
|
||||
it 'should allow an admin to delete a custom emoji' do
|
||||
custom_emoji = CustomEmoji.create!(name: 'test', upload: upload)
|
||||
Emoji.clear_cache
|
|
@ -1,15 +1,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Managing flags as an admin" do
|
||||
RSpec.describe Admin::FlagsController do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:post_1) { Fabricate(:post) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
context 'viewing flags' do
|
||||
context '#index' do
|
||||
it 'should return the right response when nothing is flagged' do
|
||||
get '/admin/flags.json'
|
||||
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe "Managing flags as an admin" do
|
|||
end
|
||||
|
||||
it 'should return the right response' do
|
||||
PostAction.act(user, post, PostActionType.types[:spam])
|
||||
PostAction.act(user, post_1, PostActionType.types[:spam])
|
||||
|
||||
get '/admin/flags.json'
|
||||
|
||||
|
@ -33,13 +33,13 @@ RSpec.describe "Managing flags as an admin" do
|
|||
end
|
||||
end
|
||||
|
||||
context 'agreeing with a flag' do
|
||||
context '#agree' do
|
||||
it 'should work' do
|
||||
SiteSetting.allow_user_locale = true
|
||||
post_action = PostAction.act(user, post, PostActionType.types[:spam], message: 'bad')
|
||||
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
||||
admin.update!(locale: 'ja')
|
||||
|
||||
xhr :post, "/admin/flags/agree/#{post.id}"
|
||||
post "/admin/flags/agree/#{post_1.id}.json"
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
|
@ -47,9 +47,9 @@ RSpec.describe "Managing flags as an admin" do
|
|||
|
||||
expect(post_action.agreed_by_id).to eq(admin.id)
|
||||
|
||||
post = Post.offset(1).last
|
||||
post_1 = Post.offset(1).last
|
||||
|
||||
expect(post.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') })
|
||||
expect(post_1.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') })
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Managing groups as an admin" do
|
||||
RSpec.describe Admin::GroupsController do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
@ -9,7 +9,7 @@ RSpec.describe "Managing groups as an admin" do
|
|||
sign_in(admin)
|
||||
end
|
||||
|
||||
describe 'creating a new group' do
|
||||
describe '#create' do
|
||||
it 'should work' do
|
||||
post "/admin/groups.json", group: {
|
||||
name: 'testing',
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe "Managing groups as an admin" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'adding a new owner' do
|
||||
describe '#add_owners' do
|
||||
it 'should work' do
|
||||
put "/admin/groups/#{group.id}/owners.json", group: {
|
||||
usernames: [user.username, admin.username].join(",")
|
|
@ -1,10 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe "Groups" do
|
||||
describe GroupsController do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group, users: [user]) }
|
||||
|
||||
describe 'viewing groups' do
|
||||
describe '#index' do
|
||||
let!(:staff_group) do
|
||||
Fabricate(:group, name: '0000', visibility_level: Group.visibility_levels[:staff])
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "checking if a group can be mentioned" do
|
||||
describe '#mentionable' do
|
||||
it "should return the right response" do
|
||||
sign_in(user)
|
||||
group.update_attributes!(name: 'test')
|
||||
|
@ -79,7 +79,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "group can be updated" do
|
||||
describe '#update' do
|
||||
let(:group) do
|
||||
Fabricate(:group,
|
||||
name: 'test',
|
||||
|
@ -103,7 +103,7 @@ describe "Groups" do
|
|||
group.update!(allow_membership_requests: false)
|
||||
|
||||
expect do
|
||||
xhr :put, "/groups/#{group.id}", group: {
|
||||
put "/groups/#{group.id}.json", group: {
|
||||
flair_bg_color: 'FFF',
|
||||
flair_color: 'BBB',
|
||||
flair_url: 'fa-adjust',
|
||||
|
@ -138,7 +138,7 @@ describe "Groups" do
|
|||
end
|
||||
|
||||
it 'should be able to update the group' do
|
||||
xhr :put, "/groups/#{group.id}", group: { flair_color: 'BBB' }
|
||||
put "/groups/#{group.id}.json", group: { flair_color: 'BBB' }
|
||||
|
||||
expect(response).to be_success
|
||||
expect(group.reload.flair_color).to eq('BBB')
|
||||
|
@ -149,14 +149,14 @@ describe "Groups" do
|
|||
it 'should not be able to update the group' do
|
||||
sign_in(user)
|
||||
|
||||
xhr :put, "/groups/#{group.id}", group: { name: 'testing' }
|
||||
put "/groups/#{group.id}.json", group: { name: 'testing' }
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'members' do
|
||||
describe '#members' do
|
||||
let(:user1) do
|
||||
Fabricate(:user,
|
||||
last_seen_at: Time.zone.now,
|
||||
|
@ -220,7 +220,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "membership edit permissions" do
|
||||
describe "edit" do
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
context 'when user is not signed in' do
|
||||
|
@ -287,7 +287,7 @@ describe "Groups" do
|
|||
sign_in(admin)
|
||||
end
|
||||
|
||||
context 'adding members' do
|
||||
context 'add_members' do
|
||||
it "can make incremental adds" do
|
||||
user2 = Fabricate(:user)
|
||||
|
||||
|
@ -394,7 +394,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
context 'removing members' do
|
||||
context '#remove_member' do
|
||||
it "cannot remove members from automatic groups" do
|
||||
group.update!(automatic: true)
|
||||
|
||||
|
@ -555,7 +555,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "requesting membership for a group" do
|
||||
describe '#request_membership' do
|
||||
let(:new_user) { Fabricate(:user) }
|
||||
|
||||
it 'requires the user to log in' do
|
||||
|
@ -602,7 +602,7 @@ describe "Groups" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'search for groups' do
|
||||
describe '#search ' do
|
||||
let(:hidden_group) do
|
||||
Fabricate(:group,
|
||||
visibility_level: Group.visibility_levels[:owners],
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "OmniAuth Callbacks" do
|
||||
RSpec.describe Users::OmniauthCallbacksController do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
|
@ -1,7 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Safe mode' do
|
||||
describe 'entering safe mode' do
|
||||
RSpec.describe SafeModeController do
|
||||
describe 'enter' do
|
||||
context 'when no params are given' do
|
||||
it 'should redirect back to safe mode page' do
|
||||
post '/safe-mode'
|
|
@ -1,11 +1,11 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe "Tags" do
|
||||
describe TagsController do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
|
||||
describe "checking tag hashtags" do
|
||||
describe '#check_hashtag' do
|
||||
let(:tag) { Fabricate(:tag, name: 'test') }
|
||||
|
||||
it "should return the right response" do
|
|
@ -0,0 +1,118 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TopicsController do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe '#timer' do
|
||||
context 'when a user is not logged in' do
|
||||
it 'should return the right response' do
|
||||
expect do
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: '24',
|
||||
status_type: TopicTimer.types[1]
|
||||
end.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when does not have permission' do
|
||||
it 'should return the right response' do
|
||||
sign_in(user)
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: '24',
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
expect(JSON.parse(response.body)["error_type"]).to eq('invalid_access')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when logged in as an admin' do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it 'should be able to create a topic status update' do
|
||||
time = 24
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 24,
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
topic_status_update = TopicTimer.last
|
||||
|
||||
expect(topic_status_update.topic).to eq(topic)
|
||||
|
||||
expect(topic_status_update.execute_at)
|
||||
.to be_within(1.second).of(24.hours.from_now)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(DateTime.parse(json['execute_at']))
|
||||
.to be_within(1.seconds).of(DateTime.parse(topic_status_update.execute_at.to_s))
|
||||
|
||||
expect(json['duration']).to eq(topic_status_update.duration)
|
||||
expect(json['closed']).to eq(topic.reload.closed)
|
||||
end
|
||||
|
||||
it 'should be able to delete a topic status update' do
|
||||
Fabricate(:topic_timer, topic: topic)
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: nil,
|
||||
status_type: TopicTimer.types[1]
|
||||
|
||||
expect(response).to be_success
|
||||
expect(topic.reload.public_topic_timer).to eq(nil)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json['execute_at']).to eq(nil)
|
||||
expect(json['duration']).to eq(nil)
|
||||
expect(json['closed']).to eq(topic.closed)
|
||||
end
|
||||
|
||||
describe 'publishing topic to category in the future' do
|
||||
it 'should be able to create the topic status update' do
|
||||
SiteSetting.queue_jobs = true
|
||||
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 24,
|
||||
status_type: TopicTimer.types[3],
|
||||
category_id: topic.category_id
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
topic_status_update = TopicTimer.last
|
||||
|
||||
expect(topic_status_update.topic).to eq(topic)
|
||||
|
||||
expect(topic_status_update.execute_at)
|
||||
.to be_within(1.second).of(24.hours.from_now)
|
||||
|
||||
expect(topic_status_update.status_type)
|
||||
.to eq(TopicTimer.types[:publish_to_category])
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json['category_id']).to eq(topic.category_id)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'invalid status type' do
|
||||
it 'should raise the right error' do
|
||||
expect do
|
||||
post "/t/#{topic.id}/timer.json",
|
||||
time: 10,
|
||||
status_type: 'something'
|
||||
end.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "Users" do
|
||||
RSpec.describe UsersController do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe "viewing a user" do
|
||||
describe '#show' do
|
||||
|
||||
it "should be able to view a user" do
|
||||
get "/u/#{user.username}"
|
Loading…
Reference in New Issue