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,3 +1,3 @@
1
- Morpheus::Configuration.host = "http://localhost:3002"
1
+ Morpheus::Configuration.host = 'http://localhost:3002'
2
2
  Morpheus::Configuration.logger = Rails.logger
3
3
  Morpheus::Configuration.allow_net_connect = false
@@ -2,4 +2,4 @@
2
2
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
- hello: "Hello world"
5
+ hello: 'Hello world'
@@ -1,58 +1,2 @@
1
1
  Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
4
-
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => "welcome#index"
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id(.:format)))'
58
2
  end
@@ -1,44 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Associations::Association, ".id" do
4
-
5
- before(:each) do
6
- meeting = Meeting.new(:id => 5, :title => "Rails Development")
7
- Meeting.stub(:get).and_return(meeting)
8
- end
9
-
10
- it "calls the loaded target and retrieves it's id" do
11
- @speaker = Speaker.new(:meeting_id => 5)
12
- @speaker.meeting.id.should eql(5)
13
- end
14
-
15
- end
3
+ describe Morpheus::Associations::Association do
16
4
 
17
- describe Morpheus::Associations::Association, ".loaded_target" do
18
-
19
- before(:each) do
20
- @meeting = Meeting.new(:id => 5, :title => "Rails Development")
5
+ describe '#initialize' do
6
+ pending
21
7
  end
22
-
23
- it "loads target only once" do
24
- Meeting.should_receive(:get).once.and_return(@meeting)
25
- @speaker = Speaker.new(:meeting_id => 5)
26
- @speaker.meeting.id
27
- @speaker.meeting.id
8
+
9
+ describe '#id' do
10
+ before(:each) do
11
+ meeting = Meeting.new(:id => 5, :title => 'Rails Development')
12
+ Meeting.stub(:get).and_return(meeting)
13
+ end
14
+
15
+ it 'calls the loaded target and retrieves the id' do
16
+ @speaker = Speaker.new(:meeting_id => 5)
17
+ @speaker.meeting.id.should eql(5)
18
+ end
19
+ end
20
+
21
+ describe '#nil?' do
22
+ pending
23
+ end
24
+
25
+ describe '#to_param' do
26
+ pending
28
27
  end
29
-
30
- end
31
28
 
32
- describe Morpheus::Associations::Association, ".method_missing" do
29
+ describe '#try' do
30
+ pending
31
+ end
33
32
 
34
- before(:each) do
35
- meeting = Meeting.new(:id => 5, :title => "Rails Development")
36
- Meeting.stub(:get).and_return(meeting)
33
+ describe '#includes' do
34
+ pending
37
35
  end
38
-
39
- it "calls the loaded target and tries the method on the target" do
40
- @speaker = Speaker.new(:meeting_id => 5)
41
- @speaker.meeting.title
36
+
37
+ describe '#loaded_target' do
38
+ before(:each) do
39
+ @meeting = Meeting.new(:id => 5, :title => 'Rails Development')
40
+ end
41
+
42
+ it 'loads target only once' do
43
+ Meeting.should_receive(:get).once.and_return(@meeting)
44
+ @speaker = Speaker.new(:meeting_id => 5)
45
+ @speaker.meeting.id
46
+ @speaker.meeting.id
47
+ end
48
+ end
49
+
50
+ describe '#method_missing' do
51
+ before(:each) do
52
+ meeting = Meeting.new(:id => 5, :title => 'Rails Development')
53
+ Meeting.stub(:get).and_return(meeting)
54
+ end
55
+
56
+ it 'calls the loaded target and tries the method on the target' do
57
+ @speaker = Speaker.new(:meeting_id => 5)
58
+ @speaker.meeting.title
59
+ end
42
60
  end
43
61
 
44
62
  end
@@ -1,5 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Associations::BelongsToAssociation, ".load_target!" do
4
- pending
3
+ describe Morpheus::Associations::BelongsToAssociation do
4
+
5
+ describe '#initialize' do
6
+ pending
7
+ end
8
+
9
+ describe '#with_filter' do
10
+ pending
11
+ end
12
+
13
+ describe '#load_target!' do
14
+ pending
15
+ end
16
+
5
17
  end
@@ -1,17 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Associations::HasManyAssociation, ".load_target!" do
4
- pending
5
- end
3
+ describe Morpheus::Associations::HasManyAssociation do
6
4
 
7
- describe Morpheus::Associations::HasManyAssociation, ".where" do
8
- pending
9
- end
5
+ describe '#initialize' do
6
+ pending
7
+ end
10
8
 
