A platform for community discussion. Free, open, simple.
DEV: Reduce duplication
Daniel Waterworth2b8a013e322c
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rbindex 358c1f99372..f1b0d3a2f2a 100644--- a/spec/requests/tags_controller_spec.rb+++ b/spec/requests/tags_controller_spec.rb@@ -3,6 +3,12 @@require 'rails_helper'describe TagsController do+ define_method(:get_json_body) do+ ::JSON.parse(response.body)+ end++ let(:json) { get_json_body }+fab!(:user) { Fabricate(:user) }fab!(:admin) { Fabricate(:admin) }fab!(:regular_user) { Fabricate(:trust_level_4) }@@ -28,7 +34,7 @@ describe TagsController doexpect(response.status).to eq(200)- tags = JSON.parse(response.body)["tags"]+ tags = json["tags"]expect(tags.length).to eq(1)expect(tags[0]['text']).to eq("topic-test")end@@ -53,7 +59,7 @@ describe TagsController doexpect(response.status).to eq(200)- tags = JSON.parse(response.body)["tags"]+ tags = json["tags"]expect(tags.length).to eq(2)end@@ -94,7 +100,7 @@ describe TagsController doexpect(response.status).to eq(200)- response_tag = JSON.parse(response.body)["valid"].first+ response_tag = json["valid"].firstexpect(response_tag["value"]).to eq(tag.name)endend@@ -160,7 +166,7 @@ describe TagsController doexpect(response.status).to eq(200)- tag = JSON.parse(response.body)['tags']+ tag = json['tags']expect(tag[0]["id"]).to eq('test')endend@@ -175,7 +181,7 @@ describe TagsController doexpect(response.status).to eq(200)- tag = JSON.parse(response.body)['tags']+ tag = json['tags']expect(tag[0]["id"]).to eq('test')end@@ -184,7 +190,7 @@ describe TagsController doexpect(response.status).to eq(200)- tag = JSON.parse(response.body)['tags']+ tag = json['tags']expect(tag[0]["id"]).to eq('test')endend@@ -209,7 +215,7 @@ describe TagsController docontext 'tagging enabled' dodef parse_topic_ids- JSON.parse(response.body)["topic_list"]["topics"]+ get_json_body["topic_list"]["topics"].map { |topic| topic["id"] }end@@ -353,7 +359,6 @@ describe TagsController dotag_names.each { |name| Fabricate(:tag, name: name) }get "/tags/filter/search.json", params: { q: 'stu' }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }.sort).to eq(['stuff', 'stumped'])end@@ -364,7 +369,6 @@ describe TagsController doget '/tags/filter/search.json', params: { q: 'tag', limit: 2 }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json['results'].map { |j| j['id'] }).to eq(['tag', 'tag2'])end@@ -376,7 +380,6 @@ describe TagsController donope = Fabricate(:tag, name: 'nope')get "/tags/filter/search.json", params: { q: nope.name, categoryId: category.id }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }.sort).to eq([])expect(json["forbidden"]).to be_presentexpect(json["forbidden_message"]).to eq(I18n.t("tags.forbidden.in_this_category", tag_name: nope.name))@@ -385,7 +388,6 @@ describe TagsController doit "can say if given tag is restricted to different category" docategoryget "/tags/filter/search.json", params: { q: yup.name, categoryId: Fabricate(:category).id }- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }.sort).to eq([])expect(json["forbidden"]).to be_presentexpect(json["forbidden_message"]).to eq(I18n.t(@@ -400,7 +402,6 @@ describe TagsController donope = Fabricate(:tag, name: 'nope')get "/tags/filter/search.json", params: { categoryId: category.id }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }.sort).to eq([yup.name])endend@@ -409,7 +410,6 @@ describe TagsController doyup, nope = Fabricate(:tag, name: 'yup'), Fabricate(:tag, name: 'nope')get "/tags/filter/search.json", params: { q: 'N/ope' }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }.sort).to eq(["nope"])end@@ -418,7 +418,6 @@ describe TagsController doFabricate(:topic, category: c, tags: [Fabricate(:tag, name: "cooltag")])get "/tags/filter/search.json", params: { q: "cool" }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["results"].map { |j| j["id"] }).to eq(['cooltag'])end@@ -428,12 +427,12 @@ describe TagsController doget "/tags/filter/search.json", params: { q: '房' }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)+ json = get_json_bodyexpect(json["results"].map { |j| j["id"] }).to eq(['房地产'])get "/tags/filter/search.json", params: { q: 'тема' }expect(response.status).to eq(200)- json = ::JSON.parse(response.body)+ json = get_json_bodyexpect(json["results"].map { |j| j["id"] }).to eq(['тема-в-разработке'])endend@@ -458,7 +457,6 @@ describe TagsController doit 'returns a tag not found message' dodelete "/tags/doesntexists.json"expect(response).not_to be_successful- json = ::JSON.parse(response.body)expect(json['error_type']).to eq('not_found')endend@@ -491,7 +489,6 @@ describe TagsController doit 'returns the correct unused tags' doget "/tags/unused.json"expect(response.status).to eq(200)- json = ::JSON.parse(response.body)expect(json["tags"]).to contain_exactly("unused1", "unused2")end