diff --git a/controllers/profile/pairwise_plugin_profile_controller.rb b/controllers/profile/pairwise_plugin_profile_controller.rb index d165031..d65ebb2 100644 --- a/controllers/profile/pairwise_plugin_profile_controller.rb +++ b/controllers/profile/pairwise_plugin_profile_controller.rb @@ -31,6 +31,7 @@ class PairwisePluginProfileController < ProfileController def choose @pairwise_content = find_content(params) + return render_access_denied if @pairwise_content.archived? vote = @pairwise_content.vote_to(params[:prompt_id], params[:direction], user_identifier, params[:appearance_id]) if request.xhr? render 'content_viewer/load_prompt.rjs' @@ -153,4 +154,3 @@ class PairwisePluginProfileController < ProfileController end - diff --git a/lib/pairwise_plugin/pairwise_content.rb b/lib/pairwise_plugin/pairwise_content.rb index 7c36cc9..8fefd12 100644 --- a/lib/pairwise_plugin/pairwise_content.rb +++ b/lib/pairwise_plugin/pairwise_content.rb @@ -54,15 +54,24 @@ class PairwisePlugin::PairwiseContent < Article 'Question managed by pairwise' end + def css_class_name + cl = "pairwise-plugin_pairwise-content" + cl += archived? ? " archived" : " active" + end + def to_html(options = {}) source = options["source"] embeded = options.has_key? "embeded" prompt_id = options["prompt_id"] pairwise_content = self - if not Environment.default.enabled_plugins.include? "PairwisePlugin" + if not environment.plugin_enabled?(PairwisePlugin) proc do render :file => 'content_viewer/closed_pool' end + elsif pairwise_content.archived? + proc do + render :file => 'content_viewer/read_only', :locals => {:pairwise_content => pairwise_content} + end else proc do locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } diff --git a/public/style.css b/public/style.css index f2dd129..8bb2fc2 100644 --- a/public/style.css +++ b/public/style.css @@ -2,7 +2,7 @@ width: 94%; } -.pairwise-plugin_pairwise-content #article-header .title { +.pairwise-plugin_pairwise-content.active #article-header .title { display: none; } diff --git a/test/functional/profile/pairwise_plugin_profile_controller_test.rb b/test/functional/profile/pairwise_plugin_profile_controller_test.rb index 19e6af9..ed3e992 100644 --- a/test/functional/profile/pairwise_plugin_profile_controller_test.rb +++ b/test/functional/profile/pairwise_plugin_profile_controller_test.rb @@ -271,4 +271,20 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase assert_redirected_to @content.url assert_equal "Only logged user could suggest new ideas", flash[:error] end + + should 'not register a vote when pairwise is archived' do + login_as(@user.user.login) + @content.update_attribute(:archived, true) + PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content).at_least_once + + get :choose, + :profile => @profile.identifier, + :id => @content.id, + :question_id => @question.id, + :prompt_id => @question.prompt.id, + :appearance_id => @question.appearance_id, + :direction => 'left' + assert_response 403 + end + end diff --git a/test/unit/pairwise_plugin/pairwise_content_test.rb b/test/unit/pairwise_plugin/pairwise_content_test.rb index 0ca6de6..0058054 100644 --- a/test/unit/pairwise_plugin/pairwise_content_test.rb +++ b/test/unit/pairwise_plugin/pairwise_content_test.rb @@ -18,7 +18,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase def setup pairwise_env_settings = { :api_host => "http://localhost:3030/", - :username => "abner.oliveira@serpro.gov.br", + :username => "abner.oliveira@serpro.gov.br", :password => "serpro" } @profile = create_user('testing').person @@ -39,7 +39,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase question = @http_stub_fixtures.create_question(2, 'Question 2', 'Choice X\nChoice Y') assert_not_nil question assert_equal 2, question.id - assert_equal 'Question 2', question.name + assert_equal 'Question 2', question.name end should 'provide proper short description' do @@ -77,7 +77,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase end should 'add error to base when the question does not exist' do - Response = Struct.new(:code, :message) + Response = Struct.new(:code, :message) @response = Response.new(422, "Any error") @@ -97,15 +97,15 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase #expectations pairwise_content = PairwiseContentFixtures.new_pairwise_content pairwise_content.profile = @profile - pairwise_content.expects(:valid?).returns(true) + pairwise_content.expects(:valid?).returns(true) pairwise_content.expects(:create_pairwise_question).returns(question) pairwise_content.expects(:toggle_autoactivate_ideas).at_least_once #save should call before_save which sends the question to pairwise pairwise_content.save! - + #after save pairwise_question_id should store question id generated by pairwise assert_equal question.id, pairwise_content.pairwise_question_id - end + end should 'send changes in choices to pairwise service' do @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) @@ -121,7 +121,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase end should 'send new choices to pairwise_service' do - @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) + @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) @pairwise_content.expects('new_record?').returns(false).at_least_once @pairwise_content.expects('valid?').returns(true).at_least_once @@ -170,7 +170,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase pairwise_content.stubs(:valid? => true) pairwise_content.stubs(:send_question_to_service => true) pairwise_content.join_choices(choices_to_join, parent_choice, user=nil) - + choices_related = PairwisePlugin::ChoicesRelated.related_choices_for(parent_choice) assert_equal 2, choices_related.size assert_equal 1, choices_related.select { |c| c.choice_id == 2}.size @@ -182,12 +182,12 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase # end should 'ask skip prompt reasons' do - prompt = Pairwise::Prompt.new({"left_choice_text"=>"Choice 1", "right_choice_text"=>"New inactive choice", "left_choice_id"=>1300, "right_choice_id"=>1302, "id"=>194, "tracking"=>nil, "votes_count"=>0}) + prompt = Pairwise::Prompt.new({"left_choice_text"=>"Choice 1", "right_choice_text"=>"New inactive choice", "left_choice_id"=>1300, "right_choice_id"=>1302, "id"=>194, "tracking"=>nil, "votes_count"=>0}) reasons = @pairwise_content.ask_skip_reasons(prompt) assert_not_nil reasons assert_equal 7, reasons.size - + assert reasons[0].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[0][:text] assert reasons[1].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[1][:text] assert reasons[2].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[2][:text] @@ -196,4 +196,35 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase assert reasons[5].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[4][:text] assert reasons[6].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[5][:text] end + + should 'append active class in article view when it is not archived' do + @pairwise_content.expects(:archived?).returns(false) + assert_equal 'pairwise-plugin_pairwise-content active', @pairwise_content.css_class_name + end + + should 'append archived class in article view when it is archived' do + @pairwise_content.expects(:archived?).returns(true) + assert_equal 'pairwise-plugin_pairwise-content archived', @pairwise_content.css_class_name + end + + should 'render read only view when the pairwise content is archived' do + @profile.environment.enable_plugin(PairwisePlugin) + expects(:render).with(:file => 'content_viewer/read_only', :locals => {:pairwise_content => @pairwise_content}) + @pairwise_content.expects(:archived?).returns(true) + instance_eval(&@pairwise_content.to_html) + end + + should 'render normal view when the pairwise content is not archived' do + @profile.environment.enable_plugin(PairwisePlugin) + expects(:render).with(:file => 'content_viewer/prompt', :locals => {:pairwise_content => @pairwise_content, :source => nil, :embeded => false, :prompt_id => nil }) + @pairwise_content.expects(:archived?).returns(false) + instance_eval(&@pairwise_content.to_html) + end + + should 'render nothing when the plugin is not enabled' do + @profile.environment.disable_plugin(PairwisePlugin) + expects(:render).with(:file => 'content_viewer/closed_pool') + instance_eval(&@pairwise_content.to_html) + end + end diff --git a/views/content_viewer/_menu.html.erb b/views/content_viewer/_menu.html.erb index d1c979d..b28188e 100644 --- a/views/content_viewer/_menu.html.erb +++ b/views/content_viewer/_menu.html.erb @@ -1,9 +1,11 @@ <% extend PairwisePlugin::Helpers::ViewerHelper %>