morpheus 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.rvmrc +1 -0
  2. data/Gemfile +21 -0
  3. data/Gemfile.lock +134 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +44 -0
  6. data/Rakefile +48 -0
  7. data/VERSION +1 -0
  8. data/autotest/discover.rb +7 -0
  9. data/lib/ext/typhoeus.rb +37 -0
  10. data/lib/morpheus/associations/association.rb +110 -0
  11. data/lib/morpheus/associations/belongs_to_association.rb +45 -0
  12. data/lib/morpheus/associations/has_many_association.rb +70 -0
  13. data/lib/morpheus/associations/has_one_association.rb +46 -0
  14. data/lib/morpheus/base.rb +66 -0
  15. data/lib/morpheus/client/associations.rb +47 -0
  16. data/lib/morpheus/client/inflections.rb +3 -0
  17. data/lib/morpheus/client/log_subscriber.rb +64 -0
  18. data/lib/morpheus/client/railtie.rb +25 -0
  19. data/lib/morpheus/configuration.rb +49 -0
  20. data/lib/morpheus/errors.rb +32 -0
  21. data/lib/morpheus/filter.rb +18 -0
  22. data/lib/morpheus/mixins/associations.rb +55 -0
  23. data/lib/morpheus/mixins/attributes.rb +133 -0
  24. data/lib/morpheus/mixins/conversion.rb +21 -0
  25. data/lib/morpheus/mixins/filtering.rb +18 -0
  26. data/lib/morpheus/mixins/finders.rb +58 -0
  27. data/lib/morpheus/mixins/introspection.rb +25 -0
  28. data/lib/morpheus/mixins/persistence.rb +46 -0
  29. data/lib/morpheus/mixins/reflections.rb +24 -0
  30. data/lib/morpheus/mixins/request_handling.rb +34 -0
  31. data/lib/morpheus/mixins/response_parsing.rb +27 -0
  32. data/lib/morpheus/mixins/url_support.rb +36 -0
  33. data/lib/morpheus/mock.rb +66 -0
  34. data/lib/morpheus/reflection.rb +22 -0
  35. data/lib/morpheus/relation.rb +57 -0
  36. data/lib/morpheus/request.rb +41 -0
  37. data/lib/morpheus/request_cache.rb +18 -0
  38. data/lib/morpheus/request_queue.rb +44 -0
  39. data/lib/morpheus/response.rb +24 -0
  40. data/lib/morpheus/response_parser.rb +80 -0
  41. data/lib/morpheus/type_caster.rb +80 -0
  42. data/lib/morpheus/url_builder.rb +52 -0
  43. data/lib/morpheus.rb +64 -0
  44. data/morpheus.gemspec +191 -0
  45. data/spec/dummy/Rakefile +7 -0
  46. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  47. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  48. data/spec/dummy/app/models/purchase.rb +3 -0
  49. data/spec/dummy/app/resources/attendee.rb +2 -0
  50. data/spec/dummy/app/resources/author.rb +5 -0
  51. data/spec/dummy/app/resources/automobile.rb +6 -0
  52. data/spec/dummy/app/resources/book.rb +5 -0
  53. data/spec/dummy/app/resources/conference.rb +3 -0
  54. data/spec/dummy/app/resources/dog.rb +10 -0
  55. data/spec/dummy/app/resources/item.rb +5 -0
  56. data/spec/dummy/app/resources/meeting.rb +7 -0
  57. data/spec/dummy/app/resources/speaker.rb +3 -0
  58. data/spec/dummy/app/resources/state.rb +5 -0
  59. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  60. data/spec/dummy/config/application.rb +45 -0
  61. data/spec/dummy/config/boot.rb +10 -0
  62. data/spec/dummy/config/database.yml +22 -0
  63. data/spec/dummy/config/environment.rb +5 -0
  64. data/spec/dummy/config/environments/development.rb +26 -0
  65. data/spec/dummy/config/environments/production.rb +49 -0
  66. data/spec/dummy/config/environments/test.rb +35 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/inflections.rb +10 -0
  69. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  70. data/spec/dummy/config/initializers/morpheus.rb +3 -0
  71. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  72. data/spec/dummy/config/initializers/session_store.rb +8 -0
  73. data/spec/dummy/config/locales/en.yml +5 -0
  74. data/spec/dummy/config/routes.rb +58 -0
  75. data/spec/dummy/config.ru +4 -0
  76. data/spec/dummy/db/migrate/20110605002144_create_purchases.rb +13 -0
  77. data/spec/dummy/db/test.sqlite3 +0 -0
  78. data/spec/dummy/public/404.html +26 -0
  79. data/spec/dummy/public/422.html +26 -0
  80. data/spec/dummy/public/500.html +26 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  83. data/spec/dummy/script/rails +6 -0
  84. data/spec/morpheus/associations/association_spec.rb +44 -0
  85. data/spec/morpheus/associations/belongs_to_association_spec.rb +5 -0
  86. data/spec/morpheus/associations/has_many_association_spec.rb +17 -0
  87. data/spec/morpheus/associations/has_one_association_spec.rb +5 -0
  88. data/spec/morpheus/base_spec.rb +126 -0
  89. data/spec/morpheus/client/associations_spec.rb +44 -0
  90. data/spec/morpheus/configuration_spec.rb +136 -0
  91. data/spec/morpheus/mixins/associations_spec.rb +141 -0
  92. data/spec/morpheus/mixins/attributes_spec.rb +99 -0
  93. data/spec/morpheus/mixins/conversion_spec.rb +76 -0
  94. data/spec/morpheus/mixins/finders_spec.rb +255 -0
  95. data/spec/morpheus/mixins/introspection_spec.rb +154 -0
  96. data/spec/morpheus/mixins/persistence_spec.rb +161 -0
  97. data/spec/morpheus/mixins/reflection_spec.rb +100 -0
  98. data/spec/morpheus/mixins/response_parsing_spec.rb +5 -0
  99. data/spec/morpheus/mock_spec.rb +133 -0
  100. data/spec/morpheus/relation_spec.rb +71 -0
  101. data/spec/morpheus/request_cache_spec.rb +5 -0
  102. data/spec/morpheus/request_spec.rb +5 -0
  103. data/spec/morpheus/response_spec.rb +73 -0
  104. data/spec/morpheus/type_caster_spec.rb +343 -0
  105. data/spec/shared/active_model_lint_test.rb +14 -0
  106. data/spec/spec_helper.rb +32 -0
  107. data/spec/support/configuration.rb +26 -0
  108. metadata +427 -0
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Attributes, "#property" do
4
+
5
+ it "defines setter and getter methods for the given property" do
6
+ @book = Book.new
7
+ @book.should respond_to(:title)
8
+ @book.title = "Test Title"
9
+ @book.title.should eql("Test Title")
10
+ end
11
+
12
+ it "creates an attribute entry for this property" do
13
+ Book.new.attributes.should include(:title)
14
+ end
15
+
16
+ end
17
+
18
+ describe Morpheus::Attributes, "#default_attributes" do
19
+
20
+ it "returns the default attributes has which will be applied as the attributes when a new object is instantiated" do
21
+ Book.default_attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
22
+ end
23
+
24
+ end
25
+
26
+ describe Morpheus::Attributes, "#typecast_attributes" do
27
+ pending
28
+ end
29
+
30
+ describe Morpheus::Attributes, "#attribute_defined?" do
31
+ pending
32
+ end
33
+
34
+ describe Morpheus::Attributes, ".attributes" do
35
+
36
+ it "returns the attributes hash" do
37
+ Book.new.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :title => nil, :author_id => nil }))
38
+ end
39
+
40
+ end
41
+
42
+ describe Morpheus::Attributes, ".read_attribute_for_validation" do
43
+ pending
44
+ end
45
+
46
+ describe Morpheus::Attributes, ".typecast" do
47
+ pending
48
+ end
49
+
50
+ describe Morpheus::Attributes, ".attributes_without_id" do
51
+ pending
52
+ end
53
+
54
+ describe Morpheus::Attributes, ".update_attribute" do
55
+
56
+ it "updates the attribute with the given value" do
57
+ @book = Book.new(:title => "Horton Hears a Who")
58
+ @book.title.should eql("Horton Hears a Who")
59
+ @book.update_attribute(:title, "Red Fish, Blue Fish, One Fish, Two Fish")
60
+ @book.title.should eql("Red Fish, Blue Fish, One Fish, Two Fish")
61
+ end
62
+
63
+ end
64
+
65
+ describe Morpheus::Attributes, ".merge_attributes" do
66
+
67
+ it "updates each attribute with the given value" do
68
+ @book = Book.new(:title => "Green Eggs and Ham")
69
+ @book.id.should be_nil
70
+ @book.title.should eql("Green Eggs and Ham")
71
+ @book.send(:merge_attributes, { :title => "Red Fish, Blue Fish, One Fish, Two Fish", :id => 5 })
72
+ @book.id.should eql(5)
73
+ @book.title.should eql("Red Fish, Blue Fish, One Fish, Two Fish")
74
+ end
75
+
76
+ end
77
+
78
+ describe Morpheus::Attributes, "dirty tracking" do
79
+
80
+ it "includes the ActiveModel::Validations module" do
81
+ Morpheus::Base.included_modules.should include(ActiveModel::Dirty)
82
+ end
83
+
84
+ it "tracks dirty state for property values" do
85
+ @book = Book.new
86
+ @book.should_not be_title_changed
87
+ @book.title = "Dirty title"
88
+ @book.should be_title_changed
89
+ end
90
+
91
+ end
92
+
93
+ describe Morpheus::Attributes, "validations" do
94
+
95
+ it "includes the ActiveModel::Validations module" do
96
+ Morpheus::Base.included_modules.should include(ActiveModel::Validations)
97
+ end
98
+
99
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Conversion, ".to_model" do
4
+
5
+ before(:each) do
6
+ @dog = Dog.new
7
+ end
8
+
9
+ it "returns this object" do
10
+ @dog.to_model.should eql(@dog)
11
+ end
12
+
13
+ end
14
+
15
+ describe Morpheus::Conversion, ".to_param" do
16
+
17
+ context "when the id attribute is set" do
18
+
19
+ before(:each) do
20
+ Morpheus::Base.stub(:get).and_return(Morpheus::Base.new(:id => 1))
21
+ @base = Morpheus::Base.find(1)
22
+ end
23
+
24
+ it "returns the id as a string" do
25
+ @base.to_param.should eql("1")
26
+ end
27
+
28
+ end
29
+
30
+ context "when the id attribute is set" do
31
+
32
+ before(:each) do
33
+ @base = Morpheus::Base.new
34
+ end
35
+
36
+ it "returns the id as a string" do
37
+ @base.to_param.should be_nil
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ describe Morpheus::Conversion, ".to_key" do
45
+
46
+ context "when the object is a new record" do
47
+
48
+ before(:each) do
49
+ @dog = Dog.new(:name => "Daisy", :breed => "English Bulldog", :age => 2)
50
+ end
51
+
52
+ it "returns nil" do
53
+ @dog.to_key.should be_nil
54
+ end
55
+
56
+ end
57
+
58
+ context "when the object is persisted" do
59
+
60
+ before(:each) do
61
+ Dog.stub(:get).and_return(Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog", :age => 2))
62
+ @dog = Dog.find(1)
63
+ end
64
+
65
+ it "returns the attribute keys of the object" do
66
+ @keys = @dog.to_key
67
+ @keys.should have(4).keys
68
+ @keys.should include('id')
69
+ @keys.should include('name')
70
+ @keys.should include('breed')
71
+ @keys.should include('age')
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,255 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morpheus::Finders, "#find" do
4
+
5
+ context "when the argument is a single integer" do
6
+
7
+ context "when this record exists on the external service" do
8
+
9
+ before(:each) do
10
+ @dog = Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog")
11
+ Dog.stub(:get).and_return(@dog)
12
+ end
13
+
14
+ it "makes a request to /dogs/1 at the external service" do
15
+ Dog.should_receive(:get).with("/dogs/1", nil, { :id => 1 }).and_return(@dog)
16
+ Dog.find(1)
17
+ end
18
+
19
+ it "returns the instance representing this found record" do
20
+ @dog = Dog.find(1)
21
+ @dog.should be_a(Dog)
22
+ @dog.id.should eql(1)
23
+ @dog.name.should eql("Daisy")
24
+ @dog.breed.should eql("English Bulldog")
25
+ end
26
+
27
+ end
28
+
29
+ context "when this record does not exist on the external service" do
30
+
31
+ before(:each) do
32
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs/1").and_return(build_morpheus_response(404, nil))
33
+ end
34
+
35
+ it "raises a ResourceNotFound error" do
36
+ lambda { Dog.find(1) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find Dog with ID=1")
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ context "when the argument is a single array" do
44
+
45
+ context "when all records exists on the external service" do
46
+
47
+ before(:each) do
48
+ @dogs = [
49
+ Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
50
+ Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
51
+ Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
52
+ ]
53
+ Dog.stub(:get).and_return(@dogs)
54
+ end
55
+
56
+ it "makes a request to /dogs?ids=1,2,3 at the external service" do
57
+ Dog.should_receive(:get).with("/dogs", { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
58
+ Dog.find([1,2,3])
59
+ end
60
+
61
+ it "returns an array of instances representing these found records" do
62
+ @dogs = Dog.find([1,2,3])
63
+ @dogs.should be_an(Array)
64
+ @dogs.should have(3).dogs
65
+ @dogs.each do |dog|
66
+ dog.should be_a(Dog)
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ context "when there is a requested record that does not exist on the external service" do
73
+
74
+ before(:each) do
75
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3").and_return(build_morpheus_response(404, nil))
76
+ end
77
+
78
+ it "raises a ResourceNotFound error" do
79
+ lambda { Dog.find([1,2,3]) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ context "when there are multiple arguments, each being an integer" do
87
+
88
+ context "when all records exists on the external service" do
89
+
90
+ before(:each) do
91
+ @dogs = [
92
+ Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
93
+ Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
94
+ Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
95
+ ]
96
+ Dog.stub(:get).and_return(@dogs)
97
+ end
98
+
99
+ it "makes a request to /dogs?ids=1,2,3 at the external service" do
100
+ Dog.should_receive(:get).with("/dogs", { :ids => [1,2,3] }, { :ids => [1,2,3] }).and_return(@dogs)
101
+ Dog.find(1,2,3)
102
+ end
103
+
104
+ it "returns an array of instances representing these found records" do
105
+ @dogs = Dog.find(1,2,3)
106
+ @dogs.should be_an(Array)
107
+ @dogs.should have(3).dogs
108
+ @dogs.each do |dog|
109
+ dog.should be_a(Dog)
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ context "when there is a requested record that does not exist on the external service" do
116
+
117
+ before(:each) do
118
+ Morpheus::Configuration.hydra.stub(:get, "#{Morpheus::Configuration.host}/dogs?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3").and_return(build_morpheus_response(404, nil))
119
+ end
120
+
121
+ it "raises a ResourceNotFound error" do
122
+ lambda { Dog.find(1,2,3) }.should raise_error(Morpheus::ResourceNotFound, "Couldn't find all Dogs with IDs (1, 2, 3)")
123
+ end
124
+
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+
131
+ describe Morpheus::Finders, "#all" do
132
+
133
+ before(:each) do
134
+ @dogs = [
135
+ Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog"),
136
+ Dog.new(:id => 2, :name => "Wilbur", :breed => "Hounddog"),
137
+ Dog.new(:id => 3, :name => "Fido", :breed => "Dalmatian")
138
+ ]
139
+ Dog.stub(:get).and_return(@dogs)
140
+ end
141
+
142
+ it "returns all found records" do
143
+ @dogs = Dog.all
144
+ @dogs.should be_an(Array)
145
+ @dogs.should have(3).dogs
146
+ @dogs.each do |dog|
147
+ dog.should be_a(Dog)
148
+ end
149
+ end
150
+
151
+ end
152
+
153
+ describe Morpheus::Finders, "#first" do
154
+
155
+ before(:each) do
156
+ @dogs = [Dog.new(:id => 1, :name => "Daisy", :breed => "English Bulldog")]
157
+ Dog.stub(:get).and_return(@dogs)
158
+ end
159
+
160
+ it "returns first found record" do
161
+ @dog = Dog.first
162
+ @dog.should be_a(Dog)
163
+ end
164
+
165
+ end
166
+
167
+ describe Morpheus::Finders, "#where" do
168
+
169
+ context "when the where attribute is an acceptable attribute" do
170
+
171
+ context "for a where clause with one attribute" do
172
+
173
+ before(:each) do
174
+ @dogs = [Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1)]
175
+ end
176
+
177
+ it "makes a request to find all records with the given query parameter" do
178
+ Dog.should_receive(:get).with("/dogs", { :name => "Daisy" }).and_return(@dogs)
179
+ Dog.where(:name => "Daisy").first
180
+ end
181
+
182
+ end
183
+
184
+ context "for a where clause with multiple attributes" do
185
+
186
+ before(:each) do
187
+ @dogs = [Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1)]
188
+ end
189
+
190
+ it "makes a request to find all records with the given query parameters" do
191
+ Dog.should_receive(:get).with("/dogs", { :breed => "English Bulldog", :name => "Daisy" }).and_return(@dogs)
192
+ Dog.where(:name => "Daisy", :breed => "English Bulldog").first
193
+ end
194
+
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+
201
+ describe Morpheus::Finders, "#limit" do
202
+
203
+ before(:each) do
204
+ @dogs = [
205
+ Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1),
206
+ Dog.new(:name => "Wilbur", :breed => "Hounddog").attributes.merge(:id => 2),
207
+ Dog.new(:name => "Fido", :breed => "Dalmatian").attributes.merge(:id => 3)
208
+ ]
209
+ end
210
+
211
+ it "makes a request to find all of the given records, but with a given limit" do
212
+ Dog.should_receive(:get).with("/dogs", { :limit => 10 }).and_return(@dogs)
213
+ Dog.limit(10).all
214
+ end
215
+
216
+ end
217
+
218
+ describe Morpheus::Finders, "#page" do
219
+
220
+ before(:each) do
221
+ Dog.results_per_page = 10
222
+
223
+ @dogs = [
224
+ Dog.new(:name => "Daisy", :breed => "English Bulldog").attributes.merge(:id => 1),
225
+ Dog.new(:name => "Wilbur", :breed => "Hounddog").attributes.merge(:id => 2),
226
+ Dog.new(:name => "Fido", :breed => "Dalmatian").attributes.merge(:id => 3)
227
+ ]
228
+ end
229
+
230
+ it "makes a request to find all of the given records, but with a given limit and offset" do
231
+ Dog.should_receive(:get).with("/dogs", { :limit => 10, :offset => 20 }).and_return(@dogs)
232
+ Dog.page(3).all
233
+ end
234
+
235
+ end
236
+
237
+ describe Morpheus::Finders, "#results_per_page" do
238
+
239
+ it "defaults to 10" do
240
+ Dog.results_per_page.should eql(10)
241
+ end
242
+
243
+ context "when set to something other than the default" do
244
+
245
+ before(:each) do
246
+ Dog.results_per_page = 25
247
+ end
248
+
249
+ it "returns the number of results to be returned on a page request" do
250
+ Dog.results_per_page.should eql(25)
251
+ end
252
+
253
+ end
254
+
255
+ end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
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
29
+
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
+
44
+ before(:each) do
45
+ stub_web!
46
+ @attendee.save
47
+ end
48
+
49
+ it "returns true" do
50
+ @attendee.should be_persisted
51
+ 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
+
66
+ end
67
+
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
78
+ end
79
+
80
+ end
81
+
82
+ context "when the record is not new" do
83
+
84
+ before(:each) do
85
+ stub_web!
86
+ @attendee.save
87
+ end
88
+
89
+ it "returns false" do
90
+ @attendee.should_not be_new_record
91
+ 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
+
108
+ describe Morpheus::Introspection, ".destroyed?" do
109
+
110
+ it "returns false" do
111
+ Dog.new.should_not be_destroyed
112
+ end
113
+
114
+ end
115
+
116
+ describe Morpheus::Introspection, ".respond_to?" do
117
+
118
+ before(:each) do
119
+ @dog = Dog.new(:name => "Fido", :age => 10)
120
+ end
121
+
122
+ context "if the query method is a method on the object" do
123
+
124
+ it "returns true" do
125
+ @dog.should respond_to(:bark!)
126
+ end
127
+
128
+ end
129
+
130
+ context "if the query method is not a method on the object" do
131
+
132
+ it "returns false" do
133
+ @dog.should_not respond_to(:bite!)
134
+ end
135
+
136
+ end
137
+
138
+ context "if the query method is an attribute on the object" do
139
+
140
+ it "returns true" do
141
+ @dog.should respond_to(:age)
142
+ end
143
+
144
+ end
145
+
146
+ context "if the query method is not an attribute on the object" do
147
+
148
+ it "returns false" do
149
+ @dog.should_not respond_to(:weight)
150
+ end
151
+
152
+ end
153
+
154
+ end