acts_as_api 0.4.4 → 1.0.0

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