changed spec_helper rails version selection to use VERSION

added RAILS_VER constant for version checking
fixed rspec module include requirement for 1.1.4 in specs
This commit is contained in:
Adam Meehan
2008-06-27 09:56:45 +10:00
parent 8b6d6ec789
commit ec12d60224
4 changed files with 26 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
# For Rails 2.0.2: # For Rails 2.0.x:
# This module adds method to create reader method for Time attributes # This module adds method to create reader method for Time attributes
# to allow for invalid date checking. If date is invalid then returns nil for # to allow for invalid date checking. If date is invalid then returns nil for
# time value. # time value.
@@ -15,7 +15,7 @@ module ValidatesTimeliness
module AttributeMethods module AttributeMethods
def self.included(base) def self.included(base)
if Rails::VERSION::STRING <= '2.0.2' if RAILS_VER <= '2.1'
base.extend ClassMethods::Old base.extend ClassMethods::Old
else else
base.extend ClassMethods::New base.extend ClassMethods::New
@@ -95,7 +95,7 @@ module ValidatesTimeliness
end end
end end
# defines time attribute reader and does conversion strict # defines time attribute reader and does strict conversion
def define_read_method_for_time_attribute(attr_name) def define_read_method_for_time_attribute(attr_name)
method_body = <<-EOV method_body = <<-EOV
def #{attr_name}(reload = false) def #{attr_name}(reload = false)

View File

@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/spec_helper' require File.dirname(__FILE__) + '/spec_helper'
describe ValidatesTimeliness::AttributeMethods do describe ValidatesTimeliness::AttributeMethods do
include ValidatesTimeliness::AttributeMethods
before do before do
@person = Person.new @person = Person.new
end end
@@ -42,12 +44,14 @@ describe ValidatesTimeliness::AttributeMethods do
strict_time_type_cast(Time.now).should be_kind_of(Time) strict_time_type_cast(Time.now).should be_kind_of(Time)
end end
if RAILS_VER >= '2.1'
it "should convert time string into current timezone" do it "should convert time string into current timezone" do
time = strict_time_type_cast("2000-01-01 12:13:14") time = strict_time_type_cast("2000-01-01 12:13:14")
Time.zone.utc_offset.should == 0 Time.zone.utc_offset.should == 0
time.zone.should == 'UTC' time.zone.should == 'UTC'
end end
end end
end
it "should return string value for attribute_before_type_cast when written as string" do it "should return string value for attribute_before_type_cast when written as string" do
time_string = "2000-06-01 01:02:03" time_string = "2000-06-01 01:02:03"
@@ -73,7 +77,7 @@ describe ValidatesTimeliness::AttributeMethods do
@person.birth_date_and_time.should be_nil @person.birth_date_and_time.should be_nil
end end
unless Rails::VERSION::STRING <= '2.0.2' unless RAILS_VER < '2.1'
it "should return stored time string as Time with correct timezone" do it "should return stored time string as Time with correct timezone" do
Time.zone = 'Melbourne' Time.zone = 'Melbourne'
time_string = "2000-06-01 01:02:03" time_string = "2000-06-01 01:02:03"
@@ -84,7 +88,7 @@ describe ValidatesTimeliness::AttributeMethods do
end end
describe "time attribute persistance" do describe "time attribute persistance" do
unless Rails::VERSION::STRING <= '2.0.2' unless RAILS_VER < '2.1'
it "should return time object from database in correct timezone" do it "should return time object from database in correct timezone" do
Time.zone = 'Melbourne' Time.zone = 'Melbourne'
time_string = "1980-06-01 09:00:00" time_string = "1980-06-01 09:00:00"

View File

@@ -1,6 +1,7 @@
require File.dirname(__FILE__) + '/spec_helper' require File.dirname(__FILE__) + '/spec_helper'
describe ValidatesTimeliness::Base do describe ValidatesTimeliness::Base do
include ValidatesTimeliness::Base
class AttributeAssignmentError; def initialize(*args); end; end class AttributeAssignmentError; def initialize(*args); end; end
class MultiparameterAssignmentErrors; def initialize(*args); end; end class MultiparameterAssignmentErrors; def initialize(*args); end; end

View File

@@ -4,26 +4,29 @@ require 'rubygems'
require 'spec' require 'spec'
if File.exists?(File.dirname(__FILE__) + '/../../../../vendor/rails') if File.exists?(File.dirname(__FILE__) + '/../../../../vendor/rails')
$: << File.dirname(__FILE__) + '/../../../../vendor/rails' $:.unshift File.dirname(__FILE__) + '/../../../../vendor/rails'
require 'activesupport/lib/active_support' require 'activesupport/lib/active_support'
require 'activerecord/lib/active_record' require 'activerecord/lib/active_record'
require 'railties/lib/rails/version' require 'railties/lib/rails/version'
vendored_rails = true
puts "Using vendored Rails version #{Rails::VERSION::STRING}" puts "Using vendored Rails version #{Rails::VERSION::STRING}"
else else
gem 'rails', "=#{ENV['VERSION']}" if ENV['VERSION']
require 'rails/version'
require 'active_record' require 'active_record'
require 'active_record/version' require 'active_record/version'
require 'rails/version'
vendored_rails = false
puts "Using gem Rails version #{Rails::VERSION::STRING}" puts "Using gem Rails version #{Rails::VERSION::STRING}"
end end
RAILS_VER = Rails::VERSION::STRING
Time.zone_default = TimeZone['UTC']
ActiveRecord::Base.default_timezone = :utc ActiveRecord::Base.default_timezone = :utc
if RAILS_VER >= '2.1'
Time.zone_default = TimeZone['UTC']
ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.time_zone_aware_attributes = true
end
require 'validates_timeliness' require 'validates_timeliness'