morpheus 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/.autotest +12 -0
  2. data/.rspec +1 -0
  3. data/README.md +77 -0
  4. data/Rakefile +16 -0
  5. data/lib/morpheus.rb +2 -2
  6. data/lib/morpheus/base.rb +1 -1
  7. data/lib/morpheus/client/inflections.rb +1 -1
  8. data/lib/morpheus/configuration.rb +41 -43
  9. data/lib/morpheus/errors.rb +1 -1
  10. data/lib/morpheus/mixins/associations.rb +3 -1
  11. data/lib/morpheus/mixins/attributes.rb +66 -67
  12. data/lib/morpheus/mixins/conversion.rb +9 -13
  13. data/lib/morpheus/mixins/filtering.rb +4 -1
  14. data/lib/morpheus/mixins/finders.rb +4 -1
  15. data/lib/morpheus/mixins/introspection.rb +12 -16
  16. data/lib/morpheus/mixins/persistence.rb +25 -26
  17. data/lib/morpheus/mixins/reflections.rb +4 -1
  18. data/lib/morpheus/mixins/request_handling.rb +4 -1
  19. data/lib/morpheus/mixins/response_parsing.rb +12 -12
  20. data/lib/morpheus/mixins/url_support.rb +4 -1
  21. data/lib/morpheus/request.rb +34 -34
  22. data/lib/morpheus/response.rb +2 -2
  23. data/lib/morpheus/response_parser.rb +9 -4
  24. data/lib/morpheus/version.rb +1 -1
  25. data/morpheus.gemspec +4 -4
  26. data/spec/dummy/app/resources/author.rb +0 -1
  27. data/spec/dummy/app/resources/book.rb +0 -1
  28. data/spec/dummy/app/resources/dog.rb +3 -3
  29. data/spec/dummy/app/resources/meeting.rb +1 -2
  30. data/spec/dummy/config/application.rb +7 -36
  31. data/spec/dummy/config/environments/production.rb +1 -1
  32. data/spec/dummy/config/initializers/morpheus.rb +1 -1
  33. data/spec/dummy/config/locales/en.yml +1 -1
  34. data/spec/dummy/config/routes.rb +0 -56
  35. data/spec/morpheus/associations/association_spec.rb +51 -33
  36. data/spec/morpheus/associations/belongs_to_association_spec.rb +14 -2
  37. data/spec/morpheus/associations/has_many_association_spec.rb +31 -11
  38. data/spec/morpheus/associations/has_one_association_spec.rb +14 -2
  39. data/spec/morpheus/base_spec.rb +104 -100
  40. data/spec/morpheus/client/associations_spec.rb +43 -36
  41. data/spec/morpheus/client/log_subscriber_spec.rb +33 -0
  42. data/spec/morpheus/client/railtie_spec.rb +5 -0
  43. data/spec/morpheus/configuration_spec.rb +92 -113
  44. data/spec/morpheus/mixins/associations_spec.rb +90 -108
  45. data/spec/morpheus/mixins/attributes_spec.rb +71 -77
  46. data/spec/morpheus/mixins/conversion_spec.rb +49 -59
  47. data/spec/morpheus/mixins/filtering_spec.rb +13 -0
  48. data/spec/morpheus/mixins/finders_spec.rb +180 -217
  49. data/spec/morpheus/mixins/introspection_spec.rb +81 -124
  50. data/spec/morpheus/mixins/persistence_spec.rb +140 -133
  51. data/spec/morpheus/mixins/{reflection_spec.rb → reflections_spec.rb} +28 -28
  52. data/spec/morpheus/mixins/request_handling_spec.rb +21 -0
  53. data/spec/morpheus/mixins/response_parsing_spec.rb +10 -2
  54. data/spec/morpheus/mixins/url_support_spec.rb +29 -0
  55. data/spec/morpheus/reflection_spec.rb +21 -0
  56. data/spec/morpheus/relation_spec.rb +34 -58
  57. data/spec/morpheus/request_cache_spec.rb +33 -2
  58. data/spec/morpheus/request_queue_spec.rb +37 -0
  59. data/spec/morpheus/request_spec.rb +102 -1
  60. data/spec/morpheus/response_parser_spec.rb +17 -0
  61. data/spec/morpheus/response_spec.rb +55 -51
  62. data/spec/morpheus/type_caster_spec.rb +128 -118
  63. data/spec/morpheus/url_builder_spec.rb +41 -0
  64. data/spec/shared/active_model_lint_test.rb +2 -2
  65. data/spec/spec_helper.rb +7 -14
  66. data/spec/support/configuration.rb +3 -4
  67. metadata +32 -16
  68. data/README.rdoc +0 -44
  69. data/autotest/discover.rb +0 -7
  70. data/lib/morpheus/mock.rb +0 -66
  71. data/spec/morpheus/mock_spec.rb +0 -133
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::ResponseParser do
4
+
5
+ describe '#initialize' do
6
+ pending
7
+ end
8
+
9
+ describe '.parse' do
10
+ pending
11
+ end
12
+
13
+ describe '#parse' do
14
+ pending
15
+ end
16
+
17
+ end
@@ -1,72 +1,76 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Response, ".cached?" do
3
+ describe Morpheus::Response do
4
4
 
