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,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "calling a method in the api template", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- @response = @luke.as_api_response(:only_full_name)
10
- end
11
-
12
- after(:each) do
13
- clean_up
14
- end
15
-
16
- it "returns a hash" do
17
- @response.should be_kind_of(Hash)
18
- end
19
-
20
- it "returns the correct number of fields" do
21
- @response.should have(1).key
22
- end
23
-
24
- it "returns all specified fields by name" do
25
- @response.keys.should include(:full_name)
26
- end
27
-
28
- it "returns the correct values for the specified fields" do
29
- @response.values.should include(@luke.full_name)
30
- end
31
-
32
- end
33
- end
@@ -1,63 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "renaming", :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 "an attribute in the api template" do
16
-
17
- before(:each) do
18
- @response = @luke.as_api_response(:rename_last_name)
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(1).key
27
- end
28
-
29
- it "returns all specified fields" do
30
- @response.keys.should include(:family_name)
31
- end
32
-
33
- it "returns the correct values for the specified fields" do
34
- @response.values.should include(@luke.last_name)
35
- end
36
-
37
- end
38
-
39
- describe "the node/key of a method in the api template" do
40
-
41
- before(:each) do
42
- @response = @luke.as_api_response(:rename_full_name)
43
- end
44
-
45
- it "returns a hash" do
46
- @response.should be_kind_of(Hash)
47
- end
48
-
49
- it "returns the correct number of fields" do
50
- @response.should have(1).key
51
- end
52
-
53
- it "returns all specified fields" do
54
- @response.keys.should include(:other_full_name)
55
- end
56
-
57
- it "returns the correct values for the specified fields" do
58
- @response.values.should include(@luke.full_name)
59
- end
60
-
61
- end
62
- end
63
- end
@@ -1,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "listing attributes in the api template", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- @response = @luke.as_api_response(:name_only)
10
- end
11
-
12
- after(:each) do
13
- clean_up
14
- end
15
-
16
- it "returns a hash" do
17
- @response.should be_kind_of(Hash)
18
- end
19
-
20
- it "returns the correct number of fields" do
21
- @response.should have(2).keys
22
- end
23
-
24
- it "returns the specified fields only" do
25
- @response.keys.should include(:first_name, :last_name)
26
- end
27
-
28
- it "the specified fields have the correct value" do
29
- @response.values.should include(@luke.first_name, @luke.last_name)
30
- end
31
-
32
- end
33
- end
@@ -1,118 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "creating a sub hash 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 "and putting an attribute in it" do
16
-
17
- before(:each) do
18
- @response = @luke.as_api_response(:sub_node)
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(1).key
27
- end
28
-
29
- it "returns all specified fields" do
30
- @response.keys.should include(:sub_nodes)
31
- end
32
-
33
- it "returns the correct values for the specified fields" do
34
- @response[:sub_nodes].should be_a Hash
35
- end
36
-
37
- it "provides the correct number of sub nodes" do
38
- @response[:sub_nodes].should have(1).keys
39
- end
40
-
41
- it "provides the correct sub nodes values" do
42
- @response[:sub_nodes][:foo].should eql("something")
43
- end
44
- end
45
-
46
- describe "multiple times and putting an attribute in it" do
47
-
48
- before(:each) do
49
- @response = @luke.as_api_response(:nested_sub_node)
50
- end
51
-
52
- it "returns a hash" do
53
- @response.should be_kind_of(Hash)
54
- end
55
-
56
- it "returns the correct number of fields" do
57
- @response.should have(1).key
58
- end
59
-
60
- it "returns all specified fields" do
61
- @response.keys.should include(:sub_nodes)
62
- end
63
-
64
- it "returns the correct values for the specified fields" do
65
- @response[:sub_nodes].should be_a Hash
66
- end
67
-
68
- it "provides the correct number of sub nodes" do
69
- @response[:sub_nodes].should have(1).keys
70
- end
71
-
72
- it "provides the correct number of sub nodes in the second level" do
73
- @response[:sub_nodes][:foo].should have(1).keys
74
- end
75
-
76
- it "provides the correct sub nodes values" do
77
- @response[:sub_nodes][:foo].tap do |foo|
78
- foo[:bar].tap do |bar|
79
- bar.should eql(@luke.last_name)
80
- end
81
- end
82
- end
83
-
84
- end
85
-
86
- describe "using a method" do
87
-
88
- before(:each) do
89
- @response = @luke.as_api_response(:nested_sub_hash)
90
- end
91
-
92
- it "returns a hash" do
93
- @response.should be_kind_of(Hash)
94
- end
95
-
96
- it "returns the correct number of fields" do
97
- @response.should have(1).key
98
- end
99
-
100
- it "returns all specified fields" do
101
- @response.keys.should include(:sub_hash)
102
- end
103
-
104
- it "provides the correct number of sub nodes" do
105
- @response[:sub_hash].should have(2).keys
106
- end
107
-
108
- it "provides the correct sub nodes" do
109
- @response[:sub_hash].keys.should include(:foo, :hello)
110
- end
111
-
112
- it "provides the correct values in its sub nodes" do
113
- @response[:sub_hash].values.should include("bar", "world")
114
- end
115
-
116
- end
117
- end
118
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "trying to render an api template that is not defined", :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
- it "raises an descriptive error" do
16
- lambda{ @luke.as_api_response(:does_not_exist) }.should raise_error(ActsAsApi::TemplateNotFoundError)
17
- end
18
-
19
- end
20
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe Untouched, :orm => :active_record do
6
-
7
- describe "has disabled acts_as_api by default" do
8
- it "indicates that acts_as_api is disabled" do
9
- Untouched.acts_as_api?.should be_false
10
- end
11
-
12
- it "does not respond to api_accessible" do
13
- Untouched.should_not respond_to :api_accessible
14
- end
15
- end
16
-
17
- end
18
- end