grape_resource 0.1.6 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/grape_resource/generator_helpers.rb +22 -1
- data/lib/generators/grape_resource/namespace_generator.rb +7 -2
- data/lib/generators/grape_resource/rest_generator.rb +5 -1
- data/lib/generators/templates/namespace/namespace_endpoint.rb.erb +7 -7
- data/lib/generators/templates/namespace/specs.rb.erb +133 -0
- data/lib/generators/templates/rest/rest_endpoint.rb.erb +4 -4
- data/lib/generators/templates/rest/specs.rb.erb +116 -0
- data/lib/grape_resource/version.rb +1 -1
- metadata +4 -3
- data/lib/generators/templates/specs.rb.erb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ab79efc27f78c897e94a94302dfc63d92e3c029df67f7b3d595154707cdd6c
|
4
|
+
data.tar.gz: 45eb79d583d8a11c61406a5e318ce3073777fa06d8452b59cdff0961e40ea934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89390cb279e86b7b62915e4b30d3093f80756646296aa67d3f1e0e6017c29e7bb1642752e1c1d94534a11bbe589f096b28dabb746ac6813e2e4022c0feebc85c
|
7
|
+
data.tar.gz: b4299558cd02dccd560495cadddbf3b5e83ef736d02a3716b5d38a972b05ce71bba951e314e151e3682f1704acf450fe3da614598d88e9ee5e8debb177d32a88
|
data/Gemfile.lock
CHANGED
@@ -76,6 +76,27 @@ module GrapeResource
|
|
76
76
|
File.exist? rspec_file
|
77
77
|
end
|
78
78
|
|
79
|
+
def rspec_dummy
|
80
|
+
@dummy = {}
|
81
|
+
editable_attributes.map do |col|
|
82
|
+
@dummy[col.name] = case col.type.underscore
|
83
|
+
when "string"
|
84
|
+
"Example of string"
|
85
|
+
when "text"
|
86
|
+
"Example of text"
|
87
|
+
when "uuid"
|
88
|
+
"e388e513-2510-44d6-9fb3-56411e7ed7f2"
|
89
|
+
when "integer"
|
90
|
+
123
|
91
|
+
when "boolean"
|
92
|
+
1
|
93
|
+
when "date_time"
|
94
|
+
"2019-07-09 04:10:55"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
@dummy
|
98
|
+
end
|
99
|
+
|
79
100
|
# Entities
|
80
101
|
def entities_exist?
|
81
102
|
entity_file = Rails.root.join("app/#{GrapeResource.directory}#{name.underscore.pluralize}/entities/#{name.underscore.singularize}.rb")
|
@@ -97,7 +118,7 @@ module GrapeResource
|
|
97
118
|
def attributes_for_params
|
98
119
|
@entities = {}
|
99
120
|
editable_attributes.map do |col|
|
100
|
-
@entities[col.name] = col.type.
|
121
|
+
@entities[col.name] = col.type.underscore.in?(["text", "uuid"]) ? "String" : col.type.camelize
|
101
122
|
end
|
102
123
|
@entities
|
103
124
|
end
|
@@ -21,7 +21,7 @@ module GrapeResource
|
|
21
21
|
insert_resources
|
22
22
|
insert_into_main unless mounted_routes_exist?
|
23
23
|
insert_namespace_entities unless entities_exist?
|
24
|
-
template_rspec
|
24
|
+
template_rspec
|
25
25
|
routes_exist? ? insert_namespace_routes : template_namespace_routes
|
26
26
|
end
|
27
27
|
|
@@ -52,7 +52,12 @@ module GrapeResource
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def template_rspec
|
55
|
-
|
55
|
+
check_endpoint_or_method args
|
56
|
+
template "namespace/specs.rb.erb", "app/#{GrapeResource.directory}/#{name.underscore.pluralize}/spec/#{name.underscore.singularize}_spec.rb"
|
57
|
+
|
58
|
+
inside "app/#{GrapeResource.directory}/#{name.underscore.pluralize}/spec/" do
|
59
|
+
gsub_file("#{name.underscore.singularize}_spec.rb", /.*?remove.*\r?\n/, "")
|
60
|
+
end
|
56
61
|
end
|
57
62
|
|
58
63
|
def insert_namespace_routes
|
@@ -51,7 +51,11 @@ module GrapeResource
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def template_rspec
|
54
|
-
|
54
|
+
rspec_dummy
|
55
|
+
template "rest/specs.rb.erb", "app/#{GrapeResource.directory}/#{name.underscore.pluralize}/spec/#{name.underscore.pluralize}_spec.rb"
|
56
|
+
inside "app/#{GrapeResource.directory}/#{name.underscore.pluralize}/spec/" do
|
57
|
+
gsub_file("#{name.underscore.pluralize}_spec.rb", /.*?remove.*\r?\n/, "")
|
58
|
+
end
|
55
59
|
end
|
56
60
|
|
57
61
|
def insert_rest_routes
|
@@ -12,7 +12,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
12
12
|
results = <%= name.camelize.singularize %>.all
|
13
13
|
resources = paginate(results)
|
14
14
|
present_metas resources
|
15
|
-
present :<%= name.
|
15
|
+
present :<%= name.underscore.pluralize %>, resources, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
16
16
|
end
|
17
17
|
|
18
18
|
<% end %>remove
|
@@ -23,10 +23,10 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
23
23
|
desc "Get <%= k.underscore %>"
|
24
24
|
paginate per_page: Pagy::VARS[:items], max_per_page: Pagy::VARS[:max_per_page]
|
25
25
|
get "/<%= k.downcase %>" do
|
26
|
-
results = <%= name.camelize.singularize %>.<%= k.downcase %>
|
26
|
+
results = <%= name.camelize.singularize %>.<%= k.downcase %> # Populate this method
|
27
27
|
resources = paginate(results)
|
28
28
|
present_metas resources
|
29
|
-
present :<%= name.
|
29
|
+
present :<%= name.underscore.pluralize %>, resources, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
30
30
|
end
|
31
31
|
|
32
32
|
<% end %>remove
|
@@ -36,11 +36,11 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
36
36
|
# Member method
|
37
37
|
desc "Get <%= k.underscore %>"
|
38
38
|
params do
|
39
|
-
requires :id, type: String
|
39
|
+
requires :id, type: String, desc: "<%= name.camelize.singularize %> ID"
|
40
40
|
end
|
41
41
|
get "/:id/<%= k.downcase %>" do
|
42
42
|
results = <%= name.camelize.singularize %>.find(params.id)
|
43
|
-
present :<%= name.
|
43
|
+
present :<%= name.underscore.pluralize %>, results, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
44
44
|
end
|
45
45
|
|
46
46
|
<% end %>remove
|
@@ -52,7 +52,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
52
52
|
# requires :your_params, type: [eg: String, Integer, Array]
|
53
53
|
end
|
54
54
|
post "/<%= k.downcase %>" do
|
55
|
-
# present :<%= name.
|
55
|
+
# present :<%= name.underscore.pluralize %>, results, with: <%= GrapeResource.class_name_prefix %>::<%= name.capitalize.singularize %>::Entities::<%= name.capitalize.singularize %>
|
56
56
|
end
|
57
57
|
|
58
58
|
<% end %>remove
|
@@ -66,7 +66,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
66
66
|
end
|
67
67
|
put "/:id/<%= k.downcase %>" do
|
68
68
|
error!("Can't find id #{params.id}", 422) unless <%= name.capitalize.singularize %>.all.pluck(:id).include?(params.id)
|
69
|
-
# present :<%= name.
|
69
|
+
# present :<%= name.underscore.pluralize %>, results, with: <%= GrapeResource.class_name_prefix %>::<%= name.capitalize.singularize %>::Entities::<%= name.capitalize.singularize %>
|
70
70
|
end
|
71
71
|
|
72
72
|
<% end %>remove
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "API::V1::<%= @name_of_class.camelize.pluralize %>::Resource::<%= @name_of_class.camelize.singularize %>", type: :request do
|
4
|
+
let(:<%= @name_of_class.underscore.singularize %>) {FactoryBot.create :<%= @name_of_class.underscore.singularize %>}
|
5
|
+
|
6
|
+
<% if @post.present? %>remove
|
7
|
+
<% @post.each do |k, v| %>remove
|
8
|
+
# Post method
|
9
|
+
describe "[POST] <%= k %>" do
|
10
|
+
it "success" do
|
11
|
+
post "/v1/<%= @name_of_class.underscore.singularize %>/<%= k %>"
|
12
|
+
expect(response.status).to eq(201)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
<% end %>remove
|
16
|
+
<% end %>remove
|
17
|
+
|
18
|
+
<% if @put.present? %>remove
|
19
|
+
<% @put.each do |k, v| %>remove
|
20
|
+
# Put method
|
21
|
+
describe "[PUT] <%= k %>" do
|
22
|
+
it "success" do
|
23
|
+
obj = FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
24
|
+
put "/v1/<%= @name_of_class.underscore.singularize %>/#{obj.id}/<%= k %>",
|
25
|
+
params: {
|
26
|
+
id: obj.id
|
27
|
+
}
|
28
|
+
expect(response.status).to eq(200)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
<% end %>remove
|
32
|
+
<% end %>remove
|
33
|
+
|
34
|
+
<% if @delete.present? %>remove
|
35
|
+
<% @delete.each do |k, v| %>remove
|
36
|
+
# Delete method
|
37
|
+
describe "[DELETE] <%= k %>" do
|
38
|
+
it "success" do
|
39
|
+
obj = FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
40
|
+
delete "/v1/<%= @name_of_class.underscore.singularize %>/#{obj.id}/<%= k %>",
|
41
|
+
params: {
|
42
|
+
id: obj.id
|
43
|
+
}
|
44
|
+
expect(response.status).to eq(200)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
<% end %>remove
|
48
|
+
<% end %>remove
|
49
|
+
|
50
|
+
<% if @collection.any? %>remove
|
51
|
+
<% @collection.each do |k, v| %>remove
|
52
|
+
# Collection method
|
53
|
+
describe "[GET] <%= k %>" do
|
54
|
+
it "success" do
|
55
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/<%= k %>"
|
56
|
+
expect(response.status).to eq(500) # Make sure your endpoint is working and you can change this status to 200
|
57
|
+
end
|
58
|
+
end
|
59
|
+
<% end %>remove
|
60
|
+
<% end %>remove
|
61
|
+
|
62
|
+
<% if @member.any? %>remove
|
63
|
+
<% @member.each do |k, v| %>remove
|
64
|
+
# Member method
|
65
|
+
describe "[GET] <%= k.underscore.pluralize %>" do
|
66
|
+
it "success" do
|
67
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/#{<%= @name_of_class.underscore.singularize %>.id}/<%= k %>"
|
68
|
+
expect(response.status).to eq(200)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
<% end %>remove
|
72
|
+
<% end %>remove
|
73
|
+
|
74
|
+
<% if @default_endpoint.present? %>remove
|
75
|
+
<% @default_endpoint.each do |endpoint| %>remove
|
76
|
+
# Default method
|
77
|
+
describe "[GET] <%= endpoint %>" do
|
78
|
+
before do
|
79
|
+
5.times do
|
80
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
81
|
+
end
|
82
|
+
end
|
83
|
+
it "success" do
|
84
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/<%= endpoint %>"
|
85
|
+
expect(response.status).to eq(200)
|
86
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "Pagination" do
|
91
|
+
before do
|
92
|
+
8.times do
|
93
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
94
|
+
end
|
95
|
+
5.times do
|
96
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
97
|
+
end
|
98
|
+
end
|
99
|
+
it "Paginate page 1" do
|
100
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/<%= endpoint %>",
|
101
|
+
params: {page: 1, per_page: 5}
|
102
|
+
expect(response.status).to eq(200)
|
103
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
104
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(5)
|
105
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(1)
|
106
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "Paginate page 2" do
|
110
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/<%= endpoint %>",
|
111
|
+
params: {page: 2, per_page: 5}
|
112
|
+
expect(response.status).to eq(200)
|
113
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
114
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(5)
|
115
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(2)
|
116
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "Paginate page 3" do
|
120
|
+
get "/v1/<%= @name_of_class.underscore.singularize %>/<%= endpoint %>",
|
121
|
+
params: {page: 3, per_page: 5}
|
122
|
+
expect(response.status).to eq(200)
|
123
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(3)
|
124
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(3)
|
125
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(3)
|
126
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
<% end %>remove
|
131
|
+
<% end %>remove
|
132
|
+
|
133
|
+
end
|
@@ -9,7 +9,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
9
9
|
results = <%= name.camelize.singularize %>.all
|
10
10
|
resources = paginate(results)
|
11
11
|
present_metas resources
|
12
|
-
present :<%= name.underscore %>, resources, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
12
|
+
present :<%= name.underscore.pluralize %>, resources, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
13
13
|
end
|
14
14
|
|
15
15
|
desc "Get <%= name.underscore.singularize %> by id"
|
@@ -18,7 +18,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
18
18
|
end
|
19
19
|
get "/:id" do
|
20
20
|
results = <%= name.camelize.singularize %>.find(params.id)
|
21
|
-
present :<%= name.underscore %>, results, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
21
|
+
present :<%= name.underscore.singularize %>, results, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
22
22
|
end
|
23
23
|
|
24
24
|
desc "Create"
|
@@ -31,7 +31,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
31
31
|
p = <%= name.camelize.singularize %>.new <%= name.underscore.singularize %>_params
|
32
32
|
results = p.save!
|
33
33
|
present :status, results
|
34
|
-
present :<%= name.underscore %>, p, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
34
|
+
present :<%= name.underscore.singularize %>, p, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
35
35
|
end
|
36
36
|
|
37
37
|
desc "Update"
|
@@ -44,7 +44,7 @@ class <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Re
|
|
44
44
|
put "/" do
|
45
45
|
p = <%= name.camelize.singularize %>.find(params.id)
|
46
46
|
p.update <%= name.underscore.singularize %>_params
|
47
|
-
present :<%= name.underscore %>, p, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
47
|
+
present :<%= name.underscore.singularize %>, p, with: <%= GrapeResource.class_name_prefix %>::<%= name.camelize.pluralize %>::Entities::<%= name.camelize.singularize %>
|
48
48
|
end
|
49
49
|
|
50
50
|
desc "Delete"
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "API::V1::<%= @name_of_class.camelize.pluralize %>::Resource::<%= @name_of_class.camelize.pluralize %>", type: :request do
|
4
|
+
|
5
|
+
describe "Create" do
|
6
|
+
it "success" do
|
7
|
+
post "/v1/<%= @name_of_class.underscore.pluralize %>",
|
8
|
+
params: {
|
9
|
+
<% @dummy.each do |k, v| %>remove
|
10
|
+
<% if v.class.name.underscore.in?(["integer", "boolean"]) %>remove
|
11
|
+
<%= k %>: <%= v %>,
|
12
|
+
<% else %>remove
|
13
|
+
<%= k %>: "<%= v %>",
|
14
|
+
<% end %>remove
|
15
|
+
<% end %>remove
|
16
|
+
}
|
17
|
+
expect(response.status).to eq(201)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Update" do
|
22
|
+
it "success" do
|
23
|
+
obj = FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
24
|
+
put "/v1/<%= @name_of_class.underscore.pluralize %>",
|
25
|
+
params: {
|
26
|
+
id: obj.id,
|
27
|
+
<% @dummy.each do |k, v| %>remove
|
28
|
+
<% if v.class.name.underscore.in?(["integer", "boolean"]) %>remove
|
29
|
+
<%= k %>: <%= v %>,
|
30
|
+
<% else %>remove
|
31
|
+
<%= k %>: "<%= v %>",
|
32
|
+
<% end %>remove
|
33
|
+
<% end %>remove
|
34
|
+
}
|
35
|
+
expect(response.status).to eq(200)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Delete" do
|
40
|
+
it "success" do
|
41
|
+
obj = FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
42
|
+
delete "/v1/<%= @name_of_class.underscore.pluralize %>",
|
43
|
+
params: {
|
44
|
+
id: obj.id
|
45
|
+
}
|
46
|
+
expect(response.status).to eq(200)
|
47
|
+
expect(json_response[:data][:status]).to eq("Success deleted data with id #{obj.id}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "[GET] <%= @name_of_class.camelize.singularize %> by ID" do
|
52
|
+
it "success" do
|
53
|
+
obj = FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
54
|
+
get "/v1/<%= @name_of_class.underscore.pluralize %>/#{obj.id}",
|
55
|
+
params: {
|
56
|
+
id: obj.id
|
57
|
+
}
|
58
|
+
expect(response.status).to eq(200)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "[GET] All <%= @name_of_class.camelize.pluralize %>" do
|
63
|
+
before do
|
64
|
+
5.times do
|
65
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
66
|
+
end
|
67
|
+
end
|
68
|
+
it "Get <%= @name_of_class.underscore.pluralize %>" do
|
69
|
+
get "/v1/<%= @name_of_class.underscore.pluralize %>"
|
70
|
+
expect(response.status).to eq(200)
|
71
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "Pagination" do
|
76
|
+
before do
|
77
|
+
8.times do
|
78
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
79
|
+
end
|
80
|
+
5.times do
|
81
|
+
FactoryBot.create :<%= @name_of_class.underscore.singularize %>
|
82
|
+
end
|
83
|
+
end
|
84
|
+
it "Paginate page 1" do
|
85
|
+
get "/v1/<%= @name_of_class.underscore.pluralize %>",
|
86
|
+
params: {page: 1, per_page: 5}
|
87
|
+
expect(response.status).to eq(200)
|
88
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
89
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(5)
|
90
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(1)
|
91
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "Paginate page 2" do
|
95
|
+
get "/v1/<%= @name_of_class.underscore.pluralize %>",
|
96
|
+
params: {page: 2, per_page: 5}
|
97
|
+
expect(response.status).to eq(200)
|
98
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(5)
|
99
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(5)
|
100
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(2)
|
101
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Paginate page 3" do
|
105
|
+
get "/v1/<%= @name_of_class.underscore.pluralize %>",
|
106
|
+
params: {page: 3, per_page: 5}
|
107
|
+
expect(response.status).to eq(200)
|
108
|
+
expect(json_response[:data][:<%= @name_of_class.underscore.pluralize %>].size).to eq(3)
|
109
|
+
expect(json_response[:data][:meta][:pages][:total]).to eq(3)
|
110
|
+
expect(json_response[:data][:meta][:pages][:page]).to eq(3)
|
111
|
+
expect(json_response[:data][:meta][:pages][:per_page]).to eq(5)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yunan Helmy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-07-
|
12
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -95,9 +95,10 @@ files:
|
|
95
95
|
- lib/generators/templates/entities.rb.erb
|
96
96
|
- lib/generators/templates/initializer.rb
|
97
97
|
- lib/generators/templates/namespace/namespace_endpoint.rb.erb
|
98
|
+
- lib/generators/templates/namespace/specs.rb.erb
|
98
99
|
- lib/generators/templates/rest/rest_endpoint.rb.erb
|
100
|
+
- lib/generators/templates/rest/specs.rb.erb
|
99
101
|
- lib/generators/templates/routes.rb.erb
|
100
|
-
- lib/generators/templates/specs.rb.erb
|
101
102
|
- lib/grape_resource.rb
|
102
103
|
- lib/grape_resource/configuration.rb
|
103
104
|
- lib/grape_resource/version.rb
|