5
- context "when the response is marked as cached" do
6
-
7
- before(:each) do
8
- @response = Morpheus::Response.new({ :code => 200, :headers => "", :body => "", :time => 0.3 }, true)
9
- end
10
-
11
- it "returns true" do
12
- @response.should be_cached
13
- end
14
-
5
+ describe '#initialize' do
6
+ pending
15
7
  end
16
-
17
- context "when the response is marked as not cached" do
18
-
19
- before(:each) do
20
- @response = Morpheus::Response.new({ :code => 200, :headers => "", :body => "", :time => 0.3 }, false)
21
- end
22
8
 
23
- it "returns false" do
24
- @response.should_not be_cached
25
- end
9
+ describe '#cached?' do
10
+ context 'when the response is marked as cached' do
11
+ before(:each) do
12
+ @response = Morpheus::Response.new({ :code => 200, :headers => '', :body => '', :time => 0.3 }, true)
13
+ end
26
14
 
27
- end
28
-
29
- context "when the response is not marked as cached or otherwise" do
30
-
31
- before(:each) do
32
- @response = Morpheus::Response.new(:code => 200, :headers => "", :body => "", :time => 0.3)
15
+ it 'returns true' do
16
+ @response.should be_cached
17
+ end
33
18
  end
34
19
 
35
- it "returns false" do
36
- @response.should_not be_cached
20
+ context 'when the response is marked as not cached' do
21
+ before(:each) do
22
+ @response = Morpheus::Response.new({ :code => 200, :headers => '', :body => '', :time => 0.3 }, false)
23
+ end
24
+
25
+ it 'returns false' do
26
+ @response.should_not be_cached
27
+ end
37
28
  end
38
29
 
30
+ context 'when the response is not marked as cached or otherwise' do
31
+ before(:each) do
32
+ @response = Morpheus::Response.new(:code => 200, :headers => '', :body => '', :time => 0.3)
33
+ end
34
+
35
+ it 'returns false' do
36
+ @response.should_not be_cached
37
+ end
38
+ end
39
39
  end
40
40
 
41
- end
41
+ describe '#tag_for_caching!' do
42
+ pending
43
+ end
42
44
 
43
- describe Morpheus::Response, ".respond_to?" do
44
-
45
- before(:each) do
46
- @typhoeus_response = Typhoeus::Response.new(:code => 200, :headers => "", :body => "", :time => 0.3)
47
- @response = Morpheus::Response.new(:code => 200, :headers => "", :body => "", :time => 0.3)
45
+ describe '#tagged_for_caching?' do
46
+ pending
48
47
  end
49
-
50
- it "responds to all methods defined on itself" do
51
- @response.methods.reject { |method| method == :respond_to? }.each do |method|
52
- @response.should respond_to(method)
48
+
49
+ describe '#respond_to?' do
50
+ before(:each) do
51
+ @typhoeus_response = Typhoeus::Response.new(:code => 200, :headers => '', :body => '', :time => 0.3)
52
+ @response = Morpheus::Response.new(:code => 200, :headers => '', :body => '', :time => 0.3)
53
53
  end
