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.
- checksums.yaml +4 -4
- data/Gemfile +4 -7
- data/History.txt +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +0 -25
- data/Rakefile +5 -12
- data/acts_as_api.gemspec +14 -13
- data/{examples/introduction → docs}/docco.css +0 -0
- data/{examples/introduction → docs}/index.html +18 -21
- data/{examples/introduction → docs}/index.rb +0 -0
- data/{examples/introduction → docs}/layout.mustache +0 -0
- data/lib/acts_as_api.rb +9 -12
- data/lib/acts_as_api/adapters.rb +1 -1
- data/lib/acts_as_api/api_template.rb +23 -25
- data/lib/acts_as_api/base.rb +11 -20
- data/lib/acts_as_api/collection.rb +1 -2
- data/lib/acts_as_api/config.rb +0 -5
- data/lib/acts_as_api/exceptions.rb +2 -2
- data/lib/acts_as_api/rails_renderer.rb +0 -2
- data/lib/acts_as_api/rendering.rb +5 -12
- data/lib/acts_as_api/responder.rb +8 -13
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/README.md +15 -6
- data/spec/active_record_dummy/Gemfile +2 -10
- data/spec/active_record_dummy/app/models/user.rb +31 -32
- data/spec/active_record_dummy/config.ru +1 -1
- data/spec/active_record_dummy/config/application.rb +2 -2
- data/spec/active_record_dummy/config/boot.rb +1 -1
- data/spec/active_record_dummy/config/environments/test.rb +2 -2
- data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/active_record_dummy/config/routes.rb +1 -57
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
- data/spec/active_record_dummy/db/schema.rb +27 -29
- data/spec/active_record_dummy/script/rails +2 -2
- data/spec/controllers/plain_objects_controller_spec.rb +11 -12
- data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
- data/spec/controllers/users_controller_spec.rb +2 -3
- data/spec/models/model_spec.rb +17 -19
- data/spec/mongoid_dummy/Gemfile +3 -12
- data/spec/mongoid_dummy/app/models/profile.rb +6 -6
- data/spec/mongoid_dummy/app/models/task.rb +10 -10
- data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
- data/spec/mongoid_dummy/app/models/user.rb +12 -14
- data/spec/mongoid_dummy/config.ru +1 -1
- data/spec/mongoid_dummy/config/application.rb +7 -7
- data/spec/mongoid_dummy/config/boot.rb +1 -1
- data/spec/mongoid_dummy/config/environments/development.rb +0 -1
- data/spec/mongoid_dummy/config/environments/production.rb +0 -1
- data/spec/mongoid_dummy/config/environments/test.rb +2 -2
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
- data/spec/mongoid_dummy/config/routes.rb +1 -57
- data/spec/mongoid_dummy/script/rails +2 -2
- data/spec/shared_engine/Gemfile +1 -1
- data/spec/shared_engine/Rakefile +1 -4
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
- data/spec/shared_engine/app/models/plain_object.rb +3 -1
- data/spec/shared_engine/app/models/user_template.rb +28 -29
- data/spec/shared_engine/lib/shared_engine.rb +1 -1
- data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
- data/spec/shared_engine/shared_engine.gemspec +10 -12
- data/spec/spec_helper.rb +5 -13
- data/spec/support/api_test_helpers.rb +0 -2
- data/spec/support/controller_examples.rb +128 -173
- data/spec/support/it_supports.rb +1 -1
- data/spec/support/model_examples/associations.rb +119 -128
- data/spec/support/model_examples/callbacks.rb +17 -27
- data/spec/support/model_examples/closures.rb +21 -29
- data/spec/support/model_examples/conditional_if.rb +71 -103
- data/spec/support/model_examples/conditional_unless.rb +71 -103
- data/spec/support/model_examples/enabled.rb +5 -6
- data/spec/support/model_examples/extending.rb +49 -56
- data/spec/support/model_examples/methods.rb +11 -15
- data/spec/support/model_examples/options.rb +19 -25
- data/spec/support/model_examples/renaming.rb +21 -30
- data/spec/support/model_examples/simple.rb +10 -14
- data/spec/support/model_examples/sub_nodes.rb +47 -59
- data/spec/support/model_examples/undefined.rb +4 -6
- data/spec/support/model_examples/untouched.rb +6 -8
- data/spec/support/simple_fixtures.rb +11 -38
- metadata +22 -159
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
- 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/public/404.html +0 -26
- data/spec/active_record_dummy/public/422.html +0 -26
- data/spec/active_record_dummy/public/500.html +0 -25
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +0 -241
- data/spec/active_record_dummy/public/robots.txt +0 -5
- 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/mongoid_dummy/README.rdoc +0 -261
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +0 -26
- data/spec/mongoid_dummy/public/422.html +0 -26
- data/spec/mongoid_dummy/public/500.html +0 -25
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +0 -241
- data/spec/mongoid_dummy/public/robots.txt +0 -5
- 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/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
- data/spec/shared_engine/dummy/README.rdoc +0 -261
- data/spec/shared_engine/dummy/Rakefile +0 -7
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
- 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 +0 -14
- data/spec/shared_engine/dummy/config.ru +0 -4
- data/spec/shared_engine/dummy/config/application.rb +0 -56
- data/spec/shared_engine/dummy/config/boot.rb +0 -10
- data/spec/shared_engine/dummy/config/database.yml +0 -25
- data/spec/shared_engine/dummy/config/environment.rb +0 -5
- data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
- data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
- data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
- data/spec/shared_engine/dummy/config/routes.rb +0 -4
- 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 +0 -26
- data/spec/shared_engine/dummy/public/422.html +0 -26
- data/spec/shared_engine/dummy/public/500.html +0 -25
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +0 -6
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
shared_examples_for
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
8
|
-
User.
|
|
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
|
|
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, :
|
|
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, :
|
|
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
|
-
|
|
21
|
-
@response.should be_kind_of(Hash)
|
|
22
|
-
end
|
|
17
|
+
subject(:response) { @luke.as_api_response(:private) }
|
|
23
18
|
|
|
24
|
-
it
|
|
25
|
-
|
|
19
|
+
it 'returns a hash' do
|
|
20
|
+
expect(response).to be_kind_of(Hash)
|
|
26
21
|
end
|
|
27
22
|
|
|
28
|
-
it
|
|
29
|
-
|
|
23
|
+
it 'returns the correct number of fields' do
|
|
24
|
+
expect(response).to have(3).keys
|
|
30
25
|
end
|
|
31
26
|
|
|
32
|
-
it
|
|
33
|
-
|
|
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
|
|
36
|
+
describe 'and removing a former added value' do
|
|
37
|
+
subject(:response) { @luke.as_api_response(:age_and_first_name) }
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
it 'returns a hash' do
|
|
40
|
+
expect(response).to be_kind_of(Hash)
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
it
|
|
45
|
-
|
|
43
|
+
it 'returns the correct number of fields' do
|
|
44
|
+
expect(response).to have(2).keys
|
|
46
45
|
end
|
|
47
46
|
|
|
48
|
-
it
|
|
49
|
-
|
|
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
|
|
53
|
-
|
|
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
|
|
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, :
|
|
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
|
-
|
|
75
|
-
|
|
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
|
|
79
|
-
|
|
72
|
+
it 'returns the correct number of fields' do
|
|
73
|
+
expect(response).to have(2).keys
|
|
80
74
|
end
|
|
81
75
|
|
|
82
|
-
it
|
|
83
|
-
|
|
76
|
+
it 'returns all specified fields' do
|
|
77
|
+
expect(response.keys).to include(:first_name)
|
|
84
78
|
end
|
|
85
79
|
|
|
86
|
-
it
|
|
87
|
-
|
|
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
|
|
91
|
-
|
|
84
|
+
it 'returns all specified fields' do
|
|
85
|
+
expect(response.keys).to include(:tasks)
|
|
92
86
|
end
|
|
93
87
|
|
|
94
|
-
it
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
100
|
-
|
|
101
|
-
task.keys.
|
|
102
|
-
task.keys.
|
|
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
|
|
107
|
-
task_hash = [
|
|
108
|
-
|
|
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
|
|
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
|
-
|
|
4
|
-
|
|
4
|
+
it 'returns a hash' do
|
|
5
|
+
expect(response).to be_kind_of(Hash)
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
it
|
|
8
|
-
|
|
8
|
+
it 'returns the correct number of fields' do
|
|
9
|
+
expect(response).to have(1).keys
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
it
|
|
12
|
-
|
|
12
|
+
it 'returns all specified fields by name' do
|
|
13
|
+
expect(response.keys).to include(:full_name)
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
it
|
|
16
|
-
|
|
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
|
|
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
|
|
5
|
+
t.add ->(_, options) { options }, as: :options
|
|
8
6
|
t.add :profile
|
|
9
|
-
t.add :first_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
|
|
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
|
|
19
|
+
t.add ->(_, options) { options }, as: :options
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
context
|
|
26
|
-
|
|
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
|
|
31
|
-
|
|
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
|
|
35
|
-
|
|
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
|
|
41
|
-
it
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
14
|
-
|
|
9
|
+
it 'returns the correct number of fields' do
|
|
10
|
+
expect(response).to have(1).keys
|
|
15
11
|
end
|
|
16
12
|
|
|
17
|
-
it
|
|
18
|
-
|
|
13
|
+
it 'returns all specified fields' do
|
|
14
|
+
expect(response.keys).to include(:family_name)
|
|
19
15
|
end
|
|
20
16
|
|
|
21
|
-
it
|
|
22
|
-
|
|
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
|
|
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
|
-
|
|
30
|
-
|
|
25
|
+
it 'returns a hash' do
|
|
26
|
+
expect(response).to be_kind_of(Hash)
|
|
31
27
|
end
|
|
32
28
|
|
|
33
|
-
it
|
|
34
|
-
|
|
29
|
+
it 'returns the correct number of fields' do
|
|
30
|
+
expect(response).to have(1).keys
|
|
35
31
|
end
|
|
36
32
|
|
|
37
|
-
it
|
|
38
|
-
|
|
33
|
+
it 'returns all specified fields' do
|
|
34
|
+
expect(response.keys).to include(:other_full_name)
|
|
39
35
|
end
|
|
40
36
|
|
|
41
|
-
it
|
|
42
|
-
|
|
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
|
|
1
|
+
shared_examples_for 'listing attributes in the api template' do
|
|
2
|
+
subject(:response) { @luke.as_api_response(:name_only) }
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
it 'returns a hash' do
|
|
5
|
+
expect(response).to be_kind_of(Hash)
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
it
|
|
8
|
-
|
|
8
|
+
it 'returns the correct number of fields' do
|
|
9
|
+
expect(response).to have(2).keys
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
it
|
|
12
|
-
|
|
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
|
|
16
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
14
|
-
|
|
9
|
+
it 'returns the correct number of fields' do
|
|
10
|
+
expect(response).to have(1).keys
|
|
15
11
|
end
|
|
16
12
|
|
|
17
|
-
it
|
|
18
|
-
|
|
13
|
+
it 'returns all specified fields' do
|
|
14
|
+
expect(response.keys).to include(:sub_nodes)
|
|
19
15
|
end
|
|
20
16
|
|
|
21
|
-
it
|
|
22
|
-
|
|
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
|
|
26
|
-
|
|
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
|
|
30
|
-
|
|
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
|
|
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
|
|
41
|
-
|
|
33
|
+
it 'returns a hash' do
|
|
34
|
+
expect(response).to be_kind_of(Hash)
|
|
42
35
|
end
|
|
43
36
|
|
|
44
|
-
it
|
|
45
|
-
|
|
37
|
+
it 'returns the correct number of fields' do
|
|
38
|
+
expect(response).to have(1).keys
|
|
46
39
|
end
|
|
47
40
|
|
|
48
|
-
it
|
|
49
|
-
|
|
41
|
+
it 'returns all specified fields' do
|
|
42
|
+
expect(response.keys).to include(:sub_nodes)
|
|
50
43
|
end
|
|
51
44
|
|
|
52
|
-
it
|
|
53
|
-
|
|
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
|
|
57
|
-
|
|
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
|
|
61
|
-
|
|
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
|
|
65
|
-
|
|
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.
|
|
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
|
|
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
|
|
81
|
-
|
|
69
|
+
it 'returns a hash' do
|
|
70
|
+
expect(response).to be_kind_of(Hash)
|
|
82
71
|
end
|
|
83
72
|
|
|
84
|
-
it
|
|
85
|
-
|
|
73
|
+
it 'returns the correct number of fields' do
|
|
74
|
+
expect(response).to have(1).keys
|
|
86
75
|
end
|
|
87
76
|
|
|
88
|
-
it
|
|
89
|
-
|
|
77
|
+
it 'returns all specified fields' do
|
|
78
|
+
expect(response.keys).to include(:sub_hash)
|
|
90
79
|
end
|
|
91
80
|
|
|
92
|
-
it
|
|
93
|
-
|
|
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
|
|
97
|
-
|
|
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
|
|
101
|
-
|
|
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
|