Compare commits

..

6 Commits
2.3.0 ... 2.3.1

Author SHA1 Message Date
Adam Meehan
b874e786b6 version 2.3.1 2010-03-19 14:24:19 +11:00
Adam Meehan
b356363791 fix bug preventing custom class methods on date/times 2010-03-19 14:11:13 +11:00
Adam Meehan
e9eb812c9e fix misbehaving spec 2010-03-19 13:39:47 +11:00
Adam Meehan
353f154330 tiny spec clean 2010-02-26 11:23:55 +11:00
Adam Meehan
ccfad007d1 version 2.3.0 gemspec 2010-02-04 13:23:26 +11:00
Adam Meehan
f3c0dd6144 removed most of old gem builder guff 2010-02-04 13:22:50 +11:00
6 changed files with 48 additions and 30 deletions

View File

@@ -1,3 +1,6 @@
= 2.3.1 [2010-03-19]
- Fixed bug where custom attribute writer method for date/times were being overriden
= 2.3.0 [2010-02-04]
- Backwards incompatible change to :equal_to option. Fixed error message clash with :equal_to option which exists in Rails already. Option is now :is_at.
- Fixed I18n support so it returns missing translation message instead of error

View File

@@ -7,10 +7,6 @@ require 'lib/validates_timeliness/version'
GEM = "validates_timeliness"
GEM_VERSION = ValidatesTimeliness::VERSION
AUTHOR = "Adam Meehan"
EMAIL = "adam.meehan@gmail.com"
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
SUMMARY = "Date and time validation plugin for Rails 2.x which allows custom formats"
spec = Gem::Specification.new do |s|
s.name = GEM
@@ -19,11 +15,11 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = "validatestime"
s.has_rdoc = true
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
s.summary = SUMMARY
s.summary = "Date and time validation plugin for Rails 2.x which allows custom formats"
s.description = s.summary
s.author = AUTHOR
s.email = EMAIL
s.homepage = HOMEPAGE
s.author = "Adam Meehan"
s.email = "adam.meehan@gmail.com"
s.homepage = "http://github.com/adzap/validates_timeliness"
s.require_path = 'lib'
s.autorequire = GEM

View File

@@ -24,7 +24,6 @@ module ValidatesTimeliness
def write_date_time_attribute(attr_name, value, type, time_zone_aware)
@attributes_cache["_#{attr_name}_before_type_cast"] = value
value = ValidatesTimeliness::Parser.parse(value, type)
if value && type != :date
@@ -49,16 +48,22 @@ module ValidatesTimeliness
columns_hash.each do |name, column|
if [:date, :time, :datetime].include?(column.type)
time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false
method_name = "#{name}="
next if instance_method_already_implemented?(method_name)
time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false
define_method(method_name) do |value|
write_date_time_attribute(name, value, column.type, time_zone_aware)
write_date_time_attribute(name, value, column.type, time_zone_aware)
end
timeliness_methods << method_name
end
end
# Hack to get around instance_method_already_implemented? caching the
# methods in the ivar. It then appears to subsequent calls that the
# methods defined here, have not been and get defined again.
@_defined_class_methods = nil
define_attribute_methods_without_timeliness
# add generated methods which is a Set object hence no += method
timeliness_methods.each {|attr| generated_methods << attr }

View File

@@ -1,3 +1,3 @@
module ValidatesTimeliness
VERSION = "2.3.0"
VERSION = "2.3.1"
end

View File

@@ -6,10 +6,11 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
end
it "should define and call write method on first assign" do
Person.class_eval { @generated_methods = Set.new }
Person.send(:undef_method, :birth_date=)
@person.should_receive(:write_date_time_attribute)
@person.birth_date = "2000-01-01"
Person.class_eval { @generated_methods = Set.new; @_defined_class_methods = nil }
Person.send(:undef_method, :birth_date=) if Person.instance_methods.include?('birth_date=')
person = Person.new
person.should_receive(:write_date_time_attribute)
person.birth_date = "2000-01-01"
end
it "should call write_date_time_attribute when time attribute assigned value" do
@@ -80,7 +81,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
it "should not save invalid date value to database" do
time_string = "2000-01-32 02:03:04"
@person = Person.new
@person.birth_date_and_time = time_string
@person.save
@person.reload
@@ -92,7 +92,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
it "should return time object from database in default timezone" do
ActiveRecord::Base.default_timezone = :utc
time_string = "2000-01-01 09:00:00"
@person = Person.new
@person.birth_date_and_time = time_string
@person.save
@person.reload
@@ -111,7 +110,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
it "should return time object from database in correct timezone" do
Time.zone = 'Melbourne'
time_string = "2000-06-01 09:00:00"
@person = Person.new
@person.birth_date_and_time = time_string
@person.save
@person.reload
@@ -123,7 +121,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
it "should return correct date value after new value assigned" do
today = Date.today
tomorrow = Date.today + 1.day
@person = Person.new
@person.birth_date = today
@person.birth_date.should == today
@person.birth_date = tomorrow
@@ -133,11 +130,28 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
it "should update date attribute on existing object" do
today = Date.today
tomorrow = Date.today + 1.day
@person = Person.create(:birth_date => today)
@person.birth_date = tomorrow
@person.save!
@person.reload
@person.birth_date.should == tomorrow
person = Person.create(:birth_date => today)
person.birth_date = tomorrow
person.save!
person.reload
person.birth_date.should == tomorrow
end
describe "attribute writer" do
it "should be able to be overridden in class" do
Person.class_eval { attr_accessor :birth_date }
person = Person.new
person.birth_date = 'overriden'
person.birth_date.should == 'overriden'
end
after do
Person.class_eval do
undef_method(:birth_date)
undef_method(:birth_date=)
end
end
end
end

View File

@@ -2,20 +2,20 @@
Gem::Specification.new do |s|
s.name = %q{validates_timeliness}
s.version = "2.2.2"
s.version = "2.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Adam Meehan"]
s.autorequire = %q{validates_timeliness}
s.date = %q{2009-09-19}
s.date = %q{2010-03-19}
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
s.email = %q{adam.meehan@gmail.com}
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/version.rb", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/matcher.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness.rb", "spec/validator_spec.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/ginger_scenarios.rb", "spec/spec_helper.rb", "spec/formats_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/time_travel", "spec/time_travel/time_travel.rb", "spec/time_travel/time_extensions.rb", "spec/time_travel/MIT-LICENSE", "spec/parser_spec.rb", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/resources", "spec/resources/person.rb", "spec/resources/sqlite_patch.rb", "spec/resources/schema.rb", "spec/resources/application.rb"]
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/matcher.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/version.rb", "lib/validates_timeliness.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/formats_spec.rb", "spec/ginger_scenarios.rb", "spec/parser_spec.rb", "spec/resources", "spec/resources/application.rb", "spec/resources/person.rb", "spec/resources/schema.rb", "spec/resources/sqlite_patch.rb", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/spec_helper.rb", "spec/time_travel", "spec/time_travel/MIT-LICENSE", "spec/time_travel/time_extensions.rb", "spec/time_travel/time_travel.rb", "spec/validator_spec.rb"]
s.homepage = %q{http://github.com/adzap/validates_timeliness}
s.require_paths = ["lib"]
s.rubyforge_project = %q{validatestime}
s.rubygems_version = %q{1.3.4}
s.rubygems_version = %q{1.3.5}
s.summary = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
if s.respond_to? :specification_version then