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
data/spec/dummy/config/routes.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
29
|
+
describe '#try' do
|
30
|
+
pending
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
Meeting.stub(:get).and_return(meeting)
|
33
|
+
describe '#includes' do
|
34
|
+
pending
|
37
35
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
4
|
-
|
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
|
4
|
-
pending
|
5
|
-
end
|
3
|
+
describe Morpheus::Associations::HasManyAssociation do
|
6
4
|
|
7
|
-
describe
|
8
|
-
|
9
|
-
end
|
5
|
+
describe '#initialize' do
|
6
|
+
pending
|
7
|
+
end
|
10
8
|
|
11
|
-
describe
|
12
|
-
|
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
|
4
|
-
|
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
|
data/spec/morpheus/base_spec.rb
CHANGED
@@ -1,126 +1,130 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Morpheus::Base
|
3
|
+
describe Morpheus::Base do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe 'ActiveModel lint' do
|
6
|
+
let(:model_under_test) { Morpheus::Base.new }
|
7
|
+
it_behaves_like 'ActiveModel'
|
8
|
+
end
|
7
9
|
|
8
|
-
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
59
|
-
|
60
|
-
|
61
|
-
|
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::
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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::
|
100
|
-
|
101
|
-
|
102
|
-
|
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::
|
117
|
-
|
118
|
-
|
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,
|
117
|
+
describe Morpheus::Base, '#==' do
|
118
|
+
pending
|
119
|
+
end
|
121
120
|
|
122
|
-
|
123
|
-
|
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
|