Skip to content

Commit

Permalink
Initial Rails 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
spikex committed Feb 24, 2010
1 parent 6ea1060 commit f79c538
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/strongbox_test.rb
Expand Up @@ -197,12 +197,12 @@ class StrongboxTest < Test::Unit::TestCase

should 'not have an error on the secret when valid' do
assert @valid.valid?
assert_nil @valid.errors.on(:secret)
assert_does_not_have_errors_on(@valid,:secret)
end

should 'have an error on the secret when invalid' do
assert !@invalid.valid?
assert @invalid.errors.on(:secret)
assert_has_errors_on(@invalid,:secret)
end
end

Expand All @@ -223,22 +223,22 @@ class StrongboxTest < Test::Unit::TestCase

should 'not have an error on the secret when in range' do
assert @valid.valid?
assert_nil @valid.errors.on(:secret)
assert_does_not_have_errors_on(@valid,:secret)
end

should 'not have an error on the secret when nil' do
assert @valid_nil.valid?
assert_nil @valid_nil.errors.on(:secret)
assert_does_not_have_errors_on(@valid_nil,:secret)
end

should 'not have an error on the secret when blank' do
assert @valid_blank.valid?
assert_nil @valid_blank.errors.on(:secret)
assert_does_not_have_errors_on(@valid_blank,:secret)
end

should 'have an error on the secret when invalid' do
assert !@invalid.valid?
assert @invalid.errors.on(:secret)
assert_has_errors_on(@invalid,:secret)
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_helper.rb
Expand Up @@ -4,7 +4,9 @@

require 'rubygems'
require 'test/unit'
require 'sqlite3'
require 'active_record'
require 'logger'
gem 'thoughtbot-shoulda', ">= 2.9.0"
require 'shoulda'
begin require 'redgreen'; rescue LoadError; end
Expand Down Expand Up @@ -49,6 +51,16 @@ def rebuild_class options = {}
end
end

def assert_has_errors_on(model,attribute)
# Rails 2.X && Rails 3.X
!model.errors[attribute].empty?
end

def assert_does_not_have_errors_on(model,attribute)
# Rails 2.X Rails 3.X
model.errors[attribute].nil? || model.errors[attribute].empty?
end

def generate_key_pair(password = nil,size = 2048)
rsa_key = OpenSSL::PKey::RSA.new(size)
# If no password is provided, don't encrypt the key
Expand Down

0 comments on commit f79c538

Please sign in to comment.