auxiliary_rails 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958f50b63022de69faac6f1b94099164dbf3463d396e89788617bf12cedf8185
4
- data.tar.gz: c06b0c5d5e55f2f2bc7344ef3525d1a5078fa621562b81f24c72f7084b399b1a
3
+ metadata.gz: 55024b258096ba35ea6d1ae4279ee9193d8c127d96186f86c91842b5436e7745
4
+ data.tar.gz: dccf5c0d9d4de4776af52ef0b55a3ca7b78debf1077019f55483e034df290753
5
5
  SHA512:
6
- metadata.gz: 458a23d499bf1d4be3688c373f26c5e67fb021212f5164c55516d1d5d4319ab890a1c7ed40eb41908986be2111637c5588a26e46f399cd46114bf81e07dd608f
7
- data.tar.gz: 7c7612a040bbe55300c4e95ddcdce21b83735524cb36f78efef0882532bbfac9a75dd035946da699001388743c71a603e4819ce4aaadcd66b7d636d7fe3764ec
6
+ metadata.gz: 98e16100b8ac8cf42af60dfbd6ee79ef906f2537cce8170c1cd14eff4bda1890757f6b44d14b69140924541c4366b6f85b4d7063d7752add414583bf3134cd3d
7
+ data.tar.gz: 05e38836a6ed91b0df116239d0f3643c59615dc7ff074f7cfbedc15408a7e774dacc97f877a703ae82f4f6ed41f4b8588e9df6c18c2eef14255e37bdb46a6a16
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- auxiliary_rails (0.1.7)
4
+ auxiliary_rails (0.1.8)
5
5
  thor
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -46,14 +46,17 @@ rails new APP_PATH --skip-action-cable --skip-coffee --skip-test --database=post
46
46
  ### Generators
47
47
 
48
48
  ```sh
49
- # install everything
49
+ # Install everything at once
50
50
  rails generate auxiliary_rails:install
51
51
 
52
- # install one by one
52
+ # Install one by one
53
53
  rails generate auxiliary_rails:install_commands
54
54
  rails generate auxiliary_rails:install_errors
55
55
  rails generate auxiliary_rails:install_rubocop
56
56
  rails generate auxiliary_rails:install_rubocop --no-specify-gems
57
+
58
+ # API resource generator
59
+ rails generate auxiliary_rails:api_resource NAME
57
60
  ```
58
61
 
59
62
  ### View Helpers
@@ -1,3 +1,3 @@
1
1
  module AuxiliaryRails
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
@@ -37,7 +37,12 @@ module AuxiliaryRails
37
37
 
38
38
  def create_api_resource_spec_file
39
39
  template 'api_resource_spec_template.rb.erb',
40
- "spec/#{api_module_path}/#{plural_file_name}_resource_spec.rb"
40
+ "spec/#{api_module_path}/resources/#{plural_file_name}_resource_spec.rb"
41
+ end
42
+
43
+ def say_instructions
44
+ say "Mount resource in #{api_module_name}:"
45
+ say " mount #{resource_class_name}"
41
46
  end
42
47
 
43
48
  private
@@ -59,5 +64,9 @@ module AuxiliaryRails
59
64
  def entity_class_name
60
65
  "#{api_module_name}::Entities::#{class_name}Entity"
61
66
  end
67
+
68
+ def resource_class_name
69
+ "#{api_module_name}::Resources::#{plural_name.camelize}Resource"
70
+ end
62
71
  end
63
72
  end
@@ -1,6 +1,7 @@
1
1
  module <%= api_module_name %>::Entities
2
2
  class <%= class_name %>Entity < Grape::Entity
3
- expose :id
3
+ expose :id,
4
+ documentation: { type: 'Integer' }
4
5
  # TODO: define `<%= class_name %>Entity` exposes
5
6
  expose :created_at, :updated_at
6
7
  end
@@ -1,11 +1,18 @@
1
1
  require 'rails_helper'
2
2
 
3
- RSpec.describe <%= api_module_name %>::Resources::<%= plural_name.camelize %>Resource, type: :request do
3
+ RSpec.describe <%= resource_class_name %>, type: :request do
4
4
  describe 'GET <%= api_url_path %>' do
5
5
  subject { get '<%= api_url_path %>' }
6
6
 
7
- # TODO: write some tests
8
- skip
7
+ it 'returns a list of <%= plural_name %>' do
8
+ create_list(:<%= singular_name %>, 2)
9
+
10
+ subject
11
+
12
+ expect_status :ok
13
+ expect_json_sizes 2
14
+ expect_json '0', id: <%= class_name %> %>.first.id
15
+ end
9
16
  end
10
17
 
11
18
  describe 'POST <%= api_url_path %>' do
@@ -16,17 +23,37 @@ RSpec.describe <%= api_module_name %>::Resources::<%= plural_name.camelize %>Res
16
23
  end
17
24
 
18
25
  describe 'GET <%= api_url_path %>/:id' do
19
- # TODO: write some tests
20
- skip
26
+ subject { get "<%= api_url_path %>/#{<%= singular_name %>.id}" }
27
+
28
+ let(:<%= singular_name %>) { create(:<%= singular_name %>) }
29
+
30
+ it 'returns a <%= singular_name %> by ID' do
31
+ subject
32
+
33
+ expect_status :ok
34
+ expect_json id: <%= singular_name %>.id
35
+ end
21
36
  end
