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.
- 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,154 +1,111 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Morpheus::Introspection
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@dog = Dog.new
|
7
|
-
end
|
8
|
-
|
9
|
-
context "when the errors hash is empty" do
|
10
|
-
|
11
|
-
it "returns true" do
|
12
|
-
@dog.name = "Fido"
|
13
|
-
@dog.should be_valid
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when the errors hash is not empty" do
|
19
|
-
|
20
|
-
it "returns false" do
|
21
|
-
@dog.should_not be_valid
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Morpheus::Introspection, ".persisted?" do
|
3
|
+
describe Morpheus::Introspection do
|
29
4
|
|
30
|
-
|
31
|
-
@attendee = Attendee.new
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when the record is not persisted" do
|
35
|
-
|
36
|
-
it "returns false" do
|
37
|
-
@attendee.should_not be_persisted
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when the record is persisted" do
|
43
|
-
|
5
|
+
describe '#persisted?' do
|
44
6
|
before(:each) do
|
45
|
-
|
46
|
-
@attendee.save
|
7
|
+
@attendee = Attendee.new
|
47
8
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
9
|
+
|
10
|
+
context 'when the record is not persisted' do
|
11
|
+
it 'returns false' do
|
12
|
+
@attendee.should_not be_persisted
|
13
|
+
end
|
51
14
|
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def stub_web!
|
56
|
-
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response(
|
57
|
-
201,
|
58
|
-
{
|
59
|
-
:id => 1,
|
60
|
-
:valid => true,
|
61
|
-
:errors => {}
|
62
|
-
}
|
63
|
-
))
|
64
|
-
end
|
65
15
|
|
66
|
-
|
16
|
+
context 'when the record is persisted' do
|
17
|
+
before(:each) do
|
18
|
+
stub_web!
|
19
|
+
@attendee.save
|
20
|
+
end
|
67
21
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
22
|
+
it 'returns true' do
|
23
|
+
@attendee.should be_persisted
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_web!
|
28
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response(
|
29
|
+
201,
|
30
|
+
{
|
31
|
+
:id => 1,
|
32
|
+
:valid => true,
|
33
|
+
:errors => {}
|
34
|
+
}
|
35
|
+
))
|
78
36
|
end
|
79
|
-
|
37
|
+
|
80
38
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
39
|
+
|
40
|
+
describe '#new_record?' do
|
84
41
|
before(:each) do
|
85
|
-
|
86
|
-
@attendee.save
|
42
|
+
@attendee = Attendee.new
|
87
43
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
44
|
+
|
45
|
+
context 'when the record is new' do
|
46
|
+
it 'returns true' do
|
47
|
+
@attendee.should be_new_record
|
48
|
+
end
|
91
49
|
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def stub_web!
|
96
|
-
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response(
|
97
|
-
201,
|
98
|
-
{
|
99
|
-
:id => 1,
|
100
|
-
:valid => true,
|
101
|
-
:errors => {}
|
102
|
-
}
|
103
|
-
))
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
50
|
|
108
|
-
|
51
|
+
context 'when the record is not new' do
|
52
|
+
before(:each) do
|
53
|
+
stub_web!
|
54
|
+
@attendee.save
|
55
|
+
end
|
109
56
|
|
110
|
-
|
111
|
-
|
112
|
-
|
57
|
+
it 'returns false' do
|
58
|
+
@attendee.should_not be_new_record
|
59
|
+
end
|
60
|
+
end
|
113
61
|
|
114
|
-
|
62
|
+
def stub_web!
|
63
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response(
|
64
|
+
201,
|
65
|
+
{
|
66
|
+
:id => 1,
|
67
|
+
:valid => true,
|
68
|
+
:errors => {}
|
69
|
+
}
|
70
|
+
))
|
71
|
+
end
|
115
72
|
|
116
|
-
describe Morpheus::Introspection, ".respond_to?" do
|
117
|
-
|
118
|
-
before(:each) do
|
119
|
-
@dog = Dog.new(:name => "Fido", :age => 10)
|
120
73
|
end
|
121
|
-
|
122
|
-
context "if the query method is a method on the object" do
|
123
74
|
|
124
|
-
|
125
|
-
|
75
|
+
describe '#destroyed?' do
|
76
|
+
it 'returns false' do
|
77
|
+
Dog.new.should_not be_destroyed
|
126
78
|
end
|
127
|
-
|
128
79
|
end
|
129
|
-
|
130
|
-
context "if the query method is not a method on the object" do
|
131
80
|
|
132
|
-
|
133
|
-
|
81
|
+
describe '#respond_to?' do
|
82
|
+
before(:each) do
|
83
|
+
@dog = Dog.new(:name => 'Fido', :age => 10)
|
134
84
|
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
context "if the query method is an attribute on the object" do
|
139
85
|
|
140
|
-
|
141
|
-
|
86
|
+
context 'if the query method is a method on the object' do
|
87
|
+
it 'returns true' do
|
88
|
+
@dog.should respond_to(:bark!)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'if the query method is not a method on the object' do
|
93
|
+
it 'returns false' do
|
94
|
+
@dog.should_not respond_to(:bite!)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'if the query method is an attribute on the object' do
|
99
|
+
it 'returns true' do
|
100
|
+
@dog.should respond_to(:age)
|
101
|
+
end
|
142
102
|
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
context "if the query method is not an attribute on the object" do
|
147
103
|
|
148
|
-
|
149
|
-
|
104
|
+
context 'if the query method is not an attribute on the object' do
|
105
|
+
it 'returns false' do
|
106
|
+
@dog.should_not respond_to(:weight)
|
107
|
+
end
|
150
108
|
end
|
151
|
-
|
152
109
|
end
|
153
110
|
|
154
111
|
end
|
@@ -1,44 +1,105 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Morpheus::Persistence
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
3
|
+
describe Morpheus::Persistence do
|
4
|
+
|
5
|
+
describe '#save' do
|
6
|
+
context 'when the instance is a new record' do
|
7
|
+
before(:each) do
|
8
|
+
stub_web!
|
9
|
+
@california = State.new(
|
10
|
+
:name => 'California',
|
11
|
+
:capital => 'Sacramento',
|
12
|
+
:motto => 'Eureka!'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'updates the attributes to match those returned in the response' do
|
17
|
+
@california.id.should be_nil
|
18
|
+
@california.save
|
19
|
+
@california.id.should eql(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'marks the instance as not new' do
|
23
|
+
@california.should be_new_record
|
24
|
+
@california.save
|
25
|
+
@california.should_not be_new_record
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the errors hash based on the response' do
|
29
|
+
@california.save
|
30
|
+
@california.errors.should be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sets the valid? flag based on the response' do
|
34
|
+
@california.save
|
35
|
+
@california.should be_valid
|
36
|
+
end
|
26
37
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
|
39
|
+
context 'when the instance is not a new record' do
|
40
|
+
before(:each) do
|
41
|
+
stub_web!
|
42
|
+
@state = State.new(
|
43
|
+
:name => 'California',
|
44
|
+
:capital => 'Sacramento',
|
45
|
+
:motto => 'Eureka!'
|
46
|
+
)
|
47
|
+
@state.save
|
48
|
+
@state.name = 'Oregon'
|
49
|
+
@state.capital = 'Salem'
|
50
|
+
@state.motto = 'She flies with her own wings'
|
51
|
+
@state.save
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has a new name attribute' do
|
55
|
+
@state.name.should eql('Oregon')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'has a new capital attribute' do
|
59
|
+
@state.capital.should eql('Salem')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has a new motto attribute' do
|
63
|
+
@state.motto.should eql('She flies with her own wings')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'is still valid' do
|
67
|
+
@state.should be_valid
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'still has no errors' do
|
71
|
+
@state.errors.should be_empty
|
72
|
+
end
|
31
73
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
74
|
+
|
75
|
+
def stub_web!
|
76
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states").and_return(build_morpheus_response(
|
77
|
+
201,
|
78
|
+
{
|
79
|
+
:id => 1,
|
80
|
+
:valid => true,
|
81
|
+
:errors => {},
|
82
|
+
:name => 'California',
|
83
|
+
:capital => 'Sacramento',
|
84
|
+
:motto => 'Eureka!'
|
85
|
+
}
|
86
|
+
))
|
87
|
+
|
88
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states/1").and_return(build_morpheus_response(
|
89
|
+
200,
|
90
|
+
{
|
91
|
+
:id => 1,
|
92
|
+
:valid => true,
|
93
|
+
:errors => {},
|
94
|
+
:name => 'Oregon',
|
95
|
+
:capital => 'Salem',
|
96
|
+
:motto => 'She flies with her own wings'
|
97
|
+
}
|
98
|
+
))
|
36
99
|
end
|
37
|
-
|
38
100
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
101
|
+
|
102
|
+
describe '#update_attributes' do
|
42
103
|
before(:each) do
|
43
104
|
stub_web!
|
44
105
|
@state = State.new(
|
@@ -47,115 +108,61 @@ describe Morpheus::Persistence, "#save" do
|
|
47
108
|
:motto => 'Eureka!'
|
48
109
|
)
|
49
110
|
@state.save
|
50
|
-
|
51
|
-
@state.name = 'Oregon'
|
52
|
-
@state.capital = 'Salem'
|
53
|
-
@state.motto = 'She flies with her own wings'
|
54
|
-
@state.save
|
55
111
|
end
|
56
|
-
|
57
|
-
it '
|
112
|
+
|
113
|
+
it 'sets the attributes to their new values' do
|
114
|
+
@state.update_attributes(:name => 'Oregon', :capital => 'Salem', :motto => 'She flies with her own wings')
|
58
115
|
@state.name.should eql('Oregon')
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'has a new capital attribute' do
|
62
116
|
@state.capital.should eql('Salem')
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'has a new motto attribute' do
|
66
117
|
@state.motto.should eql('She flies with her own wings')
|
67
118
|
end
|
68
|
-
|
69
|
-
it '
|
70
|
-
@state.
|
71
|
-
|
72
|
-
|
73
|
-
it 'still has no errors' do
|
74
|
-
@state.errors.should be_empty
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def stub_web!
|
80
|
-
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states").and_return(build_morpheus_response(
|
81
|
-
201,
|
82
|
-
{
|
83
|
-
:id => 1,
|
84
|
-
:valid => true,
|
85
|
-
:errors => {},
|
86
|
-
:name => 'California',
|
87
|
-
:capital => 'Sacramento',
|
88
|
-
:motto => 'Eureka!'
|
89
|
-
}
|
90
|
-
))
|
91
|
-
|
92
|
-
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states/1").and_return(build_morpheus_response(
|
93
|
-
200,
|
94
|
-
{
|
95
|
-
:id => 1,
|
96
|
-
:valid => true,
|
97
|
-
:errors => {},
|
119
|
+
|
120
|
+
it 'calls #save on the record' do
|
121
|
+
@state.should_receive(:save)
|
122
|
+
@state.update_attributes(
|
98
123
|
:name => 'Oregon',
|
99
124
|
:capital => 'Salem',
|
100
125
|
:motto => 'She flies with her own wings'
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
126
|
+
)
|
127
|
+
end
|
106
128
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
129
|
+
def stub_web!
|
130
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states").and_return(build_morpheus_response(
|
131
|
+
201,
|
132
|
+
{
|
133
|
+
:id => 1,
|
134
|
+
:valid => true,
|
135
|
+
:errors => {},
|
136
|
+
:name => 'California',
|
137
|
+
:capital => 'Sacramento',
|
138
|
+
:motto => 'Eureka!'
|
139
|
+
}
|
140
|
+
))
|
141
|
+
|
142
|
+
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states/1").and_return(build_morpheus_response(
|
143
|
+
200,
|
144
|
+
{
|
145
|
+
:id => 1,
|
146
|
+
:valid => true,
|
147
|
+
:errors => {},
|
148
|
+
:name => 'Oregon',
|
149
|
+
:capital => 'Salem',
|
150
|
+
:motto => 'She flies with her own wings'
|
151
|
+
}
|
152
|
+
))
|
153
|
+
end
|
117
154
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
@state.name.should eql("Oregon")
|
122
|
-
@state.capital.should eql("Salem")
|
123
|
-
@state.motto.should eql("She flies with her own wings")
|
155
|
+
|
156
|
+
describe '#destroy' do
|
157
|
+
pending
|
124
158
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
@state.update_attributes(
|
129
|
-
:name => 'Oregon',
|
130
|
-
:capital => 'Salem',
|
131
|
-
:motto => 'She flies with her own wings'
|
132
|
-
)
|
159
|
+
|
160
|
+
describe '.create' do
|
161
|
+
pending
|
133
162
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
201,
|
138
|
-
{
|
139
|
-
:id => 1,
|
140
|
-
:valid => true,
|
141
|
-
:errors => {},
|
142
|
-
:name => 'California',
|
143
|
-
:capital => 'Sacramento',
|
144
|
-
:motto => 'Eureka!'
|
145
|
-
}
|
146
|
-
))
|
147
|
-
|
148
|
-
Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states/1").and_return(build_morpheus_response(
|
149
|
-
200,
|
150
|
-
{
|
151
|
-
:id => 1,
|
152
|
-
:valid => true,
|
153
|
-
:errors => {},
|
154
|
-
:name => 'Oregon',
|
155
|
-
:capital => 'Salem',
|
156
|
-
:motto => 'She flies with her own wings'
|
157
|
-
}
|
158
|
-
))
|
163
|
+
|
164
|
+
describe '.create!' do
|
165
|
+
pending
|
159
166
|
end
|
160
|
-
|
167
|
+
|
161
168
|
end
|