acts_as_api_sequel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/History.txt +108 -0
- data/README.md +126 -0
- data/Rakefile +48 -0
- data/acts_as_api.gemspec +28 -0
- data/examples/introduction/docco.css +186 -0
- data/examples/introduction/index.html +338 -0
- data/examples/introduction/index.rb +144 -0
- data/examples/introduction/layout.mustache +67 -0
- data/lib/acts_as_api.rb +46 -0
- data/lib/acts_as_api/adapters.rb +5 -0
- data/lib/acts_as_api/adapters/mongoid.rb +11 -0
- data/lib/acts_as_api/api_template.rb +139 -0
- data/lib/acts_as_api/array.rb +21 -0
- data/lib/acts_as_api/base.rb +88 -0
- data/lib/acts_as_api/config.rb +58 -0
- data/lib/acts_as_api/exceptions.rb +4 -0
- data/lib/acts_as_api/rails_renderer.rb +17 -0
- data/lib/acts_as_api/rendering.rb +95 -0
- data/lib/acts_as_api/responder.rb +39 -0
- data/lib/acts_as_api/version.rb +3 -0
- data/spec/README.md +55 -0
- data/spec/active_record_dummy/.gitignore +15 -0
- data/spec/active_record_dummy/Gemfile +16 -0
- data/spec/active_record_dummy/README.rdoc +261 -0
- data/spec/active_record_dummy/Rakefile +7 -0
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/active_record_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/profile.rb +4 -0
- data/spec/active_record_dummy/app/models/task.rb +4 -0
- data/spec/active_record_dummy/app/models/untouched.rb +2 -0
- data/spec/active_record_dummy/app/models/user.rb +186 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/active_record_dummy/config.ru +4 -0
- data/spec/active_record_dummy/config/application.rb +59 -0
- data/spec/active_record_dummy/config/boot.rb +6 -0
- data/spec/active_record_dummy/config/database.yml +25 -0
- data/spec/active_record_dummy/config/environment.rb +5 -0
- data/spec/active_record_dummy/config/environments/development.rb +37 -0
- data/spec/active_record_dummy/config/environments/production.rb +67 -0
- data/spec/active_record_dummy/config/environments/test.rb +37 -0
- data/spec/active_record_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/active_record_dummy/config/initializers/generators.rb +2 -0
- data/spec/active_record_dummy/config/initializers/inflections.rb +15 -0
- data/spec/active_record_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/active_record_dummy/config/locales/en.yml +5 -0
- data/spec/active_record_dummy/config/routes.rb +59 -0
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +44 -0
- data/spec/active_record_dummy/db/schema.rb +47 -0
- data/spec/active_record_dummy/db/seeds.rb +7 -0
- data/spec/active_record_dummy/doc/README_FOR_APP +2 -0
- data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/log/.gitkeep +0 -0
- data/spec/active_record_dummy/public/404.html +26 -0
- data/spec/active_record_dummy/public/422.html +26 -0
- data/spec/active_record_dummy/public/500.html +25 -0
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +241 -0
- data/spec/active_record_dummy/public/robots.txt +5 -0
- data/spec/active_record_dummy/script/rails +6 -0
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/controllers/plain_objects_controller_spec.rb +36 -0
- data/spec/controllers/respond_with_users_controller_spec.rb +142 -0
- data/spec/controllers/users_controller_spec.rb +15 -0
- data/spec/models/model_spec.rb +31 -0
- data/spec/mongoid_dummy/.gitignore +15 -0
- data/spec/mongoid_dummy/Gemfile +18 -0
- data/spec/mongoid_dummy/README.rdoc +261 -0
- data/spec/mongoid_dummy/Rakefile +7 -0
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/models/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/models/profile.rb +10 -0
- data/spec/mongoid_dummy/app/models/task.rb +12 -0
- data/spec/mongoid_dummy/app/models/untouched.rb +7 -0
- data/spec/mongoid_dummy/app/models/user.rb +48 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/mongoid_dummy/config.ru +4 -0
- data/spec/mongoid_dummy/config/application.rb +65 -0
- data/spec/mongoid_dummy/config/boot.rb +6 -0
- data/spec/mongoid_dummy/config/environment.rb +5 -0
- data/spec/mongoid_dummy/config/environments/development.rb +31 -0
- data/spec/mongoid_dummy/config/environments/production.rb +64 -0
- data/spec/mongoid_dummy/config/environments/test.rb +35 -0
- data/spec/mongoid_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/generators.rb +2 -0
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +3 -0
- data/spec/mongoid_dummy/config/initializers/inflections.rb +15 -0
- data/spec/mongoid_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/mongoid_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/mongoid_dummy/config/initializers/session_store.rb +8 -0
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/mongoid_dummy/config/locales/en.yml +5 -0
- data/spec/mongoid_dummy/config/mongoid.yml +120 -0
- data/spec/mongoid_dummy/config/routes.rb +59 -0
- data/spec/mongoid_dummy/db/seeds.rb +7 -0
- data/spec/mongoid_dummy/doc/README_FOR_APP +2 -0
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/log/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +26 -0
- data/spec/mongoid_dummy/public/422.html +26 -0
- data/spec/mongoid_dummy/public/500.html +25 -0
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +241 -0
- data/spec/mongoid_dummy/public/robots.txt +5 -0
- data/spec/mongoid_dummy/script/rails +6 -0
- data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_engine/.gitignore +7 -0
- data/spec/shared_engine/Gemfile +14 -0
- data/spec/shared_engine/MIT-LICENSE +20 -0
- data/spec/shared_engine/README.rdoc +3 -0
- data/spec/shared_engine/Rakefile +29 -0
- data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +15 -0
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +13 -0
- data/spec/shared_engine/app/controllers/shared_engine/application_controller.rb +4 -0
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +14 -0
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +64 -0
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +71 -0
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +4 -0
- data/spec/shared_engine/app/models/plain_object.rb +17 -0
- data/spec/shared_engine/app/models/user_template.rb +154 -0
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +14 -0
- data/spec/shared_engine/config/routes.rb +28 -0
- data/spec/shared_engine/dummy/README.rdoc +261 -0
- data/spec/shared_engine/dummy/Rakefile +7 -0
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/shared_engine/dummy/config.ru +4 -0
- data/spec/shared_engine/dummy/config/application.rb +62 -0
- data/spec/shared_engine/dummy/config/boot.rb +10 -0
- data/spec/shared_engine/dummy/config/database.yml +25 -0
- data/spec/shared_engine/dummy/config/environment.rb +5 -0
- data/spec/shared_engine/dummy/config/environments/development.rb +37 -0
- data/spec/shared_engine/dummy/config/environments/production.rb +67 -0
- data/spec/shared_engine/dummy/config/environments/test.rb +37 -0
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +15 -0
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +8 -0
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/shared_engine/dummy/config/locales/en.yml +5 -0
- data/spec/shared_engine/dummy/config/routes.rb +4 -0
- data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
- data/spec/shared_engine/dummy/log/.gitkeep +0 -0
- data/spec/shared_engine/dummy/public/404.html +26 -0
- data/spec/shared_engine/dummy/public/422.html +26 -0
- data/spec/shared_engine/dummy/public/500.html +25 -0
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +6 -0
- data/spec/shared_engine/lib/magic/rails/engine.rb +69 -0
- data/spec/shared_engine/lib/shared_engine.rb +4 -0
- data/spec/shared_engine/lib/shared_engine/engine.rb +5 -0
- data/spec/shared_engine/lib/shared_engine/version.rb +3 -0
- data/spec/shared_engine/lib/tasks/shared_engine_tasks.rake +4 -0
- data/spec/shared_engine/script/rails +8 -0
- data/spec/shared_engine/shared_engine.gemspec +22 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/api_test_helpers.rb +23 -0
- data/spec/support/controller_examples.rb +458 -0
- data/spec/support/it_supports.rb +3 -0
- data/spec/support/model_examples/associations.rb +272 -0
- data/spec/support/model_examples/callbacks.rb +38 -0
- data/spec/support/model_examples/closures.rb +49 -0
- data/spec/support/model_examples/conditional_if.rb +165 -0
- data/spec/support/model_examples/conditional_unless.rb +165 -0
- data/spec/support/model_examples/enabled.rb +10 -0
- data/spec/support/model_examples/extending.rb +112 -0
- data/spec/support/model_examples/methods.rb +23 -0
- data/spec/support/model_examples/options.rb +53 -0
- data/spec/support/model_examples/renaming.rb +50 -0
- data/spec/support/model_examples/simple.rb +23 -0
- data/spec/support/model_examples/sub_nodes.rb +105 -0
- data/spec/support/model_examples/undefined.rb +7 -0
- data/spec/support/model_examples/untouched.rb +13 -0
- data/spec/support/routing.rb +4 -0
- data/spec/support/simple_fixtures.rb +59 -0
- metadata +499 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
shared_examples_for "conditional unless statements" do
|
2
|
+
|
3
|
+
describe "using the :unless option" do
|
4
|
+
|
5
|
+
describe "passing a symbol" do
|
6
|
+
|
7
|
+
describe "that returns false" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@response = @luke.as_api_response(:unless_under_thirty)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a hash" do
|
14
|
+
@response.should be_kind_of(Hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the correct number of fields" do
|
18
|
+
@response.should have(1).keys
|
19
|
+
end
|
20
|
+
|
21
|
+
it "won't add the conditional field but all others" do
|
22
|
+
@response.keys.should include(:first_name)
|
23
|
+
@response.keys.should_not include(:full_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "the other specified fields have the correct value" do
|
27
|
+
@response.values.should include(@luke.first_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "that returns nil" do
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
@response = @luke.as_api_response(:unless_returns_nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a hash" do
|
39
|
+
@response.should be_kind_of(Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns the correct number of fields" do
|
43
|
+
@response.should have(2).keys
|
44
|
+
end
|
45
|
+
|
46
|
+
it "won't add the conditional field but all others" do
|
47
|
+
@response.keys.should include(:first_name)
|
48
|
+
@response.keys.should include(:last_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "the other specified fields have the correct value" do
|
52
|
+
@response.values.should include(@luke.first_name, @luke.last_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "that returns true" do
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@response = @han.as_api_response(:unless_under_thirty)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a hash" do
|
64
|
+
@response.should be_kind_of(Hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns the correct number of fields" do
|
68
|
+
@response.should have(2).keys
|
69
|
+
end
|
70
|
+
|
71
|
+
it "won't add the conditional field but all others" do
|
72
|
+
@response.keys.should include(:first_name)
|
73
|
+
@response.keys.should include(:last_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "the other specified fields have the correct value" do
|
77
|
+
@response.values.should include(@han.first_name, @han.last_name)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "passing a proc" do
|
87
|
+
|
88
|
+
describe "that returns false" do
|
89
|
+
|
90
|
+
before(:each) do
|
91
|
+
@response = @luke.as_api_response(:unless_under_thirty_proc)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns a hash" do
|
95
|
+
@response.should be_kind_of(Hash)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns the correct number of fields" do
|
99
|
+
@response.should have(1).keys
|
100
|
+
end
|
101
|
+
|
102
|
+
it "won't add the conditional field but all others" do
|
103
|
+
@response.keys.should include(:first_name)
|
104
|
+
@response.keys.should_not include(:full_name)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "the other specified fields have the correct value" do
|
108
|
+
@response.values.should include(@luke.first_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "that returns nil" do
|
114
|
+
|
115
|
+
before(:each) do
|
116
|
+
@response = @luke.as_api_response(:if_returns_nil_proc)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns a hash" do
|
120
|
+
@response.should be_kind_of(Hash)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns the correct number of fields" do
|
124
|
+
@response.should have(1).keys
|
125
|
+
end
|
126
|
+
|
127
|
+
it "won't add the conditional field but all others" do
|
128
|
+
@response.keys.should include(:first_name)
|
129
|
+
@response.keys.should_not include(:full_name)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "the other specified fields have the correct value" do
|
133
|
+
@response.values.should include(@luke.first_name)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "that returns true" do
|
139
|
+
|
140
|
+
before(:each) do
|
141
|
+
@response = @han.as_api_response(:unless_under_thirty_proc)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns a hash" do
|
145
|
+
@response.should be_kind_of(Hash)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns the correct number of fields" do
|
149
|
+
@response.should have(2).keys
|
150
|
+
end
|
151
|
+
|
152
|
+
it "won't add the conditional field but all others" do
|
153
|
+
@response.keys.should include(:first_name)
|
154
|
+
@response.keys.should include(:last_name)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "the other specified fields have the correct value" do
|
158
|
+
@response.values.should include(@han.first_name, @han.last_name)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
shared_examples_for "extending a given api template" do
|
2
|
+
|
3
|
+
describe "multiple times" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
User.api_accessible :public do |t|
|
7
|
+
t.add :first_name
|
8
|
+
end
|
9
|
+
|
10
|
+
User.api_accessible :for_buddies, :extend => :public do |t|
|
11
|
+
t.add :age
|
12
|
+
end
|
13
|
+
|
14
|
+
User.api_accessible :private, :extend => :for_buddies do |t|
|
15
|
+
t.add :last_name
|
16
|
+
end
|
17
|
+
@response = @luke.as_api_response(:private)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a hash" do
|
21
|
+
@response.should be_kind_of(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the correct number of fields" do
|
25
|
+
@response.should have(3).keys
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns all specified fields" do
|
29
|
+
@response.keys.sort_by(&:to_s).should eql([:age, :first_name, :last_name])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the correct values for the specified fields" do
|
33
|
+
@response.values.sort_by(&:to_s).should eql([@luke.age, @luke.first_name, @luke.last_name].sort_by(&:to_s))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "and removing a former added value" do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@response = @luke.as_api_response(:age_and_first_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a hash" do
|
45
|
+
@response.should be_kind_of(Hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the correct number of fields" do
|
49
|
+
@response.should have(2).keys
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns all specified fields" do
|
53
|
+
@response.keys.sort_by(&:to_s).should eql([:first_name, :age].sort_by(&:to_s))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns the correct values for the specified fields" do
|
57
|
+
@response.values.sort_by(&:to_s).should eql([@luke.first_name, @luke.age].sort_by(&:to_s))
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "and inherit a field using another template name", :meow => true do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
Task.acts_as_api
|
66
|
+
Task.api_accessible :other_template do |t|
|
67
|
+
t.add :description
|
68
|
+
t.add :time_spent
|
69
|
+
end
|
70
|
+
User.api_accessible :extending_other_template, :extend => :other_sub_template
|
71
|
+
@response = @luke.as_api_response(:extending_other_template)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a hash" do
|
75
|
+
@response.should be_kind_of(Hash)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns the correct number of fields" do
|
79
|
+
@response.should have(2).keys
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns all specified fields" do
|
83
|
+
@response.keys.should include(:first_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns the correct values for the specified fields" do
|
87
|
+
@response.values.should include(@luke.first_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns all specified fields" do
|
91
|
+
@response.keys.should include(:tasks)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns the correct values for the specified fields" do
|
95
|
+
@response[:tasks].should be_an Array
|
96
|
+
@response[:tasks].should have(3).tasks
|
97
|
+
end
|
98
|
+
|
99
|
+
it "contains the associated child models with the determined api template" do
|
100
|
+
@response[:tasks].each do |task|
|
101
|
+
task.keys.should include(:description, :time_spent)
|
102
|
+
task.keys.should have(2).attributes
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "contains the correct data of the child models" do
|
107
|
+
task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } }
|
108
|
+
@response[:tasks].should eql task_hash
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
shared_examples_for "calling a method in the api template" do
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@response = @luke.as_api_response(:only_full_name)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns a hash" do
|
8
|
+
@response.should be_kind_of(Hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the correct number of fields" do
|
12
|
+
@response.should have(1).keys
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns all specified fields by name" do
|
16
|
+
@response.keys.should include(:full_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the correct values for the specified fields" do
|
20
|
+
@response.values.should include(@luke.full_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
shared_examples_for "options" do
|
2
|
+
|
3
|
+
describe "options in the api template" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
User.api_accessible :with_options do |t|
|
7
|
+
t.add lambda{|model,options| options }, :as => :options
|
8
|
+
t.add :profile
|
9
|
+
t.add :first_name, :if => lambda{|m,options| options[:with_name] }
|
10
|
+
end
|
11
|
+
|
12
|
+
Profile.acts_as_api
|
13
|
+
Profile.api_accessible :with_options do |t|
|
14
|
+
t.add lambda{|model,options| options }, :as => :options
|
15
|
+
end
|
16
|
+
|
17
|
+
Task.acts_as_api
|
18
|
+
Task.api_accessible :other_template do |t|
|
19
|
+
t.add :description
|
20
|
+
t.add :time_spent
|
21
|
+
t.add lambda{|model,options| options }, :as => :options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "as_api_response accept options" do
|
26
|
+
before :each do
|
27
|
+
@response = @luke.as_api_response(:with_options, :loc => [12, 13])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the options field as specified" do
|
31
|
+
@response[:options][:loc].should == [12, 13]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the option for the associations " do
|
35
|
+
@response[:profile][:options][:loc].should == [12, 13]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "allowed_to_render accept options" do
|
41
|
+
it "should not contains first_name when options[:with_name] is false" do
|
42
|
+
@response = @luke.as_api_response(:with_options, :with_name => false)
|
43
|
+
@response.should_not include(:first_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should contains first_name when options[:with_name] is true" do
|
47
|
+
@response = @luke.as_api_response(:with_options, :with_name => true)
|
48
|
+
@response[:first_name].should == 'Luke'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
shared_examples_for "renaming" do
|
2
|
+
|
3
|
+
describe "an attribute in the api template" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@response = @luke.as_api_response(:rename_last_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a hash" do
|
10
|
+
@response.should be_kind_of(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the correct number of fields" do
|
14
|
+
@response.should have(1).keys
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns all specified fields" do
|
18
|
+
@response.keys.should include(:family_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the correct values for the specified fields" do
|
22
|
+
@response.values.should include(@luke.last_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "the node/key of a method in the api template" do
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
@response = @luke.as_api_response(:rename_full_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a hash" do
|
34
|
+
@response.should be_kind_of(Hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns the correct number of fields" do
|
38
|
+
@response.should have(1).keys
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns all specified fields" do
|
42
|
+
@response.keys.should include(:other_full_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns the correct values for the specified fields" do
|
46
|
+
@response.values.should include(@luke.full_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
shared_examples_for "listing attributes in the api template" do
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@response = @luke.as_api_response(:name_only)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns a hash" do
|
8
|
+
@response.should be_kind_of(Hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the correct number of fields" do
|
12
|
+
@response.should have(2).keys
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the specified fields only" do
|
16
|
+
@response.keys.should include(:first_name, :last_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "the specified fields have the correct value" do
|
20
|
+
@response.values.should include(@luke.first_name, @luke.last_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
shared_examples_for "creating a sub hash in the api template" do
|
2
|
+
|
3
|
+
describe "and putting an attribute in it" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@response = @luke.as_api_response(:sub_node)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a hash" do
|
10
|
+
@response.should be_kind_of(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the correct number of fields" do
|
14
|
+
@response.should have(1).keys
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns all specified fields" do
|
18
|
+
@response.keys.should include(:sub_nodes)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the correct values for the specified fields" do
|
22
|
+
@response[:sub_nodes].should be_a Hash
|
23
|
+
end
|
24
|
+
|
25
|
+
it "provides the correct number of sub nodes" do
|
26
|
+
@response[:sub_nodes].should have(1).keys
|
27
|
+
end
|
28
|
+
|
29
|
+
it "provides the correct sub nodes values" do
|
30
|
+
@response[:sub_nodes][:foo].should eql("something")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "multiple times and putting an attribute in it" do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@response = @luke.as_api_response(:nested_sub_node)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns a hash" do
|
41
|
+
@response.should be_kind_of(Hash)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the correct number of fields" do
|
45
|
+
@response.should have(1).keys
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns all specified fields" do
|
49
|
+
@response.keys.should include(:sub_nodes)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns the correct values for the specified fields" do
|
53
|
+
@response[:sub_nodes].should be_a Hash
|
54
|
+
end
|
55
|
+
|
56
|
+
it "provides the correct number of sub nodes" do
|
57
|
+
@response[:sub_nodes].should have(1).keys
|
58
|
+
end
|
59
|
+
|
60
|
+
it "provides the correct number of sub nodes in the second level" do
|
61
|
+
@response[:sub_nodes][:foo].should have(1).keys
|
62
|
+
end
|
63
|
+
|
64
|
+
it "provides the correct sub nodes values" do
|
65
|
+
@response[:sub_nodes][:foo].tap do |foo|
|
66
|
+
foo[:bar].tap do |bar|
|
67
|
+
bar.should eql(@luke.last_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "using a method" do
|
75
|
+
|
76
|
+
before(:each) do
|
77
|
+
@response = @luke.as_api_response(:nested_sub_hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns a hash" do
|
81
|
+
@response.should be_kind_of(Hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns the correct number of fields" do
|
85
|
+
@response.should have(1).keys
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns all specified fields" do
|
89
|
+
@response.keys.should include(:sub_hash)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "provides the correct number of sub nodes" do
|
93
|
+
@response[:sub_hash].should have(2).keys
|
94
|
+
end
|
95
|
+
|
96
|
+
it "provides the correct sub nodes" do
|
97
|
+
@response[:sub_hash].keys.should include(:foo, :hello)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "provides the correct values in its sub nodes" do
|
101
|
+
@response[:sub_hash].values.should include("bar", "world")
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|