54
- end
55
-
56
- it "responds to all methods defined on the Typhoeus::Response object it wraps" do
57
- @typhoeus_response.methods.each do |method|
58
- @response.should respond_to(method)
54
+
55
+ it 'responds to all methods defined on itself' do
56
+ @response.methods.reject { |method| method == :respond_to? }.each do |method|
57
+ @response.should respond_to(method)
58
+ end
59
59
  end
60
- end
61
-
62
- end
63
60
 
64
- describe Morpheus::Response, ".method_missing" do
61
+ it 'responds to all methods defined on the Typhoeus::Response object it wraps' do
62
+ @typhoeus_response.methods.each do |method|
63
+ @response.should respond_to(method)
64
+ end
65
+ end
66
+ end
65
67
 
66
- it "wraps a Typhoeus::Response object" do
67
- @response = Morpheus::Response.new
68
- Typhoeus::Response.new.methods.each do |method|
69
- @response.should respond_to(method.to_sym)
68
+ describe '#method_missing' do
69
+ it 'wraps a Typhoeus::Response object' do
70
+ @response = Morpheus::Response.new
71
+ Typhoeus::Response.new.methods.each do |method|
72
+ @response.should respond_to(method.to_sym)
73
+ end
70
74
  end
71
75
  end
72
76
 
@@ -1,343 +1,353 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::TypeCaster, "#cast" do
3
+ describe Morpheus::TypeCaster do
4
4
 
5
- context "when the type_class is nil" do
5
+ describe '.cast' do
6
+ context 'when the typecast_class is nil' do
7
+ it 'casts "hello" to "hello"' do
8
+ Morpheus::TypeCaster.cast('hello', nil).should eql('hello')
9
+ end
6
10
 
7
- it "casts 'hello' to 'hello'" do
8
- Morpheus::TypeCaster.cast('hello', nil).should eql('hello')
9
- end
11
+ it 'casts "2011-04-10" to "2011-04-10"' do
12
+ Morpheus::TypeCaster.cast('2011-04-10', nil).should eql('2011-04-10')
13
+ end
10
14
 
11
- it "casts '2011-04-10' to '2011-04-10'" do
12
- Morpheus::TypeCaster.cast('2011-04-10', nil).should eql('2011-04-10')
13
- end
15
+ it 'cast "3" to "3"' do
16
+ Morpheus::TypeCaster.cast('3', nil).should eql('3')
17
+ end
14
18
 
15
- it "cast '3' to '3'" do
16
- Morpheus::TypeCaster.cast('3', nil).should eql('3')
17
- end
19
+ it 'casts "10-04-2011T05:00:00Z" to "10-04-2011T05:00:00Z"' do
20
+ Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', nil).should eql('10-04-2011T05:00:00Z')
21
+ end
22
+
23
+ it 'casts "true" to "true"' do
24
+ Morpheus::TypeCaster.cast('true', nil).should eql('true')
25
+ end
26
+
27
+ it 'casts 4 to 4' do
28
+ Morpheus::TypeCaster.cast(4, nil).should eql(4)
29
+ end
30
+
31
+ it 'casts true to true' do
32
+ Morpheus::TypeCaster.cast(true, nil).should eql(true)
33
+ end
18
34
 
19
- it "casts '10-04-2011T05:00:00Z' to '10-04-2011T05:00:00Z'" do
20
- Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', nil).should eql('10-04-2011T05:00:00Z')
35
+ it 'cast DateTime to DateTime' do
36
+ Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), nil).should eql(DateTime.parse('10-04-2011T05:00:00Z'))
37
+ end
38
+
39
+ it 'casts Date to Date' do
40
+ Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), nil).should eql(Date.parse('2011-04-10'))
41
+ end
42
+
43
+ it 'casts Time to Time' do
44
+ Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), nil).should eql(Time.parse('10-04-2011T05:00:00Z'))
45
+ end
21
46
  end
22
47
 
23
- it "casts 'true' to 'true'" do
24
- Morpheus::TypeCaster.cast('true', nil).should eql('true')
48
+ context 'when the typecast_class is String' do
49
+ pending
25
50
  end
26
51
 
27
- it "casts 4 to 4" do
28
- Morpheus::TypeCaster.cast(4, nil).should eql(4)
52
+ context 'when the typecast_class is Integer' do
53
+ pending
29
54
  end
