acts_as_api 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/Gemfile +1 -1
  2. data/History.txt +5 -0
  3. data/README.rdoc +9 -2
  4. data/Rakefile +15 -1
  5. data/acts_as_api.gemspec +1 -0
  6. data/examples/introduction/index.html +7 -6
  7. data/examples/introduction/index.rb +9 -8
  8. data/lib/acts_as_api.rb +12 -5
  9. data/lib/acts_as_api/adapters.rb +5 -0
  10. data/lib/acts_as_api/adapters/mongoid.rb +11 -0
  11. data/lib/acts_as_api/array.rb +4 -8
  12. data/lib/acts_as_api/responder.rb +40 -0
  13. data/lib/acts_as_api/version.rb +1 -1
  14. data/spec/controllers/respond_with_users_controller_spec.rb +30 -2
  15. data/spec/controllers/users_controller_spec.rb +17 -235
  16. data/spec/models/active_record_spec.rb +28 -0
  17. data/spec/models/mongoid_spec.rb +28 -0
  18. data/spec/rails_app/app/controllers/respond_with_users_controller.rb +19 -8
  19. data/spec/rails_app/app/controllers/users_controller.rb +13 -4
  20. data/spec/rails_app/app/models/mongo_profile.rb +10 -0
  21. data/spec/rails_app/app/models/mongo_task.rb +12 -0
  22. data/spec/rails_app/app/models/mongo_untouched.rb +7 -0
  23. data/spec/rails_app/app/models/mongo_user.rb +149 -0
  24. data/spec/rails_app/app/models/user.rb +6 -6
  25. data/spec/rails_app/config/initializers/acts_as_api_mongoid.rb +6 -0
  26. data/spec/rails_app/config/mongoid.yml +23 -0
  27. data/spec/support/controller_examples.rb +246 -0
  28. data/spec/support/it_supports.rb +3 -0
  29. data/spec/support/model_examples/associations.rb +272 -0
  30. data/spec/support/model_examples/closures.rb +49 -0
  31. data/spec/support/model_examples/conditional_if.rb +165 -0
  32. data/spec/support/model_examples/conditional_unless.rb +165 -0
  33. data/spec/support/model_examples/enabled.rb +10 -0
  34. data/spec/support/model_examples/extending.rb +112 -0
  35. data/spec/support/model_examples/methods.rb +23 -0
  36. data/spec/support/model_examples/renaming.rb +50 -0
  37. data/spec/support/model_examples/simple.rb +23 -0
  38. data/spec/support/model_examples/sub_nodes.rb +105 -0
  39. data/spec/support/model_examples/undefined.rb +7 -0
  40. data/spec/support/model_examples/untouched.rb +13 -0
  41. data/spec/support/simple_fixtures.rb +39 -8
  42. metadata +67 -28
  43. data/spec/models/base/associations_spec.rb +0 -284
  44. data/spec/models/base/closures_spec.rb +0 -62
  45. data/spec/models/base/conditional_if_spec.rb +0 -178
  46. data/spec/models/base/conditional_unless_spec.rb +0 -178
  47. data/spec/models/base/enabled_spec.rb +0 -15
  48. data/spec/models/base/extending_spec.rb +0 -125
  49. data/spec/models/base/methods_spec.rb +0 -33
  50. data/spec/models/base/renaming_spec.rb +0 -63
  51. data/spec/models/base/simple_spec.rb +0 -33
  52. data/spec/models/base/sub_nodes_spec.rb +0 -118
  53. data/spec/models/base/undefined_spec.rb +0 -20
  54. data/spec/models/base/untouched_spec.rb +0 -18
