simple_model 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
3
2
  describe SimpleModel::ExtendCore, 'Float.rb' do
4
3
  before(:all) do
5
4
  include SimpleModel::ExtendCore
@@ -18,44 +17,40 @@ describe SimpleModel::ExtendCore, 'Float.rb' do
18
17
  it "should return a string" do
19
18
  0.333.to_currency_s.class.should eql(String)
20
19
  end
21
- # it "should prefix string with currency symbol" do
22
- # 5.12.to_currency_s.include?("$").should be_true
23
- # end
24
- # it "should padd with zeros for cents" do
25
- # 5.0.to_currency_s.should eql("$5.00")
26
- # end
27
- # it "should round string to nearest tenth" do
28
- # 0.333.to_currency_s.should eql("$0.33")
29
- # end
30
- # it "should add commas to long numbers" do
31
- # 500000000000.0.to_currency_s.should eql("$500,000,000,000.00")
32
- # 50000000000.0.to_currency_s.should eql("$50,000,000,000.00")
33
- # 5000000000.0.to_currency_s.should eql("$5,000,000,000.00")
34
- # end
20
+ it "should prefix string with currency symbol" do
21
+ 5.12.to_currency_s.include?("$").should be_true
22
+ end
23
+ it "should padd with zeros for cents" do
24
+ 5.0.to_currency_s.should eql("$5.00")
25
+ end
26
+ it "should round string to nearest tenth" do
27
+ 0.333.to_currency_s.should eql("$0.33")
28
+ end
29
+ it "should add commas to long numbers" do
30
+ 500000000000.0.to_currency_s.should eql("$500,000,000,000.00")
31
+ 50000000000.0.to_currency_s.should eql("$50,000,000,000.00")
32
+ 5000000000.0.to_currency_s.should eql("$5,000,000,000.00")
33
+ end
35
34
  end
36
-
37
35
  end
38
36
 
39
-
40
37
  describe SimpleModel::ExtendCore, 'String.rb' do
41
38
  before(:all) do
42
39
  include SimpleModel::ExtendCore
43
40
  end
44
- describe SimpleModel::ExtendCore, 'safe_datetime_string' do
41
+ context '#safe_datetime_string' do
45
42
  it "should set US formated datetime string to international" do
46
43
  "12/31/2010".safe_datetime_string.should eql("2010-12-31")
47
44
  "12/31/2010T23:31:59".safe_datetime_string.should eql("2010-12-31T23:31:59")
48
45
  "12/31/2010 23:31:59".safe_datetime_string.should eql("2010-12-31 23:31:59")
49
-
50
46
  end
51
47
  end
52
48
 
53
- describe SimpleModel::ExtendCore, 'to_b' do
49
+ context '#to_b' do
54
50
  it "should return a Boolean" do
55
51
  "1".to_b.class.should eql(TrueClass)
56
52
  "".to_b.class.should eql(FalseClass)
57
53
  end
58
-
59
54
  it "should return true if string is '1' or 't' or 'true'"do
60
55
  ['1','t','true'].each do |s|
61
56
  s.to_b.should be_true
@@ -63,41 +58,41 @@ describe SimpleModel::ExtendCore, 'String.rb' do
63
58
  end
64
59
  end
65
60
 
66
- describe SimpleModel::ExtendCore, 'to_date' do
67
- it "return a Date object" do
61
+ context '#to_date' do
62
+ it "should handel US formatted date strings" do
63
+ lambda {"12/31/2010".to_date}.should_not raise_error
68
64
  "12/31/2010".to_date.class.should eql(Date)
65
+ "12/31/2010".to_date.should eql(Date.parse("2010-12-31"))
66
+ end
67
+ it "should handle C# JSON datetime stamp" do
68
+ lambda {"\/Date(1310669017000)\/".to_date}.should_not raise_error
69
+ "\/Date(1310669017000)\/".to_date.should be_kind_of(Date)
70
+ "\/Date(1310669017000)\/".to_date.should eql(Date.parse("2011-07-14"))
69
71
  end
70
72
  end
71
- describe SimpleModel::ExtendCore, 'to_date' do
72
- it "return a Time object" do
73
- "12/31/2010".to_time.class.should eql(Time)
73
+
74
+ context '#to_time' do
75
+ it "should handel US formatted date strings" do
76
+ lambda {"12/31/2010 12:00:00".to_time}.should_not raise_error
77
+ "12/31/2010 12:00:00".to_time.should be_kind_of(Time)
78
+ "12/31/2010 12:00:00".to_time.should eql(Time.parse("2010-12-31 12:00:00"))
79
+ end
80
+ it "should handle C# JSON datetime stamp" do
81
+ lambda {"\/Date(1310669017000)\/".to_time}.should_not raise_error
82
+ "\/Date(1310669017000)\/".to_time.should be_kind_of(Time)
83
+ "\/Date(1310669017000)\/".to_time.should eql(Time.parse("2011-07-14 13:43:37"))
74
84
  end
75
85
  end
76
- describe SimpleModel::ExtendCore, 'to_f' do
86
+
87
+ context '#to_f' do
77
88
  it "return a Foat from a string that may contain non-numeric values" do
78
89
  "$5,000.006".to_f.should eql(5000.006)
79
90
  end
80
91
  end
81
- describe SimpleModel::ExtendCore, 'to_currency' do
92
+
93
+ context '#to_currency' do
82
94
  it "return a BigDecimal from a string that may contain non-numeric values" do