30
55
 
31
- it "casts true to true" do
32
- Morpheus::TypeCaster.cast(true, nil).should eql(true)
56
+ context 'when the typecast_class is DateTime' do
57
+ pending
33
58
  end
34
59
 
35
- it "cast DateTime to DateTime" do
36
- Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), nil).should eql(DateTime.parse('10-04-2011T05:00:00Z'))
60
+ context 'when the typecast_class is Date' do
61
+ pending
37
62
  end
38
63
 
39
- it "casts Date to Date" do
40
- Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), nil).should eql(Date.parse('2011-04-10'))
64
+ context 'when the typecast_class is Time' do
65
+ pending
41
66
  end
42
67
 
43
- it "casts Time to Time" do
44
- Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), nil).should eql(Time.parse('10-04-2011T05:00:00Z'))
68
+ context 'when the typecast_class is Boolean' do
69
+ pending
45
70
  end
46
71
 
72
+ context 'when the typecast_class is unknown' do
73
+ it 'raises an error' do
74
+ lambda {
75
+ Morpheus::TypeCaster.cast(nil, :made_up_class)
76
+ }.should raise_error(Morpheus::UnrecognizedTypeCastClass, "Can't typecast to made_up_class!")
77
+ end
78
+ end
47
79
  end
48
80
 
49
- context "when the type_class is String" do
50
-
51
- it "casts 'hello' to 'hello'" do
81
+ context '#parse_string' do
82
+ it 'casts "hello" to "hello"' do
52
83
  Morpheus::TypeCaster.cast('hello', :string).should eql('hello')
53
84
  end
54
85
 
55
- it "casts '2011-04-10' to '2011-04-10'" do
86
+ it 'casts "2011-04-10" to "2011-04-10"' do
56
87
  Morpheus::TypeCaster.cast('2011-04-10', :string).should eql('2011-04-10')
57
88
  end
58
89
 
59
- it "cast '3' to '3'" do
90
+ it 'cast "3" to "3"' do
60
91
  Morpheus::TypeCaster.cast('3', :string).should eql('3')
61
92
  end
62
93
 
63
- it "casts '10-04-2011T05:00:00Z' to '10-04-2011T05:00:00Z'" do
94
+ it 'casts "10-04-2011T05:00:00Z" to "10-04-2011T05:00:00Z"' do
64
95
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :string).should eql('10-04-2011T05:00:00Z')
65
96
  end
66
97
 
67
- it "casts 'true' to 'true'" do
98
+ it 'casts "true" to "true"' do
68
99
  Morpheus::TypeCaster.cast('true', :string).should eql('true')
69
100
  end
70
101
 
71
- it "casts 4 to '4'" do
102
+ it 'casts 4 to "4"' do
72
103
  Morpheus::TypeCaster.cast(4, :string).should eql('4')
73
104
  end
74
105
 
75
- it "casts true to 'true'" do
106
+ it 'casts true to "true"' do
76
107
  Morpheus::TypeCaster.cast(true, :string).should eql('true')
77
108
  end
78
109
 
79
- it "cast DateTime to '10-04-2011T05:00:00Z'" do
110
+ it 'cast DateTime to "10-04-2011T05:00:00Z"' do
80
111
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :string).should eql('2011-04-10T05:00:00+00:00')
81
112
  end
82
113
 
83
- it "casts Date to '2011-04-10'" do
114
+ it 'casts Date to "2011-04-10"' do
84
115
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :string).should eql('2011-04-10')
85
116
  end
86
117
 
87
- it "casts Time to '10-04-2011T05:00:00Z'" do
118
+ it 'casts Time to "10-04-2011T05:00:00Z"' do
88
119
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :string).should eql('Sun Apr 10 05:00:00 UTC 2011')
89
120
  end
90
-
91
121
  end
92
122
 
93
- context "when the type_class is Integer" do
94
-
95
- it "casts 'hello' to 0" do
123
+ context '#parse_integer' do
124
+ it 'casts "hello" to 0' do
96
125
  Morpheus::TypeCaster.cast('hello', :integer).should eql(0)
97
126
  end
98
127
 
