spec/helpers_spec.rb in bikepoa-tools-0.3.0 vs spec/helpers_spec.rb in bikepoa-tools-0.3.1

- old
+ new

@@ -1,18 +1,41 @@ describe BikePOA::Helpers::ForceField do - describe 'force integer' do + class DummySubject < Hashie::Dash + include BikePOA::Helpers::ForceField + property :normal + property :number + property :name - class DummySubject < Hashie::Dash - include BikePOA::Helpers::ForceField - property :normal - property :number + force_integer :number + force_utf8 :name + end - force_integer :number + describe 'force utf8' do + let(:dummy) { DummySubject.new } + + describe 'when setting property directly' do + it 'encodes a iso-8859-1 value to utf-8' do + dummy.name = "Jo\xE3o da Silva" + dummy.name.should == "Jo\xC3\xA3o da Silva" + end + + it 'does not try to over-convert an utf-8 value' do + dummy.name = "Jo\xC3\xA3o da Silva" + dummy.name.should == "Jo\xC3\xA3o da Silva" + end end + describe "when loading the Dash from a hash" do + it 'encodes an iso-8859-1 value to utf-8' do + expect { DummySubject.new(number: '678') }.to_not raise_error(ArgumentError) + end + end + end + describe 'force integer' do + let(:dummy) { DummySubject.new } + describe "when setting property directly" do - let(:dummy) { DummySubject.new } it "accepts any value that is castable to integer" do expect { dummy.number = '42' }.to_not raise_error(ArgumentError) expect { dummy.number = 42 }.to_not raise_error(ArgumentError) expect { dummy.number = 42.0 }.to_not raise_error(ArgumentError)