morpheus 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +12 -0
- data/.rspec +1 -0
- data/README.md +77 -0
- data/Rakefile +16 -0
- data/lib/morpheus.rb +2 -2
- data/lib/morpheus/base.rb +1 -1
- data/lib/morpheus/client/inflections.rb +1 -1
- data/lib/morpheus/configuration.rb +41 -43
- data/lib/morpheus/errors.rb +1 -1
- data/lib/morpheus/mixins/associations.rb +3 -1
- data/lib/morpheus/mixins/attributes.rb +66 -67
- data/lib/morpheus/mixins/conversion.rb +9 -13
- data/lib/morpheus/mixins/filtering.rb +4 -1
- data/lib/morpheus/mixins/finders.rb +4 -1
- data/lib/morpheus/mixins/introspection.rb +12 -16
- data/lib/morpheus/mixins/persistence.rb +25 -26
- data/lib/morpheus/mixins/reflections.rb +4 -1
- data/lib/morpheus/mixins/request_handling.rb +4 -1
- data/lib/morpheus/mixins/response_parsing.rb +12 -12
- data/lib/morpheus/mixins/url_support.rb +4 -1
- data/lib/morpheus/request.rb +34 -34
- data/lib/morpheus/response.rb +2 -2
- data/lib/morpheus/response_parser.rb +9 -4
- data/lib/morpheus/version.rb +1 -1
- data/morpheus.gemspec +4 -4
- data/spec/dummy/app/resources/author.rb +0 -1
- data/spec/dummy/app/resources/book.rb +0 -1
- data/spec/dummy/app/resources/dog.rb +3 -3
- data/spec/dummy/app/resources/meeting.rb +1 -2
- data/spec/dummy/config/application.rb +7 -36
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/initializers/morpheus.rb +1 -1
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +0 -56
- data/spec/morpheus/associations/association_spec.rb +51 -33
- data/spec/morpheus/associations/belongs_to_association_spec.rb +14 -2
- data/spec/morpheus/associations/has_many_association_spec.rb +31 -11
- data/spec/morpheus/associations/has_one_association_spec.rb +14 -2
- data/spec/morpheus/base_spec.rb +104 -100
- data/spec/morpheus/client/associations_spec.rb +43 -36
- data/spec/morpheus/client/log_subscriber_spec.rb +33 -0
- data/spec/morpheus/client/railtie_spec.rb +5 -0
- data/spec/morpheus/configuration_spec.rb +92 -113
- data/spec/morpheus/mixins/associations_spec.rb +90 -108
- data/spec/morpheus/mixins/attributes_spec.rb +71 -77
- data/spec/morpheus/mixins/conversion_spec.rb +49 -59
- data/spec/morpheus/mixins/filtering_spec.rb +13 -0
- data/spec/morpheus/mixins/finders_spec.rb +180 -217
- data/spec/morpheus/mixins/introspection_spec.rb +81 -124
- data/spec/morpheus/mixins/persistence_spec.rb +140 -133
- data/spec/morpheus/mixins/{reflection_spec.rb → reflections_spec.rb} +28 -28
- data/spec/morpheus/mixins/request_handling_spec.rb +21 -0
- data/spec/morpheus/mixins/response_parsing_spec.rb +10 -2
- data/spec/morpheus/mixins/url_support_spec.rb +29 -0
- data/spec/morpheus/reflection_spec.rb +21 -0
- data/spec/morpheus/relation_spec.rb +34 -58
- data/spec/morpheus/request_cache_spec.rb +33 -2
- data/spec/morpheus/request_queue_spec.rb +37 -0
- data/spec/morpheus/request_spec.rb +102 -1
- data/spec/morpheus/response_parser_spec.rb +17 -0
- data/spec/morpheus/response_spec.rb +55 -51
- data/spec/morpheus/type_caster_spec.rb +128 -118
- data/spec/morpheus/url_builder_spec.rb +41 -0
- data/spec/shared/active_model_lint_test.rb +2 -2
- data/spec/spec_helper.rb +7 -14
- data/spec/support/configuration.rb +3 -4
- metadata +32 -16
- data/README.rdoc +0 -44
- data/autotest/discover.rb +0 -7
- data/lib/morpheus/mock.rb +0 -66
- data/spec/morpheus/mock_spec.rb +0 -133
@@ -1,72 +1,76 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Morpheus::Response
|
3
|
+
describe Morpheus::Response do
|
4
4
|
|
5
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
36
|
-
|
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
|
-
|
41
|
+
describe '#tag_for_caching!' do
|
42
|
+
pending
|
43
|
+
end
|
42
44
|
|
43
|
-
describe
|
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
|
-
|
51
|
-
|
52
|
-
@
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
3
|
+
describe Morpheus::TypeCaster do
|
4
4
|
|
5
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
15
|
+
it 'cast "3" to "3"' do
|
16
|
+
Morpheus::TypeCaster.cast('3', nil).should eql('3')
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
24
|
-
|
48
|
+
context 'when the typecast_class is String' do
|
49
|
+
pending
|
25
50
|
end
|
26
51
|
|
27
|
-
|
28
|
-
|
52
|
+
context 'when the typecast_class is Integer' do
|
53
|
+
pending
|
29
54
|
end
|
30
55
|
|
31
|
-
|
32
|
-
|
56
|
+
context 'when the typecast_class is DateTime' do
|
57
|
+
pending
|
33
58
|
end
|
34
59
|
|
35
|
-
|
36
|
-
|
60
|
+
context 'when the typecast_class is Date' do
|
61
|
+
pending
|
37
62
|
end
|
38
63
|
|
39
|
-
|
40
|
-
|
64
|
+
context 'when the typecast_class is Time' do
|
65
|
+
pending
|
41
66
|
end
|
42
67
|
|
43
|
-
|
44
|
-
|
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
|
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
|
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
|
90
|
+
it 'cast "3" to "3"' do
|
60
91
|
Morpheus::TypeCaster.cast('3', :string).should eql('3')
|
61
92
|
end
|
62
93
|
|
63
|
-
it
|
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
|
98
|
+
it 'casts "true" to "true"' do
|
68
99
|
Morpheus::TypeCaster.cast('true', :string).should eql('true')
|
69
100
|
end
|
70
101
|
|
71
|
-
it
|
102
|
+
it 'casts 4 to "4"' do
|
72
103
|
Morpheus::TypeCaster.cast(4, :string).should eql('4')
|
73
104
|
end
|
74
105
|
|
75
|
-
it
|
106
|
+
it 'casts true to "true"' do
|
76
107
|
Morpheus::TypeCaster.cast(true, :string).should eql('true')
|
77
108
|
end
|
78
109
|
|
79
|
-
it
|
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
|
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
|
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
|
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
|
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
|
132
|
+
it 'cast "3" to 3' do
|
104
133
|
Morpheus::TypeCaster.cast('3', :integer).should eql(3)
|
105
134
|
end
|
106
135
|
|
107
|
-
it
|
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
|
140
|
+
it 'casts "true" to 0' do
|
112
141
|
Morpheus::TypeCaster.cast('true', :integer).should eql(0)
|
113
142
|
end
|
114
143
|
|
115
|
-
it
|
144
|
+
it 'casts 4 to 4' do
|
116
145
|
Morpheus::TypeCaster.cast(4, :integer).should eql(4)
|
117
146
|
end
|
118
147
|
|
119
|
-
it
|
148
|
+
it 'casts true to 1' do
|
120
149
|
Morpheus::TypeCaster.cast(true, :integer).should eql(1)
|
121
150
|
end
|
122
151
|
|
123
|
-
it
|
152
|
+
it 'casts false to 0' do
|
124
153
|
Morpheus::TypeCaster.cast(false, :integer).should eql(0)
|
125
154
|
end
|
126
155
|
|
127
|
-
it
|
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
|
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
|
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
|
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
|
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 "
|
178
|
+
it 'casts "3" to nil' do
|
152
179
|
Morpheus::TypeCaster.cast('3', :datetime).should eql(nil)
|
153
180
|
end
|
154
181
|
|
155
|
-
it
|
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
|
186
|
+
it 'casts "true" to nil' do
|
160
187
|
Morpheus::TypeCaster.cast('true', :datetime).should eql(nil)
|
161
188
|
end
|
162
189
|
|
163
|
-
it
|
190
|
+
it 'casts 4 to nil' do
|
164
191
|
Morpheus::TypeCaster.cast(4, :datetime).should eql(nil)
|
165
192
|
end
|
166
193
|
|
167
|
-
it
|
194
|
+
it 'casts true to nil' do
|
168
195
|
Morpheus::TypeCaster.cast(true, :datetime).should eql(nil)
|
169
196
|
end
|
170
197
|
|
171
|
-
it
|
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
|
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
|
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
|
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
|
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
|
220
|
+
it 'cast "3" to nil' do
|
196
221
|
Morpheus::TypeCaster.cast('3', :date).should eql(nil)
|
197
222
|
end
|
198
223
|
|
199
|
-
it
|
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
|
228
|
+
it 'casts "true" to nil' do
|
204
229
|
Morpheus::TypeCaster.cast('true', :date).should eql(nil)
|
205
230
|
end
|
206
231
|
|
207
|
-
it
|
232
|
+
it 'casts 4 to nil' do
|
208
233
|
Morpheus::TypeCaster.cast(4, :date).should eql(nil)
|
209
234
|
end
|
210
235
|
|
211
|
-
it
|
236
|
+
it 'casts true to nil' do
|
212
237
|
Morpheus::TypeCaster.cast(true, :date).should eql(nil)
|
213
238
|
end
|
214
239
|
|
215
|
-
it
|
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
|
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
|
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
|
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
|
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
|
262
|
+
it 'cast "3" to nil' do
|
240
263
|
Morpheus::TypeCaster.cast('3', :time).should eql(nil)
|
241
264
|
end
|
242
265
|
|
243
|
-
it
|
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
|
270
|
+
it 'casts "true" to nil' do
|
248
271
|
Morpheus::TypeCaster.cast('true', :time).should eql(nil)
|
249
272
|
end
|
250
273
|
|
251
|
-
it
|
274
|
+
it 'casts 4 to nil' do
|
252
275
|
Morpheus::TypeCaster.cast(4, :time).should eql(nil)
|
253
276
|
end
|
254
277
|
|
255
|
-
it
|
278
|
+
it 'casts true to nil' do
|
256
279
|
Morpheus::TypeCaster.cast(true, :time).should eql(nil)
|
257
280
|
end
|
258
281
|
|
259
|
-
it
|
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
|
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
|
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
|
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
|
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
|
304
|
+
it 'cast "3" to true' do
|
284
305
|
Morpheus::TypeCaster.cast('3', :boolean).should eql(true)
|
285
306
|
end
|
286
307
|
|
287
|
-
it
|
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
|
312
|
+
it 'casts "true" to true' do
|
292
313
|
Morpheus::TypeCaster.cast('true', :boolean).should eql(true)
|
293
314
|
end
|
294
315
|
|
295
|
-
it
|
316
|
+
it 'casts 4 to true' do
|
296
317
|
Morpheus::TypeCaster.cast(4, :boolean).should eql(true)
|
297
318
|
end
|
298
319
|
|
299
|
-
it
|
320
|
+
it 'casts true to true' do
|
300
321
|
Morpheus::TypeCaster.cast(true, :boolean).should eql(true)
|
301
322
|
end
|
302
323
|
|
303
|
-
it
|
324
|
+
it 'casts nil to false' do
|
304
325
|
Morpheus::TypeCaster.cast(nil, :boolean).should eql(false)
|
305
326
|
end
|
306
327
|
|
307
|
-
it
|
328
|
+
it 'casts "false" to false' do
|
308
329
|
Morpheus::TypeCaster.cast('false', :boolean).should eql(false)
|
309
330
|
end
|
310
331
|
|
311
|
-
it
|
332
|
+
it 'casts 1 to true' do
|
312
333
|
Morpheus::TypeCaster.cast(1, :boolean).should eql(true)
|
313
334
|
end
|
314
335
|
|
315
|
-
it
|
336
|
+
it 'casts "0" to false' do
|
316
337
|
Morpheus::TypeCaster.cast('0', :boolean).should eql(false)
|
317
338
|
end
|
318
339
|
|
319
|
-
it
|
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
|
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
|
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
|