99
- it "casts '2011-04-10' to 10" do
128
+ it 'casts "2011-04-10" to 10' do
100
129
  Morpheus::TypeCaster.cast('2011-04-10', :integer).should eql(2011)
101
130
  end
102
131
 
103
- it "cast '3' to 3" do
132
+ it 'cast "3" to 3' do
104
133
  Morpheus::TypeCaster.cast('3', :integer).should eql(3)
105
134
  end
106
135
 
107
- it "casts '10-04-2011T05:00:00Z' to 10" do
136
+ it 'casts "10-04-2011T05:00:00Z" to 10' do
108
137
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :integer).should eql(10)
109
138
  end
110
139
 
111
- it "casts 'true' to 0" do
140
+ it 'casts "true" to 0' do
112
141
  Morpheus::TypeCaster.cast('true', :integer).should eql(0)
113
142
  end
114
143
 
115
- it "casts 4 to 4" do
144
+ it 'casts 4 to 4' do
116
145
  Morpheus::TypeCaster.cast(4, :integer).should eql(4)
117
146
  end
118
147
 
119
- it "casts true to 1" do
148
+ it 'casts true to 1' do
120
149
  Morpheus::TypeCaster.cast(true, :integer).should eql(1)
121
150
  end
122
151
 
123
- it "casts false to 0" do
152
+ it 'casts false to 0' do
124
153
  Morpheus::TypeCaster.cast(false, :integer).should eql(0)
125
154
  end
126
155
 
127
- it "cast DateTime to 1302411600" do
156
+ it 'cast DateTime to 1302411600' do
128
157
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :integer).should eql(1302411600)
129
158
  end
130
159
 
131
- it "casts Date to 1302393600" do
160
+ it 'casts Date to 1302393600' do
132
161
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :integer).should eql(1302418800)
133
162
  end
134
163
 
135
- it "casts Time to 1302411600" do
164
+ it 'casts Time to 1302411600' do
136
165
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :integer).should eql(1302411600)
137
166
  end
138
-
139
167
  end
140
168
 
141
- context "when the type_class is DateTime" do
142
-
143
- it "casts 'hello' to nil" do
169
+ context '#parse_datetime' do
170
+ it 'casts "hello" to nil' do
144
171
  Morpheus::TypeCaster.cast('hello', :datetime).should eql(nil)
145
172
  end
146
173
 
147
- it "casts '2011-04-10' to DateTime" do
174
+ it 'casts "2011-04-10" to DateTime' do
148
175
  Morpheus::TypeCaster.cast('2011-04-10', :datetime).should eql(DateTime.parse('2011-04-10'))
149
176
  end
150
177
 
151
- it "cast '3' to nil" do
178
+ it 'casts "3" to nil' do
152
179
  Morpheus::TypeCaster.cast('3', :datetime).should eql(nil)
153
180
  end
154
181
 
155
- it "casts '10-04-2011T05:00:00Z' to DateTime" do
182
+ it 'casts "10-04-2011T05:00:00Z" to DateTime' do
156
183
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :datetime).should eql(DateTime.parse('10-04-2011T05:00:00Z'))
157
184
  end
158
185
 
159
- it "casts 'true' to nil" do
186
+ it 'casts "true" to nil' do
160
187
  Morpheus::TypeCaster.cast('true', :datetime).should eql(nil)
161
188
  end
162
189
 
163
- it "casts 4 to nil" do
190
+ it 'casts 4 to nil' do
164
191
  Morpheus::TypeCaster.cast(4, :datetime).should eql(nil)
165
192
  end
166
193
 
167
- it "casts true to nil" do
194
+ it 'casts true to nil' do
168
195
  Morpheus::TypeCaster.cast(true, :datetime).should eql(nil)
169
196
  end
170
197
 
171
- it "cast DateTime to DateTime" do
198
+ it 'cast DateTime to DateTime' do
172
199
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :datetime).should eql(DateTime.parse('10-04-2011T05:00:00Z'))
173
200
  end
174
201
 
175
- it "casts Date to DateTime" do
202
+ it 'casts Date to DateTime' do
176
203
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :datetime).should eql(DateTime.parse('2011-04-10'))
177
204
  end
