|
80 | 80 | end |
81 | 81 | end |
82 | 82 | end |
| 83 | + |
| 84 | + describe "#cooked" do |
| 85 | + def serialize_post(user: nil, params: {}, cookies: {}) |
| 86 | + env = { |
| 87 | + "action_dispatch.request.parameters" => params, |
| 88 | + "REQUEST_METHOD" => "GET", |
| 89 | + "rack.input" => { |
| 90 | + }, |
| 91 | + "HTTP_COOKIE" => cookies.map { |k, v| "#{k}=#{v}" }.join(";"), |
| 92 | + } |
| 93 | + request = ActionDispatch::Request.new(env) |
| 94 | + guardian = Guardian.new(user, request) |
| 95 | + PostSerializer.new(post, scope: guardian) |
| 96 | + end |
| 97 | + |
| 98 | + before { SiteSetting.experimental_topic_translation = true } |
| 99 | + |
| 100 | + it "returns original cooked when experimental_topic_translation is disabled" do |
| 101 | + SiteSetting.experimental_topic_translation = false |
| 102 | + original_cooked = post.cooked |
| 103 | + expect(serialize_post(user: user).cooked).to eq(original_cooked) |
| 104 | + end |
| 105 | + |
| 106 | + it "returns original cooked when show_original param is present" do |
| 107 | + original_cooked = post.cooked |
| 108 | + expect(serialize_post(user: user, params: { "show_original" => "true" }).cooked).to eq( |
| 109 | + original_cooked, |
| 110 | + ) |
| 111 | + end |
| 112 | + |
| 113 | + it "returns translated content based on locale" do |
| 114 | + I18n.locale = "ja" |
| 115 | + post.custom_fields[DiscourseTranslator::TRANSLATED_CUSTOM_FIELD] = { |
| 116 | + "ja" => "こんにちは", |
| 117 | + "es" => "Hola", |
| 118 | + } |
| 119 | + expect(serialize_post(user: user).cooked).to eq("こんにちは") |
| 120 | + end |
| 121 | + |
| 122 | + it "returns original cooked when plugin is disabled" do |
| 123 | + SiteSetting.translator_enabled = false |
| 124 | + original_cooked = post.cooked |
| 125 | + expect(serialize_post(user: user).cooked).to eq(original_cooked) |
| 126 | + end |
| 127 | + end |
83 | 128 | end |
0 commit comments