Fix all the errors to get our tests green on Rails 5.1.

This commit is contained in:
Guo Xiang Tan
2017-08-31 12:06:56 +08:00
parent 898ee93547
commit 77d4c4d8dc
989 changed files with 5114 additions and 3117 deletions

View File

@ -97,7 +97,7 @@ after_initialize do
class Presence::PresencesController < ::ApplicationController
requires_plugin PLUGIN_NAME
before_filter :ensure_logged_in
before_action :ensure_logged_in
def publish
data = params.permit(:response_needed,

View File

@ -38,7 +38,11 @@ describe ::Presence::PresencesController, type: :request do
it "uses guardian to secure endpoint" do
# Private message
private_post = Fabricate(:private_message_post)
post '/presence/publish.json', current: { action: 'edit', post_id: private_post.id }
post '/presence/publish.json', params: {
current: { action: 'edit', post_id: private_post.id }
}
expect(response.code.to_i).to eq(403)
# Secure category
@ -46,13 +50,18 @@ describe ::Presence::PresencesController, type: :request do
category = Fabricate(:private_category, group: group)
private_topic = Fabricate(:topic, category: category)
post '/presence/publish.json', current: { action: 'edit', topic_id: private_topic.id }
post '/presence/publish.json', params: {
current: { action: 'edit', topic_id: private_topic.id }
}
expect(response.code.to_i).to eq(403)
end
it "returns a response when requested" do
messages = MessageBus.track_publish do
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post1.id }, response_needed: true
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post1.id }, response_needed: true
}
end
expect(messages.count).to eq (1)
@ -66,7 +75,9 @@ describe ::Presence::PresencesController, type: :request do
it "doesn't return a response when not requested" do
messages = MessageBus.track_publish do
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post1.id }
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post1.id }
}
end
expect(messages.count).to eq (1)
@ -77,21 +88,34 @@ describe ::Presence::PresencesController, type: :request do
it "doesn't send duplicate messagebus messages" do
messages = MessageBus.track_publish do
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post1.id }
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post1.id }
}
end
expect(messages.count).to eq (1)
messages = MessageBus.track_publish do
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post1.id }
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post1.id }
}
end
expect(messages.count).to eq (0)
end
it "clears 'previous' state when supplied" do
messages = MessageBus.track_publish do
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post1.id }
post '/presence/publish.json', current: { compose_state: 'open', action: 'edit', post_id: post2.id }, previous: { compose_state: 'open', action: 'edit', post_id: post1.id }
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post1.id }
}
post '/presence/publish.json', params: {
current: { compose_state: 'open', action: 'edit', post_id: post2.id },
previous: { compose_state: 'open', action: 'edit', post_id: post1.id }
}
end
expect(messages.count).to eq (3)
end