DEV: Assert for 200 response code to avoid changing magic helper in the future.

This commit is contained in:
Guo Xiang Tan
2018-06-07 16:11:09 +08:00
parent 3533bdb83f
commit 3a8f69c3d2
57 changed files with 498 additions and 498 deletions

View File

@ -14,7 +14,7 @@ shared_examples 'finding and showing post' do
it 'succeeds' do
get url
expect(response).to be_successful
expect(response.status).to eq(200)
end
context "deleted post" do
@ -36,13 +36,13 @@ shared_examples 'finding and showing post' do
it "can find posts as a moderator" do
sign_in(Fabricate(:moderator))
get url
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "can find posts as a admin" do
sign_in(Fabricate(:admin))
get url
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
end
@ -277,7 +277,7 @@ describe PostsController do
it 'passes the edit reason through' do
put "/posts/#{post.id}.json", params: update_params
expect(response).to be_successful
expect(response.status).to eq(200)
post.reload
expect(post.edit_reason).to eq("typo")
expect(post.raw).to eq("edited body")
@ -307,7 +307,7 @@ describe PostsController do
put "/posts/#{post.id}.json", params: param
expect(response).to be_successful
expect(response.status).to eq(200)
expect(TopicLink.count).to eq(1)
end
@ -330,7 +330,7 @@ describe PostsController do
PostDestroyer.new(moderator, first_post).destroy
put "/posts/#{first_post.id}.json", params: update_params
expect(response).to be_successful
expect(response.status).to eq(200)
post.reload
expect(post.raw).to eq('edited body')
@ -373,7 +373,7 @@ describe PostsController do
it 'creates a bookmark' do
put "/posts/#{post.id}/bookmark.json", params: { bookmarked: "true" }
expect(response).to be_successful
expect(response.status).to eq(200)
post_action = PostAction.find_by(user: user, post: post)
expect(post_action.post_action_type_id).to eq(PostActionType.types[:bookmark])
@ -435,7 +435,7 @@ describe PostsController do
api_key: api_key.key
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(PostAction.where(
post: post,
user: user,
@ -460,7 +460,7 @@ describe PostsController do
api_username: user.username
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(PostAction.where(
post: post,
user: user,
@ -587,7 +587,7 @@ describe PostsController do
it "can rebake the post" do
sign_in(Fabricate(:moderator))
put "/posts/#{post.id}/rebake.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
end
@ -617,7 +617,7 @@ describe PostsController do
wpid: 1
}
expect(response).to be_successful
expect(response.status).to eq(200)
original = response.body
post "/posts.json", params: {
@ -628,7 +628,7 @@ describe PostsController do
wpid: 2
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(response.body).to eq(original)
end
@ -647,7 +647,7 @@ describe PostsController do
reply_to_post_number: 1
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(post_1.topic.user.notifications.count).to eq(1)
post_1.topic.user.notifications.destroy_all
@ -660,7 +660,7 @@ describe PostsController do
import_mode: true
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(post_1.topic.user.notifications.count).to eq(0)
post "/posts.json", params: {
@ -672,7 +672,7 @@ describe PostsController do
import_mode: false
}
expect(response).to be_successful
expect(response.status).to eq(200)
expect(post_1.topic.user.notifications.count).to eq(1)
end
end
@ -694,7 +694,7 @@ describe PostsController do
title: 'this is the test title for the topic'
}
expect(response).to be_successful
expect(response.status).to eq(200)
parsed = ::JSON.parse(response.body)
expect(parsed["action"]).to eq("enqueued")
@ -747,7 +747,7 @@ describe PostsController do
title: 'when I eat s3 sometimes when not looking'
}
expect(response).to be_successful
expect(response.status).to eq(200)
parsed = ::JSON.parse(response.body)
expect(parsed["action"]).to eq("enqueued")
@ -780,7 +780,7 @@ describe PostsController do
archetype: Archetype.private_message
}
expect(response).to be_successful
expect(response.status).to eq(200)
parsed = ::JSON.parse(response.body)
post = Post.find(parsed['id'])
@ -796,7 +796,7 @@ describe PostsController do
nested_post: true
}
expect(response).to be_successful
expect(response.status).to eq(200)
parsed = ::JSON.parse(response.body)
expect(parsed['post']).to be_present
expect(parsed['post']['cooked']).to be_present
@ -807,7 +807,7 @@ describe PostsController do
title = "this is a title #{SecureRandom.hash}"
post "/posts.json", params: { raw: raw, title: title, wpid: 1 }
expect(response).to be_successful
expect(response.status).to eq(200)
post "/posts.json", params: { raw: raw, title: title, wpid: 2 }
expect(response).not_to be_successful
@ -835,7 +835,7 @@ describe PostsController do
meta_data: { xyz: 'abc' }
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_post = Post.last
topic = new_post.topic
@ -858,7 +858,7 @@ describe PostsController do
image_sizes: { width: '100', height: '200' }
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_post = Post.last
topic = new_post.topic
@ -883,7 +883,7 @@ describe PostsController do
target_usernames: "#{user_2.username},#{user_3.username}"
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_post = Post.last
new_topic = Topic.last
@ -956,7 +956,7 @@ describe PostsController do
category: destination_category.id,
shared_draft: 'true'
}
expect(response).to be_successful
expect(response.status).to eq(200)
result = JSON.parse(response.body)
topic = Topic.find(result['topic_id'])
expect(topic.category_id).to eq(shared_category.id)
@ -983,7 +983,7 @@ describe PostsController do
is_warning: true
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_topic = Topic.last
@ -1000,7 +1000,7 @@ describe PostsController do
is_warning: false
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_topic = Topic.last
@ -1020,7 +1020,7 @@ describe PostsController do
is_warning: true
}
expect(response).to be_successful
expect(response.status).to eq(200)
new_topic = Topic.last
@ -1058,7 +1058,7 @@ describe PostsController do
it "ensures staff can see the revisions" do
sign_in(Fabricate(:admin))
get "/posts/#{post.id}/revisions/#{post_revision.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "ensures poster can see the revisions" do
@ -1069,13 +1069,13 @@ describe PostsController do
pr = Fabricate(:post_revision, user: user, post: post)
get "/posts/#{pr.post_id}/revisions/#{pr.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "ensures trust level 4 can see the revisions" do
sign_in(Fabricate(:user, trust_level: 4))
get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
@ -1085,7 +1085,7 @@ describe PostsController do
it "ensures anyone can see the revisions" do
get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
@ -1099,7 +1099,7 @@ describe PostsController do
it "also work on deleted post" do
sign_in(admin)
get "/posts/#{deleted_post_revision.post_id}/revisions/#{deleted_post_revision.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
@ -1114,7 +1114,7 @@ describe PostsController do
it "also work on deleted topic" do
sign_in(admin)
get "/posts/#{post_revision.post_id}/revisions/#{post_revision.number}.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
end
@ -1173,7 +1173,7 @@ describe PostsController do
it "works!" do
put "/posts/#{post_id}/revisions/#{revision_id}/revert.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "supports reverting posts in deleted topics" do
@ -1181,7 +1181,7 @@ describe PostsController do
PostDestroyer.new(moderator, first_post).destroy
put "/posts/#{post_id}/revisions/#{revision_id}/revert.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
end
end
@ -1202,7 +1202,7 @@ describe PostsController do
it "retrieves the body when you can see the post" do
TopicEmbed.expects(:expanded_for).with(post).returns("full content")
get "/posts/#{post.id}/expand-embed.json"
expect(response).to be_successful
expect(response.status).to eq(200)
expect(::JSON.parse(response.body)['cooked']).to eq("full content")
end
end
@ -1220,7 +1220,7 @@ describe PostsController do
it "can see the flagged posts when authorized" do
sign_in(Fabricate(:moderator))
get "/posts/system/flagged.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "only shows agreed and deferred flags" do
@ -1241,7 +1241,7 @@ describe PostsController do
sign_in(Fabricate(:moderator))
get "/posts/#{user.username}/flagged.json"
expect(response).to be_successful
expect(response.status).to eq(200)
expect(JSON.parse(response.body).length).to eq(2)
end
@ -1261,7 +1261,7 @@ describe PostsController do
it "can see the deleted posts when authorized" do
sign_in(Fabricate(:moderator))
get "/posts/system/deleted.json"
expect(response).to be_successful
expect(response.status).to eq(200)
end
it "doesn't return secured categories for moderators if they don't have access" do
@ -1278,7 +1278,7 @@ describe PostsController do
sign_in(Fabricate(:moderator))
get "/posts/#{user.username}/deleted.json"
expect(response).to be_successful
expect(response.status).to eq(200)
data = JSON.parse(response.body)
expect(data.length).to eq(0)
@ -1294,7 +1294,7 @@ describe PostsController do
sign_in(Fabricate(:moderator))
get "/posts/#{user.username}/deleted.json"
expect(response).to be_successful
expect(response.status).to eq(200)
data = JSON.parse(response.body)
expect(data.length).to eq(0)
@ -1313,7 +1313,7 @@ describe PostsController do
sign_in(Fabricate(:admin))
get "/posts/#{user.username}/deleted.json"
expect(response).to be_successful
expect(response.status).to eq(200)
data = JSON.parse(response.body)
expect(data.length).to eq(1)
@ -1327,7 +1327,7 @@ describe PostsController do
it "can be viewed by anonymous" do
post = Fabricate(:post, raw: "123456789")
get "/posts/#{post.id}/raw.json"
expect(response).to be_successful
expect(response.status).to eq(200)
expect(response.body).to eq("123456789")
end
end
@ -1338,7 +1338,7 @@ describe PostsController do
post = Fabricate(:post, topic: topic, post_number: 1, raw: "123456789")
post.save
get "/raw/#{topic.id}/1.json"
expect(response).to be_successful
expect(response.status).to eq(200)
expect(response.body).to eq("123456789")
end
end
@ -1366,7 +1366,7 @@ describe PostsController do
get "/u/#{user.username}/activity.rss"
expect(response).to be_successful
expect(response.status).to eq(200)
body = response.body
@ -1384,7 +1384,7 @@ describe PostsController do
private_post
get "/private-posts.rss"
expect(response).to be_successful
expect(response.status).to eq(200)
body = response.body
@ -1398,7 +1398,7 @@ describe PostsController do
public_post
private_post
get "/private-posts.json"
expect(response).to be_successful
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
post_ids = json['private_posts'].map { |p| p['id'] }
@ -1415,7 +1415,7 @@ describe PostsController do
get "/posts.rss"
expect(response).to be_successful
expect(response.status).to eq(200)
body = response.body
@ -1431,7 +1431,7 @@ describe PostsController do
topicless_post
get "/posts.json"
expect(response).to be_successful
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
post_ids = json['latest_posts'].map { |p| p['id'] }
@ -1448,7 +1448,7 @@ describe PostsController do
post = Fabricate(:post, cooked: "WAt")
get "/posts/#{post.id}/cooked.json"
expect(response).to be_successful
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
expect(json).to be_present
@ -1473,7 +1473,7 @@ describe PostsController do
sign_in(Fabricate(:moderator))
get "/posts/#{post.id}/raw-email.json"
expect(response).to be_successful
expect(response.status).to eq(200)
json = ::JSON.parse(response.body)
expect(json['raw_email']).to eq('email_content')
@ -1488,12 +1488,12 @@ describe PostsController do
it 'can lock and unlock the post' do
put "/posts/#{public_post.id}/locked.json", params: { locked: "true" }
expect(response).to be_successful
expect(response.status).to eq(200)
public_post.reload
expect(public_post).to be_locked
put "/posts/#{public_post.id}/locked.json", params: { locked: "false" }
expect(response).to be_successful
expect(response.status).to eq(200)
public_post.reload
expect(public_post).not_to be_locked
end