178
205
 
179
- it "casts Time to DateTime" do
206
+ it 'casts Time to DateTime' do
180
207
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :datetime).should eql(DateTime.parse('10-04-2011T05:00:00Z'))
181
208
  end
182
-
183
209
  end
184
210
 
185
- context "when the type_class is Date" do
186
-
187
- it "casts 'hello' to nil" do
211
+ context '#parse_date' do
212
+ it 'casts "hello" to nil' do
188
213
  Morpheus::TypeCaster.cast('hello', :date).should eql(nil)
189
214
  end
190
215
 
191
- it "casts '2011-04-10' to Date" do
216
+ it 'casts "2011-04-10" to Date' do
192
217
  Morpheus::TypeCaster.cast('2011-04-10', :date).should eql(Date.parse('10-04-2011'))
193
218
  end
194
219
 
195
- it "cast '3' to nil" do
220
+ it 'cast "3" to nil' do
196
221
  Morpheus::TypeCaster.cast('3', :date).should eql(nil)
197
222
  end
198
223
 
199
- it "casts '10-04-2011T05:00:00Z' to Date" do
224
+ it 'casts "10-04-2011T05:00:00Z" to Date' do
200
225
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :date).should eql(Date.parse('10-04-2011T05:00:00Z'))
201
226
  end
202
227
 
203
- it "casts 'true' to nil" do
228
+ it 'casts "true" to nil' do
204
229
  Morpheus::TypeCaster.cast('true', :date).should eql(nil)
205
230
  end
206
231
 
207
- it "casts 4 to nil" do
232
+ it 'casts 4 to nil' do
208
233
  Morpheus::TypeCaster.cast(4, :date).should eql(nil)
209
234
  end
210
235
 
211
- it "casts true to nil" do
236
+ it 'casts true to nil' do
212
237
  Morpheus::TypeCaster.cast(true, :date).should eql(nil)
213
238
  end
214
239
 
215
- it "cast DateTime to Date" do
240
+ it 'cast DateTime to Date' do
216
241
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :date).should eql(Date.parse('10-04-2011T05:00:00Z'))
217
242
  end
218
243
 
219
- it "casts Date to Date" do
244
+ it 'casts Date to Date' do
220
245
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :date).should eql(Date.parse('2011-04-10'))
221
246
  end
222
247
 
223
- it "casts Time to Date" do
248
+ it 'casts Time to Date' do
224
249
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :date).should eql(Date.parse('10-04-2011T05:00:00Z'))
225
250
  end
226
-
227
251
  end
228
252
 
229
- context "when the type_class is Time" do
230
-
231
- it "casts 'hello' to nil" do
253
+ context '#parse_time' do
254
+ it 'casts "hello" to nil' do
232
255
  Morpheus::TypeCaster.cast('hello', :time).should eql(nil)
233
256
  end
234
257
 
235
- it "casts '2011-04-10' to Time" do
258
+ it 'casts "2011-04-10" to Time' do
236
259
  Morpheus::TypeCaster.cast('2011-04-10', :time).should eql('2011-04-10'.to_time)
237
260
  end
238
261
 
239
- it "cast '3' to nil" do
262
+ it 'cast "3" to nil' do
240
263
  Morpheus::TypeCaster.cast('3', :time).should eql(nil)
241
264
  end
242
265
 
243
- it "casts '10-04-2011T05:00:00Z' to Time" do
266
+ it 'casts "10-04-2011T05:00:00Z" to Time' do
244
267
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :time).should eql(Time.parse('10-04-2011T05:00:00Z'))
245
268
  end
246
269
 
247
- it "casts 'true' to nil" do
270
+ it 'casts "true" to nil' do
248
271
  Morpheus::TypeCaster.cast('true', :time).should eql(nil)
249
272
  end
250
273
 
251
- it "casts 4 to nil" do
274
+ it 'casts 4 to nil' do
252
275
  Morpheus::TypeCaster.cast(4, :time).should eql(nil)
253
276
  end
254
277
 
255
- it "casts true to nil" do
278
+ it 'casts true to nil' do
256
279
  Morpheus::TypeCaster.cast(true, :time).should eql(nil)
257
280
  end
258
281
 
