Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:jetrockets/wiseattr
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed May 23, 2013
2 parents ab5ee4a + 9be573c commit 1143f32
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
8 changes: 4 additions & 4 deletions spec/attrio/inspect_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Attrio::Inspect do
context '' do
context 'without options' do
let(:model) do
Class.new do
include Attrio
Expand All @@ -13,12 +13,12 @@

let(:object) { model.new }

it 'should' do
it 'should have inspect defined by attrio' do
object.method(:inspect).source_location.first.should match(/lib\/attrio\/inspect.rb/)
end
end

context '' do
context ':inspect option passed' do
let(:model) do
Class.new do
include Attrio
Expand All @@ -30,7 +30,7 @@

let(:object) { model.new }

it 'should' do
it 'should not have inspect defined by attrio' do
if RUBY_ENGINE == 'rbx'
object.method(:inspect).source_location.first.should_not match(/attrio/)
else
Expand Down
7 changes: 5 additions & 2 deletions spec/attrio/reset_spec.rb
Expand Up @@ -24,10 +24,13 @@
object.respond_to?(:reset_attributes!).should be_true
end

it 'should' do
it 'should reset attributes without :default option to nil' do
object.reset_attributes
object.first.should be_nil
object.second.should == 'default'
end

it 'should reset attributes with :default option to default value' do
object.reset_attributes
object.second.should == 'default'
end
end
10 changes: 5 additions & 5 deletions spec/attrio/types/integer_spec.rb
Expand Up @@ -15,12 +15,12 @@
let(:object){ model.new }

context 'with not typecasted assignment' do
it 'should cast an object which implements method to_i' do
it 'should cast an object which has method to_i' do
object.integer_attribute = "10 test"
object.integer_attribute.should == 10
end

it 'should not cast an object which does not implement method to_i' do
it 'should not cast an object which has not method to_i' do
lambda {
object.integer_attribute = []
}.should_not raise_exception
Expand Down Expand Up @@ -50,17 +50,17 @@
let(:object){ model.new }

context 'with not typecasted assignment' do
it 'should cast' do
it 'should cast <String> considering :base option' do
object.integer_attribute = "A"
object.integer_attribute.should == 10
end

it 'should cast an object which implements method to_i' do
it 'should cast an object which has method to_i' do
object.integer_attribute = 10.0
object.integer_attribute.should == 10
end

it 'should not cast an object which does not implement method to_i' do
it 'should not cast an object which has not method to_i' do
lambda {
object.integer_attribute = []
}.should_not raise_exception
Expand Down
44 changes: 41 additions & 3 deletions spec/attrio/types/symbol_spec.rb
Expand Up @@ -16,11 +16,49 @@

context 'with not typecasted assignment' do
it 'should cast <String>' do
object.symbol_attribute = "symbol"
object.symbol_attribute.should == :symbol
object.symbol_attribute = "CamelCase"
object.symbol_attribute.should == :CamelCase
end

it 'should not cast object which has not method to_sym' do
it 'should not cast an object which has not method to_sym' do
lambda {
object.symbol_attribute = []
}.should_not raise_exception
object.symbol_attribute.should be_nil
end
end

context 'with typecasted assignment' do
it 'should assign <Symbol>' do
symbol = :symbol

object.symbol_attribute = symbol
object.symbol_attribute.should == symbol
object.symbol_attribute.should be_equal(symbol)
end
end
end

context ':underscore option passed' do
let(:model) do
Class.new do
include Attrio

define_attributes do
attr :symbol_attribute, Symbol, :underscore => true
end
end
end

let(:object){ model.new }

context 'with not typecasted assignment' do
it 'should cast <String>' do
object.symbol_attribute = "CamelCase"
object.symbol_attribute.should == :camel_case
end

it 'should not cast an object which has not method to_sym' do
lambda {
object.symbol_attribute = []
}.should_not raise_exception
Expand Down

0 comments on commit 1143f32

Please sign in to comment.