11
- describe Morpheus::Associations::HasManyAssociation, ".limit" do
12
- pending
13
- end
9
+ describe '#with_filter' do
10
+ pending
11
+ end
12
+
13
+ describe '#load_target!' do
14
+ pending
15
+ end
16
+
17
+ describe '#where' do
18
+ pending
19
+ end
20
+
21
+ describe '#limit' do
22
+ pending
23
+ end
24
+
25
+ describe '#page' do
26
+ pending
27
+ end
28
+
29
+ describe '#transform_association_into_relation' do
30
+ pending
31
+ end
32
+
33
+ describe '#<<' do
34
+ pending
35
+ end
14
36
 
15
- describe Morpheus::Associations::HasManyAssociation, ".page" do
16
- pending
17
37
  end
@@ -1,5 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Associations::HasOneAssociation, ".load_target!" do
4
- pending
3
+ describe Morpheus::Associations::HasOneAssociation do
4
+
5
+ describe '#initialize' do
6
+ pending
7
+ end
8
+
9
+ describe '#with_filter' do
10
+ pending
11
+ end
12
+
13
+ describe '#load_target!' do
14
+ pending
15
+ end
16
+
5
17
  end
@@ -1,126 +1,130 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Morpheus::Base, "ActiveModel Lint" do
3
+ describe Morpheus::Base do
4
4
 
5
- let(:model_under_test) { Morpheus::Base.new }
6
- it_behaves_like "ActiveModel"
5
+ describe 'ActiveModel lint' do
6
+ let(:model_under_test) { Morpheus::Base.new }
7
+ it_behaves_like 'ActiveModel'
8
+ end
7
9
 
8
- end
10
+ describe 'implements Morpheus::Associations' do
11
+ it 'includes the Morpheus::Associations module' do
12
+ Morpheus::Base.included_modules.should include(Morpheus::Associations)
13
+ end
14
+ end
9
15
 
10
- describe Morpheus::Base, "implements Morpheus::Associations" do
11
-
12
- it "includes the Morpheus::Associations module" do
13
- Morpheus::Base.included_modules.should include(Morpheus::Associations)
16
+ describe 'implements Morpheus::Attributes' do
17
+ it 'includes the Morpheus::Attributes module' do
18
+ Morpheus::Base.included_modules.should include(Morpheus::Attributes)
19
+ end
14
20
  end
15
-
16
- end
17
21
 
18
- describe Morpheus::Base, "implements Morpheus::Attributes" do
19
-
20
- it "includes the Morpheus::Attributes module" do
21
- Morpheus::Base.included_modules.should include(Morpheus::Attributes)
22
+ describe 'implements Morpheus::Conversion' do
23
+ it 'includes the Morpheus::Conversion module' do
24
+ Morpheus::Base.included_modules.should include(Morpheus::Conversion)
25
+ end
22
26
  end
23
-
24
- end
25
27
 
26
- describe Morpheus::Base, "implements Morpheus::Conversion" do
27
-
28
- it "includes the Morpheus::Finders module" do
29
- Morpheus::Base.included_modules.should include(Morpheus::Conversion)
28
+ describe 'implements Morpheus::Filtering' do
29
+ it 'includes the Morpheus::Filtering module' do
30
+ Morpheus::Base.included_modules.should include(Morpheus::Filtering)
31
+ end
30
32
  end
31
-
32
- end
33
33
 
34
- describe Morpheus::Base, "implements Morpheus::Finders" do
35
-
36
- it "includes the Morpheus::Finders module" do
37
- Morpheus::Base.included_modules.should include(Morpheus::Finders)
34
+ describe 'implements Morpheus::Finders' do
35
+ it 'includes the Morpheus::Finders module' do
36
+ Morpheus::Base.included_modules.should include(Morpheus::Finders)
37
+ end
38
38
  end
39
-
40
- end
41
39
 
42
- describe Morpheus::Base, "implements Morpheus::Introspection" do
43
-
44
- it "includes the Morpheus::Finders module" do
45
- Morpheus::Base.included_modules.should include(Morpheus::Introspection)
40
+ describe 'implements Morpheus::Introspection' do
41
+ it 'includes the Morpheus::Introspection module' do
42
+ Morpheus::Base.included_modules.should include(Morpheus::Introspection)
43
+ end
46
44
  end
47
-
48
- end
49
45
 
50
- describe Morpheus::Base, "implements Morpheus::Persistence" do
51
-
52
- it "includes the Morpheus::Persistence module" do
53
- Morpheus::Base.included_modules.should include(Morpheus::Persistence)
46
+ describe 'implements Morpheus::Persistence' do
47
+ it 'includes the Morpheus::Persistence module' do
48
+ Morpheus::Base.included_modules.should include(Morpheus::Persistence)
49
+ end
54
50
  end
55
-
56
- end
57
51
 