@@ -1,62 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "calling a closure in the api template", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- end
10
-
11
- after(:each) do
12
- clean_up
13
- end
14
-
15
- describe "i.e. a proc (the record is passed as only parameter)" do
16
-
17
- before(:each) do
18
- @response = @luke.as_api_response(:calling_a_proc)
19
- end
20
-
21
- it "returns a hash" do
22
- @response.should be_kind_of(Hash)
23
- end
24
-
25
- it "returns the correct number of fields" do
26
- @response.should have(2).keys
27
- end
28
-
29
- it "returns all specified fields" do
30
- @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param])
31
- end
32
-
33
- it "returns the correct values for the specified fields" do
34
- @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
35
- end
36
- end
37
-
38
- describe "i.e. a lambda (the record is passed as only parameter)" do
39
-
40
- before(:each) do
41
- @response = @luke.as_api_response(:calling_a_lambda)
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([:all_caps_name, :without_param])
54
- end
55
-
56
- it "returns the correct values for the specified fields" do
57
- @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
58
- end
59
-
60
- end
61
- end
62
- end
@@ -1,178 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "conditional statements", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- end
10
-
11
- after(:each) do
12
- clean_up
13
- end
14
-
15
- describe "using the :if option" do
16
-
17
- describe "passing a symbol" do
18
-
19
- describe "that returns false" do
20
-
21
- before(:each) do
22
- @response = @luke.as_api_response(:if_over_thirty)
23
- end
24
-
25
- it "returns a hash" do
26
- @response.should be_kind_of(Hash)
27
- end
28
-
29
- it "returns the correct number of fields" do
30
- @response.should have(1).keys
31
- end
32
-
33
- it "won't add the conditional field but all others" do
34
- @response.keys.should include(:first_name)
35
- @response.keys.should_not include(:full_name)
36
- end
37
-
38
- it "the other specified fields have the correct value" do
39
- @response.values.should include(@luke.first_name)
40
- end
41
-
42
- end
43
-
44
- describe "that returns nil" do
45
-
46
- before(:each) do
47
- @response = @luke.as_api_response(:if_returns_nil)
48
- end
49
-
50
- it "returns a hash" do
51
- @response.should be_kind_of(Hash)
52
- end
53
-
54
- it "returns the correct number of fields" do
55
- @response.should have(1).keys
56
- end
57
-
58
- it "won't add the conditional field but all others" do
59
- @response.keys.should include(:first_name)
60
- @response.keys.should_not include(:full_name)
61
- end
62
-
63
- it "the other specified fields have the correct value" do
64
- @response.values.should include(@luke.first_name)
65
- end
66
-
67
- end
68
-
69
- describe "that returns true" do
70
-
71
- before(:each) do
72
- @response = @han.as_api_response(:if_over_thirty)
73
- end
74
-
75
- it "returns a hash" do
76
- @response.should be_kind_of(Hash)
77
- end
78
-
79
- it "returns the correct number of fields" do
80
- @response.should have(2).keys
81
- end
82
-
83
- it "won't add the conditional field but all others" do
84
- @response.keys.should include(:first_name)
85
- @response.keys.should include(:last_name)
86
- end
87
-
88
- it "the other specified fields have the correct value" do
89
- @response.values.should include(@han.first_name, @han.last_name)
90
- end
91
-
92
- end
93
-
94
- end
95
-
96
- end
97
-
98
- describe "passing a proc" do
99
-
100
- describe "that returns false" do
101
-
102
- before(:each) do
103
- @response = @luke.as_api_response(:if_over_thirty_proc)
104
- end
105
-
106
- it "returns a hash" do
107
- @response.should be_kind_of(Hash)
108
- end
109
-
110
- it "returns the correct number of fields" do
111
- @response.should have(1).keys
112
- end
113
-
114
- it "won't add the conditional field but all others" do
115
- @response.keys.should include(:first_name)
116
- @response.keys.should_not include(:full_name)
117
- end
118
-
119
- it "the other specified fields have the correct value" do
120
- @response.values.should include(@luke.first_name)
121
- end
122
-
123
- end
124
-
125
- describe "that returns nil" do
126
-
127
- before(:each) do
128
- @response = @luke.as_api_response(:if_returns_nil_proc)
129
- end
130
-
131
- it "returns a hash" do
132
- @response.should be_kind_of(Hash)
133
- end
134
-
135
- it "returns the correct number of fields" do
136
- @response.should have(1).keys
137
- end
138
-
139
- it "won't add the conditional field but all others" do
140
- @response.keys.should include(:first_name)
141
- @response.keys.should_not include(:full_name)
142
- end
143
-
144
- it "the other specified fields have the correct value" do
145
- @response.values.should include(@luke.first_name)
146
- end
147
-
148
- end
149
-
150
- describe "that returns true" do
151
-
152
- before(:each) do
153
- @response = @han.as_api_response(:if_over_thirty_proc)
154
- end
155
-
156
- it "returns a hash" do
157
- @response.should be_kind_of(Hash)
158
- end
159
-
160
- it "returns the correct number of fields" do
161
- @response.should have(2).keys
162
- end
163
-
164
- it "won't add the conditional field but all others" do
165
- @response.keys.should include(:first_name)
166
- @response.keys.should include(:last_name)
167
- end
168
-
169
- it "the other specified fields have the correct value" do
170
- @response.values.should include(@han.first_name, @han.last_name)
171
- end
172
-
173
- end
174
-
175
- end
176
-
177
- end
178
- end
@@ -1,178 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "conditional statements", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- end
10
-
11
- after(:each) do
12
- clean_up
13
- end
14
-
15
- describe "using the :unless option" do
16
-
17
- describe "passing a symbol" do
18
-
19
- describe "that returns false" do
20
-
21
- before(:each) do
22
- @response = @luke.as_api_response(:unless_under_thirty)
23
- end
24
-
25
- it "returns a hash" do
26
- @response.should be_kind_of(Hash)
27
- end
28
-
29
- it "returns the correct number of fields" do
30
- @response.should have(1).keys
31
- end
32
-
33
- it "won't add the conditional field but all others" do
34
- @response.keys.should include(:first_name)
35
- @response.keys.should_not include(:full_name)
36
- end
37
-
38
- it "the other specified fields have the correct value" do
39
- @response.values.should include(@luke.first_name)
40
- end
41
-
42
- end
43
-
44
- describe "that returns nil" do
45
-
46
- before(:each) do
47
- @response = @luke.as_api_response(:unless_returns_nil)
48
- end
49
-
50
- it "returns a hash" do
51
- @response.should be_kind_of(Hash)
52
- end
53
-
54
- it "returns the correct number of fields" do
55
- @response.should have(2).keys
56
- end
57
-
58
- it "won't add the conditional field but all others" do
59
- @response.keys.should include(:first_name)
60
- @response.keys.should include(:last_name)
61
- end
62
-
63
- it "the other specified fields have the correct value" do
64
- @response.values.should include(@luke.first_name, @luke.last_name)
65
- end
66
-
67
- end
68
-
69
- describe "that returns true" do
70
-
71
- before(:each) do
72
- @response = @han.as_api_response(:unless_under_thirty)
73
- end
74
-
75
- it "returns a hash" do
76
- @response.should be_kind_of(Hash)
77
- end
78
-
79
- it "returns the correct number of fields" do
80
- @response.should have(2).keys
81
- end
82
-
83
- it "won't add the conditional field but all others" do
84
- @response.keys.should include(:first_name)
85
- @response.keys.should include(:last_name)
86
- end
87
-
88
- it "the other specified fields have the correct value" do
89
- @response.values.should include(@han.first_name, @han.last_name)
90
- end
91
-
92
- end
93
-
94
- end
95
-
96
- end
97
-
98
- describe "passing a proc" do
99
-
100
- describe "that returns false" do
101
-
102
- before(:each) do
103
- @response = @luke.as_api_response(:unless_under_thirty_proc)
104
- end
105
-
106
- it "returns a hash" do
107
- @response.should be_kind_of(Hash)
108
- end
109
-
110
- it "returns the correct number of fields" do
111
- @response.should have(1).keys
112
- end
113
-
114
- it "won't add the conditional field but all others" do
115
- @response.keys.should include(:first_name)
116
- @response.keys.should_not include(:full_name)
117
- end
118
-
119
- it "the other specified fields have the correct value" do
120
- @response.values.should include(@luke.first_name)
121
- end
122
-
123
- end
124
-
125
- describe "that returns nil" do
126
-
127
- before(:each) do
128
- @response = @luke.as_api_response(:if_returns_nil_proc)
129
- end
130
-
131
- it "returns a hash" do
132
- @response.should be_kind_of(Hash)
133
- end
134
-
135
- it "returns the correct number of fields" do
136
- @response.should have(1).keys
137
- end
138
-
139
- it "won't add the conditional field but all others" do
140
- @response.keys.should include(:first_name)
141
- @response.keys.should_not include(:full_name)
142
- end
143
-
144
- it "the other specified fields have the correct value" do
145
- @response.values.should include(@luke.first_name)
146
- end
147
-
148
- end
149
-
150
- describe "that returns true" do
151
-
152
- before(:each) do
153
- @response = @han.as_api_response(:unless_under_thirty_proc)
154
- end
155
-
156
- it "returns a hash" do
157
- @response.should be_kind_of(Hash)
158
- end
159
-
160
- it "returns the correct number of fields" do
161
- @response.should have(2).keys
162
- end
163
-
164
- it "won't add the conditional field but all others" do
165
- @response.keys.should include(:first_name)
166
- @response.keys.should include(:last_name)
167
- end
168
-
169
- it "the other specified fields have the correct value" do
170
- @response.values.should include(@han.first_name, @han.last_name)
171
- end
172
-
173
- end
174
-
175
- end
176
-
177
- end
178
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "acts_as_api is enabled", :orm => :active_record do
6
-
7
- it "indicates that acts_as_api is enabled" do
8
- User.acts_as_api?.should be_true
9
- end
10
-
11
- it "does respond to api_accessible" do
12
- User.should respond_to :api_accessible
13
- end
14
- end
15
- end
@@ -1,125 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "extending a given api template", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- end
10
-
11
- after(:each) do
12
- clean_up
13
- end
14
-
15
- describe "multiple times" do
16
-
17
- before(:each) do
18
- User.api_accessible :public do |t|
19
- t.add :first_name
20
- end
21
-
22
- User.api_accessible :for_buddies, :extend => :public do |t|
23
- t.add :age
24
- end
25
-
26
- User.api_accessible :private, :extend => :for_buddies do |t|
27
- t.add :last_name
28
- end
29
- @response = @luke.as_api_response(:private)
30
- end
31
-
32
- it "returns a hash" do
33
- @response.should be_kind_of(Hash)
34
- end
35
-
36
- it "returns the correct number of fields" do
37
- @response.should have(3).keys
38
- end
39
-
40
- it "returns all specified fields" do
41
- @response.keys.sort_by(&:to_s).should eql([:age, :first_name, :last_name])
42
- end
43
-
44
- it "returns the correct values for the specified fields" do
45
- @response.values.sort_by(&:to_s).should eql([@luke.age, @luke.first_name, @luke.last_name].sort_by(&:to_s))
46
- end
47
-
48
- end
49
-
50
- describe "and removing a former added value" do
51
-
52
- before(:each) do
53
- @response = @luke.as_api_response(:age_and_first_name)
54
- end
55
-
56
- it "returns a hash" do
57
- @response.should be_kind_of(Hash)
58
- end
59
-
60
- it "returns the correct number of fields" do
61
- @response.should have(2).keys
62
- end
63
-
64
- it "returns all specified fields" do
65
- @response.keys.sort_by(&:to_s).should eql([:first_name, :age].sort_by(&:to_s))
66
- end
67
-
68
- it "returns the correct values for the specified fields" do
69
- @response.values.sort_by(&:to_s).should eql([@luke.first_name, @luke.age].sort_by(&:to_s))
70
- end
71
-
72
- end
73
-
74
- describe "and inherit a field using another template name", :meow => true do
75
-
76
- before(:each) do
77
- Task.acts_as_api
78
- Task.api_accessible :other_template do |t|
79
- t.add :description
80
- t.add :time_spent
81
- end
82
- User.api_accessible :extending_other_template, :extend => :other_sub_template
83
- @response = @luke.as_api_response(:extending_other_template)
84
- end
85
-
86
- it "returns a hash" do
87
- @response.should be_kind_of(Hash)
88
- end
89
-
90
- it "returns the correct number of fields" do
91
- @response.should have(2).keys
92
- end
93
-
94
- it "returns all specified fields" do
95
- @response.keys.should include(:first_name)
96
- end
97
-
98
- it "returns the correct values for the specified fields" do
99
- @response.values.should include(@luke.first_name)
100
- end
101
-
102
- it "returns all specified fields" do
103
- @response.keys.should include(:tasks)
104
- end
105
-
106
- it "returns the correct values for the specified fields" do
107
- @response[:tasks].should be_an Array
108
- @response[:tasks].should have(3).tasks
109
- end
110
-
111
- it "contains the associated child models with the determined api template" do
112
- @response[:tasks].each do |task|
113
- task.keys.should include(:description, :time_spent)
114
- task.keys.should have(2).attributes
115
- end
116
- end
117
-
118
- it "contains the correct data of the child models" do
119
- task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } }
120
- @response[:tasks].should eql task_hash
121
- end
122
- end
123
-
124
- end
125
- end