Sha256: a6ba1c960d869f0d8e7c7f1302b090144882451a2ec6ba526e63ca49225357c4

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe ValidatesTimeliness::AttributeMethods do
  it 'should define _timeliness_raw_value_for instance method' do
    Person.instance_methods.should include('_timeliness_raw_value_for')
  end
  
  context "attribute write method" do
    class PersonWithCache
      include TestModel
      self.model_attributes = :birth_date, :birth_time, :birth_datetime
      validates_date :birth_date
      validates_time :birth_time
      validates_datetime :birth_datetime
    end

    it 'should cache attribute raw value' do
      r = PersonWithCache.new
      r.birth_datetime = date_string = '2010-01-01'
      r._timeliness_raw_value_for(:birth_datetime).should == date_string
    end

    context "with plugin parser" do
      class PersonWithParser
        include TestModel
        self.model_attributes = :birth_date, :birth_time, :birth_datetime
        validates_date :birth_date
        validates_time :birth_time
        validates_datetime :birth_datetime
      end

      before :all do
        ValidatesTimeliness.use_plugin_parser = true
      end

      it 'should parse a string value' do
        ValidatesTimeliness::Parser.should_receive(:parse) 
        r = PersonWithParser.new
        r.birth_date = '2010-01-01'
      end

      it 'should parse string as current timezone' do
        r = PersonWithParser.new
        r.birth_datetime = '2010-01-01 12:00'
        r.birth_datetime.zone == Time.zone.name
      end

      after :all do
        ValidatesTimeliness.use_plugin_parser = false
      end
    end
  end

  context "before_type_cast method" do
    it 'should not be defined if ORM does not support it' do
      Person.instance_methods(false).should_not include("birth_datetime_before_type_cast")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_timeliness-3.0.0.beta.3 spec/validates_timeliness/attribute_methods_spec.rb