58
- describe Morpheus::Base, "implements Morpheus::ResponseParsing" do
59
-
60
- it "includes the Morpheus::Finders module" do
61
- Morpheus::Base.included_modules.should include(Morpheus::ResponseParsing)
52
+ describe 'implements Morpheus::Reflections' do
53
+ it 'includes the Morpheus::Reflections module' do
54
+ Morpheus::Base.included_modules.should include(Morpheus::Reflections)
55
+ end
62
56
  end
63
-
64
- end
65
57
 
66
- describe Morpheus::Base, ".initialize" do
67
-
68
- context "when no attributes hash is supplied" do
69
-
70
- before(:each) do
71
- @auto = Automobile.new
72
- end
73
-
74
- it "has attributes that are set to nil" do
75
- @auto.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :bhp => nil, :wheels => nil, :hybrid => nil, :name => nil }))
76
- end
77
-
78
- end
79
-
80
- context "when an attributes hash is supplied" do
81
-
82
- before(:each) do
83
- @auto = Automobile.new(
84
- :bhp => 300,
85
- :wheels => 4,
86
- :hybrid => false,
87
- :name => "Roadster"
88
- )
89
- end
90
-
91
- it "has attributes that are set to nil" do
92
- @auto.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :bhp => 300, :wheels => 4, :hybrid => false, :name => "Roadster" }))
93
- end
94
-
95
- end
96
-
97
- end
58
+ describe 'implements Morpheus::RequestHandling' do
59
+ it 'includes the Morpheus::RequestHandling module' do
60
+ Morpheus::Base.included_modules.should include(Morpheus::RequestHandling)
61
+ end
62
+ end
98
63
 
99
- describe Morpheus::Base, "defines an id property by default" do
100
-
101
- it "defines setter and getter methods for the id property" do
102
- base = Morpheus::Base.new(:id => 5)
103
-
104
- Morpheus::Base.stub(:get).and_return(base)
105
- @base = Morpheus::Base.find(1)
106
- @base.should respond_to(:id)
107
- @base.id.should eql(5)
108
- end
109
-
110
- it "creates an attribute entry for the id property" do
111
- Morpheus::Base.new.attributes.should include(:id)
112
- end
113
-
114
- end
64
+ describe 'implements Morpheus::ResponseParsing' do
65
+ it 'includes the Morpheus::ResponseParsing module' do
66
+ Morpheus::Base.included_modules.should include(Morpheus::ResponseParsing)
67
+ end
68
+ end
115
69
 
116
- describe Morpheus::Base, ".==" do
117
- pending
118
- end
70
+ describe 'implements Morpheus::UrlSupport' do
71
+ it 'includes the Morpheus::UrlSupport module' do
72
+ Morpheus::Base.included_modules.should include(Morpheus::UrlSupport)
73
+ end
74
+ end
75
+
76
+ describe '#initialize' do
77
+ context 'when no attributes hash is supplied' do
78
+ before(:each) do
79
+ @auto = Automobile.new
80
+ end
81
+
82
+ it 'has attributes that are set to nil' do
83
+ @auto.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :bhp => nil, :wheels => nil, :hybrid => nil, :name => nil }))
84
+ end
85
+ end
86
+
87
+ context 'when an attributes hash is supplied' do
88
+ before(:each) do
89
+ @auto = Automobile.new(
90
+ :bhp => 300,
91
+ :wheels => 4,
92
+ :hybrid => false,
93
+ :name => 'Roadster'
94
+ )
95
+ end
96
+
97
+ it 'has attributes that are set to nil' do
98
+ @auto.attributes.should eql(HashWithIndifferentAccess.new({ :id => nil, :bhp => 300, :wheels => 4, :hybrid => false, :name => 'Roadster' }))
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'defines an id property by default' do
104
+ it 'defines setter and getter methods for the id property' do
105
+ base = Morpheus::Base.new(:id => 5)
106
+ Morpheus::Base.stub(:get).and_return(base)
107
+ @base = Morpheus::Base.find(1)
108
+ @base.should respond_to(:id)
109
+ @base.id.should eql(5)
110
+ end
111
+
112
+ it 'creates an attribute entry for the id property' do
113
+ Morpheus::Base.new.attributes.should include(:id)
114
+ end
115
+ end
119
116
 
120
- describe Morpheus::Base, "#base_class" do
117
+ describe Morpheus::Base, '#==' do
118
+ pending
119
+ end
121
120
 
122
- it "returns the current class" do
123
- Dog.base_class.should eql(Dog)
121
+ describe Morpheus::Base, '.base_class' do
122
+ it 'returns the current class' do
123
+ Dog.base_class.should eql(Dog)
124
+ end
124
125
  end
125
126
 
127
+ describe '#method_missing' do
128
+ pending
129
+ end
126
130
  end