Commit 74db0fa7656ad718bfd334cc6046c7be1cc10f9f

Authored by Victor Costa
1 parent 2a21aa48
Exists in master

Fix functional tests

test/functional/profile/pairwise_plugin_profile_controller_test.rb
@@ -13,12 +13,12 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase @@ -13,12 +13,12 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase
13 13
14 def setup 14 def setup
15 @environment = Environment.default 15 @environment = Environment.default
16 - 16 +
17 @pairwise_client = Pairwise::Client.build(1, pairwise_env_settings) 17 @pairwise_client = Pairwise::Client.build(1, pairwise_env_settings)
18 @controller = PairwisePluginProfileController.new 18 @controller = PairwisePluginProfileController.new
19 @request = ActionController::TestRequest.new 19 @request = ActionController::TestRequest.new
20 @response = ActionController::TestResponse.new 20 @response = ActionController::TestResponse.new
21 - 21 +
22 @profile = fast_create(Community, :environment_id => @environment.id) 22 @profile = fast_create(Community, :environment_id => @environment.id)
23 @question = PairwiseContentFixtures.pairwise_question_with_prompt 23 @question = PairwiseContentFixtures.pairwise_question_with_prompt
24 @user = create_user('testinguser').person 24 @user = create_user('testinguser').person
@@ -31,16 +31,24 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase @@ -31,16 +31,24 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase
31 @profile.articles << @content 31 @profile.articles << @content
32 end 32 end
33 33
  34 + should 'load question without prompt' do
  35 + login_as(@user.user.login)
  36 + PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content).at_least_once
  37 +
  38 + get :prompt, :profile => @profile.identifier, :id => @content.id, :question => @question.id
  39 + assert_not_nil assigns(:pairwise_content)
  40 + assert_match /#{@question.name}/, @response.body
  41 + assert_no_match /#{@question.prompt.left_choice_text}/, @response.body
  42 + assert_no_match /#{@question.prompt.right_choice_text}/, @response.body
  43 + end
  44 +
34 should 'get a first prompt' do 45 should 'get a first prompt' do
35 login_as(@user.user.login) 46 login_as(@user.user.login)
36 - PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content) 47 + PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content).at_least_once
37 @content.expects(:question_with_prompt_for_visitor).with(@user.identifier, nil).returns(@question) 48 @content.expects(:question_with_prompt_for_visitor).with(@user.identifier, nil).returns(@question)
38 - get :prompt,  
39 - :profile => @profile.identifier,  
40 - :id => @content.id,  
41 - :question_id => @question.id  
42 - assert_not_nil assigns(:pairwise_content)  
43 - assert_match /#{@question.name}/, @response.body 49 +
  50 + xhr :get, :load_prompt, :profile => @profile.identifier, :id => @content.id
  51 + assert_not_nil assigns(:pairwise_content)
44 assert_match /#{@question.prompt.left_choice_text}/, @response.body 52 assert_match /#{@question.prompt.left_choice_text}/, @response.body
45 assert_match /#{@question.prompt.right_choice_text}/, @response.body 53 assert_match /#{@question.prompt.right_choice_text}/, @response.body
46 end 54 end
@@ -49,15 +57,9 @@ class PairwisePluginProfileControllerTest &lt; ActionController::TestCase @@ -49,15 +57,9 @@ class PairwisePluginProfileControllerTest &lt; ActionController::TestCase
49 login_as(@user.user.login) 57 login_as(@user.user.login)
50 PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content) 58 PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content)
51 @content.expects(:question_with_prompt_for_visitor).with(@user.identifier, @question.prompt.id.to_s).returns(@question) 59 @content.expects(:question_with_prompt_for_visitor).with(@user.identifier, @question.prompt.id.to_s).returns(@question)
52 - get :prompt,  
53 - :profile => @profile.identifier,  
54 - :id => @content.id,  
55 - :question_id => @question.id,  
56 - :prompt_id => @question.prompt.id 60 + xhr :get, :load_prompt, :profile => @profile.identifier, :id => @content.id, :question_id => @question.id, :prompt_id => @question.prompt.id
57 61
58 assert_not_nil assigns(:pairwise_content) 62 assert_not_nil assigns(:pairwise_content)
59 -  
60 - assert_match /#{@question.name}/, @response.body  
61 assert_match /#{@question.prompt.left_choice_text}/, @response.body 63 assert_match /#{@question.prompt.left_choice_text}/, @response.body
62 assert_match /#{@question.prompt.right_choice_text}/, @response.body 64 assert_match /#{@question.prompt.right_choice_text}/, @response.body
63 end 65 end
test/unit/pairwise/client_test.rb
@@ -5,6 +5,7 @@ require &#39;vcr&#39; @@ -5,6 +5,7 @@ require &#39;vcr&#39;
5 VCR.configure do |c| 5 VCR.configure do |c|
6 c.cassette_library_dir = "#{Rails.root}/plugins/pairwise/test/fixtures/vcr_cassettes" 6 c.cassette_library_dir = "#{Rails.root}/plugins/pairwise/test/fixtures/vcr_cassettes"
7 c.hook_into :webmock 7 c.hook_into :webmock
  8 + c.debug_logger = File.open('/tmp/log.txt', 'w')
8 end 9 end
9 10
10 class Pairwise::ClientTest < ActiveSupport::TestCase 11 class Pairwise::ClientTest < ActiveSupport::TestCase
@@ -173,4 +174,4 @@ class Pairwise::ClientTest &lt; ActiveSupport::TestCase @@ -173,4 +174,4 @@ class Pairwise::ClientTest &lt; ActiveSupport::TestCase
173 assert_equal 0, question.pending_choices.count 174 assert_equal 0, question.pending_choices.count
174 end 175 end
175 end 176 end
176 -end  
177 \ No newline at end of file 177 \ No newline at end of file
  178 +end
views/content_viewer/load_prompt.rjs
1 extend PairwisePlugin::Helpers::ViewerHelper 1 extend PairwisePlugin::Helpers::ViewerHelper
2 2
3 -question = @pairwise_content.prepare_prompt(pairwise_user_identifier(user), nil) 3 +question = @pairwise_content.prepare_prompt(pairwise_user_identifier(user), params[:prompt_id])
4 4
5 spinner = "pairwise_spinner#{@pairwise_content.id}" 5 spinner = "pairwise_spinner#{@pairwise_content.id}"
6 6