From f96fffeb34073b86bbc8dbe0ded28c0fce437f10 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Sun, 7 Aug 2016 20:01:23 -0300 Subject: [PATCH] Add tests --- spec/components/topic_view_spec.rb | 5 +++++ .../application_controller_spec.rb | 22 +++++++++++++++++++ spec/controllers/topics_controller_spec.rb | 16 ++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index b193b9058fc..b31dd1264d7 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -35,6 +35,11 @@ describe TopicView do tv = TopicView.new(topic.id, coding_horror, slow_platform: true) expect(tv.chunk_size).to eq(TopicView.slow_chunk_size) end + + it "returns `print_chunk_size` when print param is true" do + tv = TopicView.new(topic.id, coding_horror, print: true) + expect(tv.chunk_size).to eq(TopicView.print_chunk_size) + end end context "with a few sample posts" do diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 1d46068aac6..cf2b9ff54ae 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -84,6 +84,28 @@ describe TopicsController do end + describe "print" do + render_views + + context "when the SiteSetting is enabled" do + before do + SiteSetting.stubs(:max_prints_per_hour_per_user).returns(10) + end + + it "uses the application layout when there's no param" do + get :show, topic_id: topic.id, slug: topic.slug + expect(response).to render_template(layout: 'application') + assert_select "meta[name=fragment]", true, "it has the meta tag" + end + + it "uses the crawler layout when there's an print param" do + get :show, topic_id: topic.id, slug: topic.slug, print: 'true' + expect(response).to render_template(layout: 'crawler') + assert_select "meta[name=fragment]", false, "it doesn't have the meta tag" + end + end + end + describe 'clear_notifications' do it 'correctly clears notifications if specified via cookie' do notification = Fabricate(:notification) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index eddb73bd0ee..6bff4d63347 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -747,6 +747,22 @@ describe TopicsController do expect(IncomingLink.count).to eq(1) end + it "doesn't renders the print view by default" do + user = Fabricate(:user) + get :show, topic_id: topic.id, slug: topic.slug, print: true + + expect(response).to be_forbidden + end + + it 'renders the print view when enabled' do + SiteSetting.max_prints_per_hour_per_user = 10 + + user = Fabricate(:user) + get :show, topic_id: topic.id, slug: topic.slug, print: true + + expect(response).to be_successful + end + it 'records redirects' do @request.env['HTTP_REFERER'] = 'http://twitter.com' get :show, { id: topic.id }