Skip to content

Commit

Permalink
Fix all tests, hooray
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Jul 2, 2010
1 parent 103a9f6 commit 9536a71
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
6 changes: 5 additions & 1 deletion features/refinery/site_bar.feature
Expand Up @@ -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"
Expand All @@ -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"
6 changes: 5 additions & 1 deletion 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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/web_steps.rb
Expand Up @@ -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|
Expand Down
6 changes: 1 addition & 5 deletions 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" }
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/inquiry_test.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions vendor/plugins/inquiries/app/models/inquiry.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9536a71

Please sign in to comment.