22
37
 
23
38
  describe 'PUT <%= api_url_path %>/:id' do
24
- # TODO: write some tests
25
- skip
39
+ subject { put "<%= api_url_path %>/#{<%= singular_name %>.id}" }
40
+
41
+ let(:<%= singular_name %>) { create(:<%= singular_name %>) }
42
+
43
+ it 'updates a <%= singular_name %> by ID' do
44
+ skip
45
+ end
26
46
  end
27
47
 
28
48
  describe 'DELETE <%= api_url_path %>/:id' do
29
- # TODO: write some tests
30
- skip
49
+ subject { delete "<%= api_url_path %>/#{<%= singular_name %>.id}" }
50
+
51
+ let!(:<%= singular_name %>) { create(:<%= singular_name %>) }
52
+
53
+ it 'deletes a <%= singular_name %> by ID' do
54
+ expect { subject }.to change(<%= class_name %>, :count).by -1
55
+ expect_status 204
56
+ expect(response.body).to be_blank
57
+ end
31
58
  end
32
59
  end
@@ -12,21 +12,25 @@ module <%= api_module_name %>::Resources
12
12
  end
13
13
 
14
14
  resource :<%= plural_name %> do
15
- desc 'Returns resource collection'
15
+ desc 'Returns a collection of <%= plural_name %>' do
16
+ success <%= entity_class_name %>
17
+ end
16
18
  get do
17
- # TODO: authorize resource, :index?
19
+ # TODO: authorize <%= class_name %>, :index?
18
20
  present collection,
19
21
  with: <%= entity_class_name %>
20
22
  end
21
23
 
22
- desc 'Creates a <%= class_name %>'
24
+ desc 'Creates a <%= class_name %>' do
25
+ success <%= entity_class_name %>
26
+ end
23
27
  params do
24
28
  requires :<%= singular_name %>, type: Hash do
25
29
  # TODO: define resource params or remove `params` block
26
30
  end
27
31
  end
28
32
  post do
29
- @<%= singular_name %> = <%= class_name %>.new(declared(params)[:<%= singular_name %>])
33
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
30
34
  # TODO: authorize resource, :create?
31
35
  resource.save!
32
36
  present resource,
@@ -44,14 +48,16 @@ module <%= api_module_name %>::Resources
44
48
  with: <%= entity_class_name %>
45
49
  end
46
50
 
47
- desc 'Updates a <%= class_name %>'
51
+ desc 'Updates a <%= class_name %>' do
52
+ success <%= entity_class_name %>
53
+ end
48
54
  params do
49
55
  requires :<%= singular_name %>, type: Hash do
50
56
  # TODO: define resource params or remove `params` block
51
57
  end
52
58
  end
53
59
  put do
54
- resource.assign_attributes(declared(params)[:<%= singular_name %>])
60
+ resource.assign_attributes(params[:<%= singular_name %>])
55
61
  # TODO: authorize resource, :update?
56
62
  resource.save!
57
63
  present resource,
@@ -1,6 +1,6 @@
1
1
  # AuxiliaryRails RuboCop Config
2
2
  # Homepage: https://github.com/ergoserv/auxiliary_rails
3
- # Version: 7
3
+ # Version: 8
4
4
 
5
5
  AllCops:
6
6
  Exclude:
@@ -17,9 +17,20 @@ Layout/AlignArguments:
17
17
 
18
18
  #################### Metrics ###############################
19
19
 
20
+ Metrics/BlockLength:
21
+ ExcludedMethods:
22
+ - describe
23
+ - resource
24
+
20
25
  Metrics/MethodLength:
21
26
  Max: 30
22
27
 
28
+ #################### Naming ################################
29
+
30
+ Naming/MemoizedInstanceVariableName:
31
+ Exclude:
32
+ - 'app/apis/**/resources/*_resource.rb'
33
+
23
34
  #################### Rails #################################
24
35
 
25
36
  Rails:
@@ -27,6 +38,9 @@ Rails:
27
38
 
28
39
  #################### RSpec #################################
29
40
 
41
+ RSpec/ExampleLength:
42
+ Max: 10
43
+
30
44
  RSpec/NamedSubject:
31
45
  Enabled: false
32
46
 
@@ -1,6 +1,10 @@
1
1
  inherit_from:
2
2
  - .rubocop_auxiliary_rails.yml
3
3
 
4
+ inherit_mode:
5
+ merge:
6
+ - Exclude
7
+
4
8
  require:
5
9
  - rubocop-performance
6
10
  - rubocop-rails
@@ -9,6 +9,7 @@ gem 'auxiliary_rails',
9
9
  branch: 'develop'
10
10
 
11
11
  gem_group :development, :test do
12
+ gem 'dotenv-rails'
12
13
  gem 'factory_bot_rails'
13
14
  gem 'faker'
14
15
  gem 'pry-byebug'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auxiliary_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Babenko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-23 00:00:00.000000000 Z
12
+ date: 2019-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler