morpheus 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,154 +1,111 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Introspection, ".valid?" do
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
- before(:each) do
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
- stub_web!
46
- @attendee.save
7
+ @attendee = Attendee.new
47
8
  end
48
-
49
- it "returns true" do
50
- @attendee.should be_persisted
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
- end
16
+ context 'when the record is persisted' do
17
+ before(:each) do
18
+ stub_web!
19
+ @attendee.save
20
+ end
67
21
 
68
- describe Morpheus::Introspection, ".new_record?" do
69
-
70
- before(:each) do
71
- @attendee = Attendee.new
72
- end
73
-
74
- context "when the record is new" do
75
-
76
- it "returns true" do
77
- @attendee.should be_new_record
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
- context "when the record is not new" do
83
-
39
+
40
+ describe '#new_record?' do
84
41
  before(:each) do
85
- stub_web!
86
- @attendee.save
42
+ @attendee = Attendee.new
87
43
  end
88
-
89
- it "returns false" do
90
- @attendee.should_not be_new_record
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
- describe Morpheus::Introspection, ".destroyed?" do
51
+ context 'when the record is not new' do
52
+ before(:each) do
53
+ stub_web!
54
+ @attendee.save
55
+ end
109
56
 
110
- it "returns false" do
111
- Dog.new.should_not be_destroyed
112
- end
57
+ it 'returns false' do
58
+ @attendee.should_not be_new_record
59
+ end
60
+ end
113
61
 
114
- end
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
- it "returns true" do
125
- @dog.should respond_to(:bark!)
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
- it "returns false" do
133
- @dog.should_not respond_to(:bite!)
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
- it "returns true" do
141
- @dog.should respond_to(:age)
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
- it "returns false" do
149
- @dog.should_not respond_to(:weight)
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, "#save" do
4
-
5
- context "when the instance is a new record" do
6
-
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
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
- it "sets the errors hash based on the response" do
29
- @california.save
30
- @california.errors.should be_empty
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
- it "sets the valid? flag based on the response" do
34
- @california.save
35
- @california.should be_valid
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
- context "when the instance is not a new record" do
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 'has a new name attribute' do
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 'is still valid' do
70
- @state.should be_valid
71
- end
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
- describe Morpheus::Persistence, "#update_attributes" do
108
-
109
- before(:each) do
110
- stub_web!
111
- @state = State.new(
112
- :name => "California",
113
- :capital => "Sacramento",
114
- :motto => "Eureka!"
115
- )
116
- @state.save
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
- it "sets the attributes to their new values" do
120
- @state.update_attributes(:name => "Oregon", :capital => "Salem", :motto => "She flies with her own wings")
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
- it "calls .save on the record" do
127
- @state.should_receive(:save)
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
- def stub_web!
136
- Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/states").and_return(build_morpheus_response(
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