83
- "$5,000.006".to_currency.should eql(BigDecimal("5000.01"))
84
- end
85
- end
86
-
87
- describe SimpleModel::ExtendCore, 'parse_name' do
88
- it "return return hash with name elements properly keyed" do
89
- hash = "Doe, John C.".parse_name
90
- hash[:first_name].should eql("John")
91
- hash[:last_name].should eql("Doe")
92
-
93
- hash = "John Doe".parse_name
94
- hash[:first_name].should eql("John")
95
- hash[:last_name].should eql("Doe")
96
-
97
- hash = "Mr. John C. Doe Jr".parse_name
98
- hash[:first_name].should eql("John")
99
- hash[:last_name].should eql("Doe")
100
-
95
+ "$5,000.006".to_currency.should eql(BigDecimal("5000.006"))
101
96
  end
102
97
  end
103
98
  end
@@ -1,13 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe SimpleModel do
4
+
5
+ after(:each) do
6
+ Object.send(:remove_const,:TestStuff)
7
+ end
8
+
4
9
  context 'action methods' do
5
- describe "save" do
6
-
10
+ describe "save" do
7
11
  it "should perform the supplied methods" do
8
12
  class TestStuff < SimpleModel::Base
9
- save :test
10
-
13
+ save :test
11
14
  attr_accessor :foo
12
15
 
13
16
  def test
@@ -40,7 +43,6 @@ describe SimpleModel do
40
43
  end
41
44
 
42
45
  describe "destroy" do
43
-
44
46
  it "should not preform validation by default" do
45
47
  class TestStuff < SimpleModel::Base
46
48
  destroy :test
@@ -55,6 +57,40 @@ describe SimpleModel do
55
57
  t.destroy.should be_true
56
58
  end
57
59
  end
60
+ context "action methods that end with '!'" do
61
+ it 'should raise exception if validation fails' do
62
+ class TestStuff < SimpleModel::Base
63
+ save :my_save_method
64
+ has_attributes :foo
65
+
66
+ def my_save_method
67
+ false
68
+ end
69
+ end
70
+
71
+ t = TestStuff.new
72
+ lambda {t.save!}.should raise_error(SimpleModel::ActionError)
73
+ end
74
+ it 'should raise exception if validation fails' do
75
+ class TestStuff < SimpleModel::Base
76
+ save :my_save_method
77
+ has_attributes :foo
78
+ validate :validates_bar
79
+
80
+ def my_save_method
81
+ self.errors.blank?
82
+ end
83
+
84
+ def validates_bar
85
+ self.errors.add(:foo, "bar")
86
+ end
87
+ end
88
+
89
+ t = TestStuff.new
90
+ lambda {t.save!}.should raise_error(SimpleModel::ValidationError)
91
+ end
92
+
93
+ end
58
94
  end
59
95
 
60
96
 
@@ -164,20 +200,5 @@ describe SimpleModel do
164
200
  t.changed?.should be_true
165
201
  t.save
166
202
  t.changed?.should be_false
167
- end
168
-
203
+ end
169
204
  end
170
-
171
- #describe SimpleModel::Errors do
172
- # it 'Should add a error setter' do
173
- # class TestError
174
- # include SimpleModel::Errors
175
- # attr_accessor :test_attr
176
- # end
177
- # a = TestError.new(self)
178
- # a.errors.add(:test_attr, "test")
179
- # a.errors?.should be_true
180
- #
181
- # #a.test.should be_false
182
- # end
183
- #end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  #$LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'simple_model'
4
4
  require 'rspec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-16 00:00:00.000000000Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70104505150660 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70104505150660
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activemodel
27
- requirement: &70104505150160 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '3.0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70104505150160
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70104505149780 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70104505149780
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: autotest
49
- requirement: &70104505149320 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,28 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70104505149320
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: debugger
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
58
94
  description: Simpifies building tableless models or models backed by webservices.
59
95
  Create data type specific attributes with default if values.
60
96
  email:
@@ -66,7 +102,6 @@ files:
66
102
  - .gitignore
67
103
  - .rspec
68
104
  - Gemfile
69
- - Gemfile.lock
70
105
  - LICENSE.txt
71
106
  - README.md
72
107
  - Rakefile
@@ -74,6 +109,7 @@ files:
74
109
  - lib/simple_model/attributes.rb
75
110
  - lib/simple_model/base.rb
76
111
  - lib/simple_model/error_helpers.rb
112
+ - lib/simple_model/exceptions.rb
77
113
  - lib/simple_model/extend_core.rb
78
114
  - lib/simple_model/simple_model_railtie.rb
79
115
  - lib/simple_model/validation.rb
@@ -103,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
139
  version: '0'
104
140
  requirements: []
105
141
  rubyforge_project: simple_model
106
- rubygems_version: 1.8.6
142
+ rubygems_version: 1.8.24
107
143
  signing_key:
108
144
  specification_version: 3
109
145
  summary: Simpifies building tableless models or models backed by webservices
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- simple_model (1.1.0)
5
- activemodel (~> 3.0)
6
- activesupport (~> 3.0)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- ZenTest (4.6.2)
12
- activemodel (3.1.1)
13
- activesupport (= 3.1.1)
14
- builder (~> 3.0.0)
15
- i18n (~> 0.6)
16
- activesupport (3.1.1)
17
- multi_json (~> 1.0)
18
- autotest (4.4.6)
19
- ZenTest (>= 4.4.1)
20
- builder (3.0.0)
21
- diff-lcs (1.1.3)
22
- i18n (0.6.0)
23
- multi_json (1.0.3)
24
- rspec (2.7.0)
25
- rspec-core (~> 2.7.0)
26
- rspec-expectations (~> 2.7.0)
27
- rspec-mocks (~> 2.7.0)
28
- rspec-core (2.7.1)
29
- rspec-expectations (2.7.0)
30
- diff-lcs (~> 1.1.2)
31
- rspec-mocks (2.7.0)
32
-
33
- PLATFORMS
34
- ruby
35
-
36
- DEPENDENCIES
37
- autotest
38
- rspec
39
- simple_model!