259
- it "cast DateTime to Time" do
282
+ it 'cast DateTime to Time' do
260
283
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :time).should eql(Time.parse('10-04-2011T05:00:00Z'))
261
284
  end
262
285
 
263
- it "casts Date to Time" do
286
+ it 'casts Date to Time' do
264
287
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :time).should eql(Time.parse('2011-04-10'))
265
288
  end
266
289
 
267
- it "casts Time to Time" do
290
+ it 'casts Time to Time' do
268
291
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :time).should eql(Time.parse('10-04-2011T05:00:00Z'))
269
292
  end
270
-
271
293
  end
272
294
 
273
- context "when the type_class is a boolean" do
274
-
275
- it "casts 'hello' to true" do
295
+ context '#parse_boolean' do
296
+ it 'casts "hello" to true' do
276
297
  Morpheus::TypeCaster.cast('hello', :boolean).should eql(true)
277
298
  end
278
299
 
279
- it "casts '2011-04-10' to true" do
300
+ it 'casts "2011-04-10" to true' do
280
301
  Morpheus::TypeCaster.cast('2011-04-10', :boolean).should eql(true)
281
302
  end
282
303
 
283
- it "cast '3' to true" do
304
+ it 'cast "3" to true' do
284
305
  Morpheus::TypeCaster.cast('3', :boolean).should eql(true)
285
306
  end
286
307
 
287
- it "casts '10-04-2011T05:00:00Z' to true" do
308
+ it 'casts "10-04-2011T05:00:00Z" to true' do
288
309
  Morpheus::TypeCaster.cast('10-04-2011T05:00:00Z', :boolean).should eql(true)
289
310
  end
290
311
 
291
- it "casts 'true' to true" do
312
+ it 'casts "true" to true' do
292
313
  Morpheus::TypeCaster.cast('true', :boolean).should eql(true)
293
314
  end
294
315
 
295
- it "casts 4 to true" do
316
+ it 'casts 4 to true' do
296
317
  Morpheus::TypeCaster.cast(4, :boolean).should eql(true)
297
318
  end
298
319
 
299
- it "casts true to true" do
320
+ it 'casts true to true' do
300
321
  Morpheus::TypeCaster.cast(true, :boolean).should eql(true)
301
322
  end
302
323
 
303
- it "casts nil to false" do
324
+ it 'casts nil to false' do
304
325
  Morpheus::TypeCaster.cast(nil, :boolean).should eql(false)
305
326
  end
306
327
 
307
- it "casts 'false' to false" do
328
+ it 'casts "false" to false' do
308
329
  Morpheus::TypeCaster.cast('false', :boolean).should eql(false)
309
330
  end
310
331
 
311
- it "casts 1 to true" do
332
+ it 'casts 1 to true' do
312
333
  Morpheus::TypeCaster.cast(1, :boolean).should eql(true)
313
334
  end
314
335
 
315
- it "casts '0' to false" do
336
+ it 'casts "0" to false' do
316
337
  Morpheus::TypeCaster.cast('0', :boolean).should eql(false)
317
338
  end
318
339
 
319
- it "cast DateTime to true" do
340
+ it 'cast DateTime to true' do
320
341
  Morpheus::TypeCaster.cast(DateTime.parse('10-04-2011T05:00:00Z'), :boolean).should eql(true)
321
342
  end
322
343
 
323
- it "casts Date to true" do
344
+ it 'casts Date to true' do
324
345
  Morpheus::TypeCaster.cast(Date.parse('2011-04-10'), :boolean).should eql(true)
325
346
  end
326
347
 
327
- it "casts Time to true" do
348
+ it 'casts Time to true' do
328
349
  Morpheus::TypeCaster.cast(Time.parse('10-04-2011T05:00:00Z'), :boolean).should eql(true)
329
350
  end
330
-
331
- end
332
-
333
- context "when the type_class is unknown" do
334
-
335
- it "raises an error" do
336
- lambda {
337
- Morpheus::TypeCaster.cast(nil, :made_up_class)
338
- }.should raise_error(Morpheus::UnrecognizedTypeCastClass, "Can't typecast to made_up_class!")
339
- end
340
-
341
351
  end
342
352
 
343
353
  end