From b26ec1dd0b360063e57dae46c20d726575ab63e4 Mon Sep 17 00:00:00 2001 From: nilsding Date: Tue, 27 Jan 2015 17:51:39 +0100 Subject: [PATCH] fixed question generator not working if privacy_allow_anonymous_questions is false (GitHub issue #71) --- app/models/inbox.rb | 2 +- spec/features/users/inbox_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 161e8c7c..0cea150b 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -3,7 +3,7 @@ class Inbox < ActiveRecord::Base belongs_to :question before_create do - raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and !self.user.privacy_allow_anonymous_questions? + raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and self.question.author_name != 'justask' and !self.user.privacy_allow_anonymous_questions? end def answer(answer_content, user) diff --git a/spec/features/users/inbox_spec.rb b/spec/features/users/inbox_spec.rb index 01f51740..19ba3581 100644 --- a/spec/features/users/inbox_spec.rb +++ b/spec/features/users/inbox_spec.rb @@ -60,6 +60,27 @@ feature "Inbox", :devise do page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true end + # Scenario: User with privacy options generates new question + # Given I am signed in + # When I visit the inbox + # And I click "Get new question" + # And I don't want to receive questions by anonymous users + # Then I get a new question + scenario 'user with privacy options generates new question', js: true do + me = FactoryGirl.create :user + me.privacy_allow_anonymous_questions = false + me.save + + login_as me, scope: :user + visit inbox_path + page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true + + click_button "Get new question" + wait_for_ajax + expect(page).to have_text('Answer'.upcase) + page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true + end + =begin # Scenario: User deletes a question # Given I am signed in