From 9536a711c4110a5518c0d8660277f5e38c2fd781 Mon Sep 17 00:00:00 2001 From: parndt Date: Fri, 2 Jul 2010 22:58:50 +1200 Subject: [PATCH] Fix all tests, hooray --- features/refinery/site_bar.feature | 6 +++++- features/step_definitions/refinery/user_steps.rb | 6 +++++- features/step_definitions/web_steps.rb | 2 +- features/support/factories.rb | 6 +----- test/unit/inquiry_test.rb | 6 +++--- vendor/plugins/inquiries/app/models/inquiry.rb | 14 +++++++------- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/features/refinery/site_bar.feature b/features/refinery/site_bar.feature index 6455183e56..19d213c3b8 100644 --- a/features/refinery/site_bar.feature +++ b/features/refinery/site_bar.feature @@ -3,6 +3,9 @@ Feature: Site Bar I want logged in refinery users to see a site bar And I want logged in customers to not see a site bar + Background: + Given I am not logged in + Scenario: Not logged in When I go to the home page Then I should not see "Log out" @@ -13,6 +16,7 @@ Feature: Site Bar Then I should see "Log out" Scenario: Logged in as a customer - Given I am a logged in customer + Given A Refinery user exists + And I am a logged in customer When I go to the home page Then I should not see "Log out" \ No newline at end of file diff --git a/features/step_definitions/refinery/user_steps.rb b/features/step_definitions/refinery/user_steps.rb index f672228e76..1452ad9474 100644 --- a/features/step_definitions/refinery/user_steps.rb +++ b/features/step_definitions/refinery/user_steps.rb @@ -1,6 +1,6 @@ def login @user ||= Factory(:refinery_user) - visit '/refinery' + visit admin_root_url fill_in("session_login", :with => @user.email) fill_in("session_password", :with => @user.password) click_button("submit_button") @@ -16,6 +16,10 @@ def login login end +Given /^A Refinery user exists$/ do + @refinery_user ||= Factory(:refinery_user) +end + Given /^I have a user named "(.*)"$/ do |name| Factory(:user, :login => name) end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 24e057ee17..387abb6d52 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -220,7 +220,7 @@ def with_scope(locator) # Login stuff Given %r`not logged in$` do - s = UserSession.destroy + visit logout_path end Given %r`(?:log|am logged) in as "([^\"]+)"$` do |login| diff --git a/features/support/factories.rb b/features/support/factories.rb index 9734151e53..6f7bd70446 100644 --- a/features/support/factories.rb +++ b/features/support/factories.rb @@ -1,9 +1,5 @@ require 'factory_girl' -Factory.define :refinery_role, :class => :role do |r| - r.title "Refinery" -end - Factory.define :user do |u| u.sequence(:login) { |n| "person#{n}" } u.sequence(:email) { |n| "person#{n}@cucumber.com" } @@ -12,7 +8,7 @@ end Factory.define :refinery_user, :parent => :user do |u| - u.roles { [ Factory(:refinery_role) ] } + u.roles { [ Role[:refinery] ] } u.after_create do |user| Refinery::Plugins.registered.each_with_index do |plugin, index| user.plugins.create(:name => plugin.name, :position => index) diff --git a/test/unit/inquiry_test.rb b/test/unit/inquiry_test.rb index 086b5ee067..c98588faf0 100644 --- a/test/unit/inquiry_test.rb +++ b/test/unit/inquiry_test.rb @@ -7,7 +7,7 @@ class InquiryTest < ActiveSupport::TestCase def setup @new_inquiry = Inquiry.new @bad_email_inquiry = Inquiry.new(:email => "foo.bar.com", :name => "Dave") - @valid_inquiry = Inquiry.new(:email => "foo@bar.com", :name => "Dave") + @valid_inquiry = Inquiry.new(:email => "foo@bar.com", :name => "Dave", :message => "msg") @full_valid_inquiry = Inquiry.new(:email => "foo@bar.com", :name => "Dave", :phone => "3232332", :message => "message") end @@ -18,12 +18,12 @@ def test_should_force_name_and_email_to_be_valid assert_equal I18n.translate("activerecord.errors.messages.invalid"), @new_inquiry.errors.on('email') assert_nil @new_inquiry.errors.on('phone') - assert_nil @new_inquiry.errors.on('message') + assert_equal I18n.translate("activerecord.errors.messages.blank"), @new_inquiry.errors.on('message') assert !@bad_email_inquiry.save assert_equal I18n.translate("activerecord.errors.messages.invalid"), @bad_email_inquiry.errors.on('email') assert_nil @bad_email_inquiry.errors.on('phone') - assert_nil @bad_email_inquiry.errors.on('message') + assert_equal I18n.translate("activerecord.errors.messages.blank"), @bad_email_inquiry.errors.on('message') assert_nil @bad_email_inquiry.errors.on('name') assert @valid_inquiry.save diff --git a/vendor/plugins/inquiries/app/models/inquiry.rb b/vendor/plugins/inquiries/app/models/inquiry.rb index c2b416f5f4..49ac0e2a3c 100644 --- a/vendor/plugins/inquiries/app/models/inquiry.rb +++ b/vendor/plugins/inquiries/app/models/inquiry.rb @@ -46,12 +46,12 @@ def spam! # which is based off http://snook.ca/archives/other/effective_blog_comment_spam_blocker def score_for_body_links - link_count = self.message.scan(/http:/).size + link_count = self.message.to_s.scan(/http:/).size link_count > 2 ? -link_count : 2 end def score_for_body_length - if self.message.length > 20 and self.message.scan(/http:/).size.zero? + if self.message.to_s.length > 20 and self.message.to_s.scan(/http:/).size.zero? 2 else -1 @@ -87,20 +87,20 @@ def score_for_suspect_url current_score = 0 regex = /http:\/\/\S*(\.html|\.info|\?|&|free)/i - current_score =- (1 * message.scan(regex).size) + current_score =- (1 * message.to_s.scan(regex).size) end def score_for_suspect_tld regex = /http:\/\/\S*\.(de|pl|cn)/i - message.scan(regex).size * -1 + message.to_s.scan(regex).size * -1 end def score_for_lame_body_start - message.strip =~ /^(interesting|sorry|nice|cool)/i ? -10 : 0 + message.to_s.strip =~ /^(interesting|sorry|nice|cool)/i ? -10 : 0 end def score_for_author_link - name.scan(/http:/).size * -2 + name.to_s.scan(/http:/).size * -2 end def score_for_same_body @@ -111,7 +111,7 @@ def score_for_consonant_runs current_score = 0 [name, message, phone, email].each do |field| - field.scan(/[bcdfghjklmnpqrstvwxz]{5,}/).each do |run| + field.to_s.scan(/[bcdfghjklmnpqrstvwxz]{5,}/).each do |run| current_score =- run.size - 4 end end