js_rails_routes 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff931b1b9f29b4a86444a8613d653a32961bc378e86d44fdc25cf319bcd9cc86
4
- data.tar.gz: ce054504cf1e89cde6d76bca05f5fb03834740e8ff0a2e9acdea76326ef3e8ce
3
+ metadata.gz: cd2383225d89dcc53076b7dd12b2600c09659dae5ddee39e7da9dd2f7d8d09dd
4
+ data.tar.gz: a9162a939abd31bd7fe552255846caf6a4ffbcf1ba80737e058bfe868ca2b4c0
5
5
  SHA512:
6
- metadata.gz: 932d0666655cf343988cdd19730ed038b662d6efa86c36a1e97c63a9f98a7c1cbe51a4abdc5a14903814f6a578e597a123e782ebb85a5c3dfa9e0807f7fbca25
7
- data.tar.gz: b6c2ad6c62c1c95b6db17386468801a1fc543c60fed064b253a36458c3b14cb3614b9928c495a1f26d53e02946735a452106388ad5f46ebd8af96b494b5578a6
6
+ metadata.gz: 1c900ddad4563c435937edba1c072a299438a80290b6cd77b48f2a00493c37919a987606ed7c8a7784480dcbfd2a85c52f9ce50f59b5896914165ea6bd5d1255
7
+ data.tar.gz: c27c9ce37e7d8de9031cdc13ff2c412c4ecc627f54183f67a478dd99d5dde4dde7e6c444320c7794a2e03156af22bb3c0a82b7293a359c37b33e50e4c9bd1e14
@@ -0,0 +1,43 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ test:
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os: ['ubuntu-18.04', 'ubuntu-latest', 'macos-latest']
19
+ ruby: [2.6, 2.7, 3.0, 3.1]
20
+ experimental: [false]
21
+ include:
22
+ - os: 'ubuntu-latest'
23
+ ruby: 'head'
24
+ experimental: true
25
+ runs-on: ${{ matrix.os }}
26
+ continue-on-error: ${{ matrix.experimental }}
27
+ steps:
28
+ - name: Get branch names
29
+ id: branch-name
30
+ uses: tj-actions/branch-names@v4.9
31
+ - uses: actions/checkout@v2
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ bundler-cache: true
36
+ - name: Test & publish code coverage
37
+ uses: paambaati/codeclimate-action@v2.7.5
38
+ env:
39
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
40
+ GIT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
41
+ GIT_COMMIT_SHA: ${{ github.sha }}
42
+ with:
43
+ coverageCommand: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,8 +1,11 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  require:
2
4
  - rubocop-rspec
3
5
 
4
6
  AllCops:
5
- TargetRubyVersion: 2.3
7
+ TargetRubyVersion: 2.6
8
+ NewCops: enable
6
9
 
7
10
  Metrics/LineLength:
8
11
  Max: 120
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-05-10 07:01:52 UTC using RuboCop version 1.27.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/CHANGELOG.md CHANGED
@@ -6,6 +6,25 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.0] - 2022-05-13
10
+
11
+ ### Changed
12
+ - Remove codeclimate and execute rubocop in github actions
13
+ - Update corporate name from Increments Inc. to Qiita Inc.
14
+ - Update gem authors and emails in gemspec file
15
+ - Change ci from travis.ci to github actions
16
+ - Drop supporting legacy Ruby versions
17
+ - Add supporting new ruby versions
18
+ - Depend on rails >= 6.0
19
+
20
+ ## [0.10.1] - 2020-03-09
21
+ ### Fixed
22
+ - Improved TypeScript typing
23
+
24
+ ## [0.10.0] - 2018-10-29
25
+ ### Added
26
+ - Enable to change route's name
27
+
9
28
  ## [0.9.0] - 2018-08-24
10
29
  ### Added
11
30
  - Improved TypeScript params typing support
@@ -70,16 +89,19 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
70
89
  ### Added
71
90
  - Implement "js:rails:routes" task
72
91
 
73
- [Unreleased]: https://github.com/yuku-t/js_rails_routes/compare/v0.9.0...HEAD
74
- [0.9.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.8.1...v0.9.0
75
- [0.8.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.8.0...v0.8.1
76
- [0.8.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.7.1...v0.8.0
77
- [0.7.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.7.0...v0.7.1
78
- [0.7.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.6.0...v0.7.0
79
- [0.6.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.5.0...v0.6.0
80
- [0.5.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.4.0...v0.5.0
81
- [0.4.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.3.0...v0.4.0
82
- [0.3.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.1...v0.3.0
83
- [0.2.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.0...v0.2.1
84
- [0.2.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.1.0...v0.2.0
85
- [0.1.0]: https://github.com/yuku-t/js_rails_routes/compare/033b945...v0.1.0
92
+ [Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.0.0...HEAD
93
+ [1.0.0]: https://github.com/increments/js_rails_routes/compare/v0.10.1...v1.0.0
94
+ [0.10.1]: https://github.com/increments/js_rails_routes/compare/v0.10.0...v0.10.1
95
+ [0.10.0]: https://github.com/increments/js_rails_routes/compare/v0.9.0...v0.10.0
96
+ [0.9.0]: https://github.com/increments/js_rails_routes/compare/v0.8.1...v0.9.0
97
+ [0.8.1]: https://github.com/increments/js_rails_routes/compare/v0.8.0...v0.8.1
98
+ [0.8.0]: https://github.com/increments/js_rails_routes/compare/v0.7.1...v0.8.0
99
+ [0.7.1]: https://github.com/increments/js_rails_routes/compare/v0.7.0...v0.7.1
100
+ [0.7.0]: https://github.com/increments/js_rails_routes/compare/v0.6.0...v0.7.0
101
+ [0.6.0]: https://github.com/increments/js_rails_routes/compare/v0.5.0...v0.6.0
102
+ [0.5.0]: https://github.com/increments/js_rails_routes/compare/v0.4.0...v0.5.0
103
+ [0.4.0]: https://github.com/increments/js_rails_routes/compare/v0.3.0...v0.4.0
104
+ [0.3.0]: https://github.com/increments/js_rails_routes/compare/v0.2.1...v0.3.0
105
+ [0.2.1]: https://github.com/increments/js_rails_routes/compare/v0.2.0...v0.2.1
106
+ [0.2.0]: https://github.com/increments/js_rails_routes/compare/v0.1.0...v0.2.0
107
+ [0.1.0]: https://github.com/increments/js_rails_routes/compare/033b945...v0.1.0
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Yuku TAKAHASHI
3
+ Copyright (c) 2018 Qiita Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
1
  # rake js:routes
2
2
 
3
3
  [![Gem](https://img.shields.io/gem/v/js_rails_routes.svg?maxAge=2592000)](https://rubygems.org/gems/js_rails_routes)
4
- [![Build Status](https://travis-ci.org/yuku/js_rails_routes.svg?branch=master)](https://travis-ci.org/yuku/js_rails_routes)
5
- [![Code Climate](https://codeclimate.com/github/yuku/js_rails_routes/badges/gpa.svg)](https://codeclimate.com/github/yuku/js_rails_routes)
6
- [![Test Coverage](https://codeclimate.com/github/yuku/js_rails_routes/badges/coverage.svg)](https://codeclimate.com/github/yuku/js_rails_routes/coverage)
7
- [![license](https://img.shields.io/github/license/yuku/js_rails_routes.svg?maxAge=2592000)](https://github.com/yuku/js_rails_routes/blob/master/LICENSE)
8
- [![Analytics](https://ga-beacon.appspot.com/UA-4932407-14/js_rails_routes/readme)](https://github.com/igrigorik/ga-beacon)
4
+ ![Build Status](https://github.com/increments/js_rails_routes/actions/workflows/test.yml/badge.svg?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/increments/js_rails_routes/badges/gpa.svg)](https://codeclimate.com/github/increments/js_rails_routes)
6
+ [![Test Coverage](https://codeclimate.com/github/increments/js_rails_routes/badges/coverage.svg)](https://codeclimate.com/github/increments/js_rails_routes/coverage)
7
+ [![license](https://img.shields.io/github/license/increments/js_rails_routes.svg?maxAge=2592000)](https://github.com/increments/js_rails_routes/blob/master/LICENSE)
9
8
 
10
9
  Generate a ES6 module that contains Rails routes.
11
10
 
@@ -110,6 +109,21 @@ rake js:routes exclude_paths='^/rails'
110
109
 
111
110
  The command still ignores "/rails" but includes "/sidekiq".
112
111
 
112
+ ### Rename route
113
+
114
+ You can rename route in `route_filter`:
115
+
116
+ ```rb
117
+ # Rakefile
118
+ JSRailsRoutes.configure do |c|
119
+ c.route_filter = -> (route) do
120
+ # Remove common prefix if route's name starts with it.
121
+ route.name = route.name[4..-1] if route.name.start_with?('foo_')
122
+ true
123
+ end
124
+ end
125
+ ```
126
+
113
127
  ## Install
114
128
 
115
129
  Your Rails Gemfile:
@@ -120,10 +134,4 @@ gem 'js_rails_routes', group: :development
120
134
 
121
135
  ## License
122
136
 
123
- [MIT](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
124
-
125
- ## Author
126
-
127
- [mizchi](https://github.com/mizchi) wrote "js:routes" task with referencing [mtrpcic/js-routes](https://github.com/mtrpcic/js-routes).
128
-
129
- [yuku-t](https://yuku-t.com) refactored and improved the mizchi's script and published to [rubygems](https://rubygems.org/gems/js_rails_routes).
137
+ [MIT](https://github.com/increments/js_rails_routes/blob/master/LICENSE)
@@ -7,21 +7,22 @@ require 'js_rails_routes/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'js_rails_routes'
9
9
  spec.version = JSRailsRoutes::VERSION
10
- spec.authors = ['Yuku Takahashi']
11
- spec.email = ['taka84u9@gmail.com']
10
+ spec.authors = ['Qiita Inc.']
11
+ spec.email = ['engineers@qiita.com']
12
12
  spec.summary = 'Generate a ES6 module that contains Rails routes.'
13
- spec.homepage = 'https://github.com/yuku-t/js_rails_routes'
13
+ spec.homepage = 'https://github.com/increments/js_rails_routes'
14
14
  spec.license = 'MIT'
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.require_paths = ['lib']
17
- spec.required_ruby_version = '>= 2.3.0'
17
+ spec.required_ruby_version = '>= 2.6.0'
18
18
 
19
- spec.add_dependency 'rails', '>= 3.2'
20
- spec.add_development_dependency 'bundler', '~> 1.16'
19
+ spec.add_dependency 'rails', '>= 6.0'
20
+ spec.add_development_dependency 'bundler', '>= 1.16'
21
21
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
22
22
  spec.add_development_dependency 'rake', '~> 12.3'
23
- spec.add_development_dependency 'rspec', '~> 3.7'
24
- spec.add_development_dependency 'rubocop', '~> 0.58.1'
25
- spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
26
- spec.add_development_dependency 'simplecov', '~> 0.16.1'
23
+ spec.add_development_dependency 'rspec', '~> 3.8'
24
+ spec.add_development_dependency 'rubocop', '~> 1.27.0'
25
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
26
+ spec.add_development_dependency 'simplecov', '~> 0.16.1', '!= 0.18.0', '!= 0.18.1', '!= 0.18.2', '!= 0.18.3', '!= 0.18.4', '!= 0.18.5', '!= 0.19.0', '!= 0.19.1' # rubocop:disable Metrics/LineLength
27
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
28
  end
@@ -13,7 +13,7 @@ module JSRailsRoutes
13
13
  :route_filter,
14
14
  :route_set_filter
15
15
 
16
- def initialize
16
+ def initialize # rubocop:disable Metrics/AbcSize
17
17
  self.include_paths = /.*/
18
18
  self.exclude_paths = /^$/
19
19
  self.include_names = /.*/
@@ -27,7 +27,7 @@ module JSRailsRoutes
27
27
  end
28
28
 
29
29
  # @param env [Hash{String=>String}]
30
- def configure_with_env_vars(env = ENV)
30
+ def configure_with_env_vars(env = ENV) # rubocop:disable Metrics/AbcSize
31
31
  %w[include_paths exclude_paths include_names exclude_names exclude_engines].each do |name|
32
32
  public_send("#{name}=", Regexp.new(env[name])) if env[name]
33
33
  end
@@ -5,7 +5,7 @@ module JSRailsRoutes
5
5
  class Base
6
6
  # @param routes [JSRailsRoutes::RouteSet]
7
7
  # @return [String]
8
- def handle_route_set(routes) # rubocop:disable Lint/UnusedMethodArgument
8
+ def handle_route_set(routes)
9
9
  raise NotImplementedError
10
10
  end
11
11
 
@@ -20,9 +20,10 @@ module JSRailsRoutes
20
20
 
21
21
  # @note Implementation for {JSRailsRoutes::Language::Base#generate}
22
22
  def handle_route_set(routes)
23
- routes.each_with_object([self.class::PROCESS_FUNC]) do |route, lines|
23
+ set = routes.each_with_object([self.class::PROCESS_FUNC]) do |route, lines|
24
24
  lines.push(handle_route(route))
25
- end.join("\n") + "\n"
25
+ end.join("\n")
26
+ "#{set}\n"
26
27
  end
27
28
 
28
29
  # @param route [JSRailsRoutes::Route]
@@ -56,7 +57,7 @@ module JSRailsRoutes
56
57
  # @param route_name [String]
57
58
  # @return [String]
58
59
  def function_name(route_name)
59
- url_helper_name = route_name + '_path'
60
+ url_helper_name = "#{route_name}_path"
60
61
  config.camelize.nil? ? url_helper_name : url_helper_name.camelize(config.camelize)
61
62
  end
62
63
 
@@ -11,7 +11,7 @@ module JSRailsRoutes
11
11
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
12
12
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
13
13
  if (!params) return route
14
- var query = [];
14
+ var query: string[] = [];
15
15
  for (var param in params) if (params.hasOwnProperty(param)) {
16
16
  if (keys.indexOf(param) === -1) {
17
17
  query.push(param + "=" + encodeURIComponent(params[param].toString()));
@@ -3,8 +3,8 @@
3
3
  module JSRailsRoutes
4
4
  # Encapsulate a single routing rule
5
5
  class Route
6
- # @return [String]
7
- attr_reader :name
6
+ # @return [String] route name. It becomes JavaScript function name.
7
+ attr_accessor :name
8
8
 
9
9
  # @return [String]
10
10
  attr_reader :path
@@ -25,6 +25,7 @@ module JSRailsRoutes
25
25
  return false if config.exclude_paths =~ path
26
26
  return false if config.include_names !~ name
27
27
  return false if config.exclude_names =~ name
28
+
28
29
  config.route_filter.call(self)
29
30
  end
30
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSRailsRoutes
4
- VERSION = '0.9.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -8,7 +8,7 @@ require 'js_rails_routes/language/javascript'
8
8
  require 'js_rails_routes/language/typescript'
9
9
 
10
10
  module JSRailsRoutes
11
- PARAM_REGEXP = %r{:(.*?)(/|$)}
11
+ PARAM_REGEXP = %r{:(.*?)(/|$)}.freeze
12
12
 
13
13
  module_function
14
14
 
@@ -35,6 +35,7 @@ module JSRailsRoutes
35
35
  # @yield
36
36
  def sandbox
37
37
  raise 'Already in a sandbox' if @sandbox
38
+
38
39
  @sandbox = true
39
40
  prev = @config
40
41
  @config = Configuration.new
@@ -5,7 +5,7 @@ RSpec.describe JSRailsRoutes::Builder do
5
5
 
6
6
  include_context 'run in a sandbox'
7
7
 
8
- let(:language) { instance_double('JSRailsRoutes::Language::Base', handle_route_set: body, ext: %w[js ts].sample) }
8
+ let(:language) { instance_double(JSRailsRoutes::Language::Base, handle_route_set: body, ext: %w[js ts].sample) }
9
9
  let(:body) { 'hello' }
10
10
  let(:route_set_list) { [rails_route_set, engine_route_set] }
11
11
 
@@ -31,7 +31,7 @@ RSpec.describe JSRailsRoutes::Builder do
31
31
  subject { builder.build }
32
32
 
33
33
  it 'returns an array of artifacts' do
34
- is_expected.to contain_exactly(
34
+ expect(subject).to contain_exactly(
35
35
  an_object_having_attributes(engine_name: rails_route_set.name, body: body),
36
36
  an_object_having_attributes(engine_name: engine_route_set.name, body: body)
37
37
  )
@@ -7,7 +7,7 @@ RSpec.describe JSRailsRoutes::Configuration do
7
7
  subject { config.configure_with_env_vars(env) }
8
8
 
9
9
  context 'with empty env' do
10
- let(:env) { Hash[] }
10
+ let(:env) { {} }
11
11
 
12
12
  it 'does not change' do
13
13
  expect { subject }.to not_change(config, :include_paths)
@@ -21,7 +21,7 @@ RSpec.describe JSRailsRoutes::Configuration do
21
21
  end
22
22
 
23
23
  context 'with include_paths env' do
24
- let(:env) { Hash['include_paths' => 'a'] }
24
+ let(:env) { { 'include_paths' => 'a' } }
25
25
 
26
26
  it 'changes #include_paths' do
27
27
  expect { subject }.to change(config, :include_paths).to eq(/a/)
@@ -29,7 +29,7 @@ RSpec.describe JSRailsRoutes::Configuration do
29
29
  end
30
30
 
31
31
  context 'with exclude_paths env' do
32
- let(:env) { Hash['exclude_paths' => 'a'] }
32
+ let(:env) { { 'exclude_paths' => 'a' } }
33
33
 
34
34
  it 'changes #exclude_paths' do
35
35
  expect { subject }.to change(config, :exclude_paths).to eq(/a/)
@@ -37,7 +37,7 @@ RSpec.describe JSRailsRoutes::Configuration do
37
37
  end
38
38
 
39
39
  context 'with include_names env' do
40
- let(:env) { Hash['include_names' => 'a'] }
40
+ let(:env) { { 'include_names' => 'a' } }
41
41
 
42
42
  it 'changes #include_names' do
43
43
  expect { subject }.to change(config, :include_names).to eq(/a/)
@@ -45,7 +45,7 @@ RSpec.describe JSRailsRoutes::Configuration do
45
45
  end
46
46
 
47
47
  context 'with exclude_names env' do
48
- let(:env) { Hash['exclude_names' => 'a'] }
48
+ let(:env) { { 'exclude_names' => 'a' } }
49
49
 
50
50
  it 'changes #exclude_names' do
51
51
  expect { subject }.to change(config, :exclude_names).to eq(/a/)
@@ -53,7 +53,7 @@ RSpec.describe JSRailsRoutes::Configuration do
53
53
  end
54
54
 
55
55
  context 'with exclude_engines env' do
56
- let(:env) { Hash['exclude_engines' => 'a'] }
56
+ let(:env) { { 'exclude_engines' => 'a' } }
57
57
 
58
58
  it 'changes #exclude_engines' do
59
59
  expect { subject }.to change(config, :exclude_engines).to eq(/a/)
@@ -61,7 +61,7 @@ RSpec.describe JSRailsRoutes::Configuration do
61
61
  end
62
62
 
63
63
  context 'with output_dir env' do
64
- let(:env) { Hash['output_dir' => 'path'] }
64
+ let(:env) { { 'output_dir' => 'path' } }
65
65
 
66
66
  it 'changes #output_dir' do
67
67
  expect { subject }.to change(config, :output_dir).to eq 'path'
@@ -69,7 +69,7 @@ RSpec.describe JSRailsRoutes::Configuration do
69
69
  end
70
70
 
71
71
  context 'with camelize env' do
72
- let(:env) { Hash['camelize' => 'lower'] }
72
+ let(:env) { { 'camelize' => 'lower' } }
73
73
 
74
74
  it 'changes #camelize' do
75
75
  expect { subject }.to change(config, :camelize).to eq :lower
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe JSRailsRoutes::Generator do
4
- include_context 'run in a sandbox'
5
-
6
4
  subject(:generator) { described_class.new(builder, writable: writable) }
7
5
 
6
+ include_context 'run in a sandbox'
7
+
8
8
  let(:writable) { spy('writable') }
9
9
  let(:builder) { double('builder', build: result) }
10
10
  let(:result) do
@@ -9,7 +9,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
9
9
  subject { described_class::PROCESS_FUNC }
10
10
 
11
11
  it 'returns a javascript function' do
12
- is_expected.to eq <<~JAVASCRIPT
12
+ expect(subject).to eq <<~JAVASCRIPT
13
13
  function process(route, params, keys) {
14
14
  var query = [];
15
15
  for (var param in params) if (params.hasOwnProperty(param)) {
@@ -37,7 +37,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
37
37
 
38
38
  context 'without camelize option' do
39
39
  it 'returns a javascript with snake_case functions' do
40
- is_expected.to eq <<~JAVASCRIPT
40
+ expect(subject).to eq <<~JAVASCRIPT
41
41
  #{described_class::PROCESS_FUNC}
42
42
  export function articles_path(params) { return process('/articles', params, []); }
43
43
  export function new_article_path(params) { return process('/articles/new', params, []); }
@@ -55,7 +55,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
55
55
  end
56
56
 
57
57
  it 'returns a javascript with lowerCamelCase functions' do
58
- is_expected.to eq <<~JAVASCRIPT
58
+ expect(subject).to eq <<~JAVASCRIPT
59
59
  #{described_class::PROCESS_FUNC}
60
60
  export function articlesPath(params) { return process('/articles', params, []); }
61
61
  export function newArticlePath(params) { return process('/articles/new', params, []); }
@@ -73,7 +73,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
73
73
  end
74
74
 
75
75
  it 'returns a javascript with UpperCamelCase functions' do
76
- is_expected.to eq <<~JAVASCRIPT
76
+ expect(subject).to eq <<~JAVASCRIPT
77
77
  #{described_class::PROCESS_FUNC}
78
78
  export function ArticlesPath(params) { return process('/articles', params, []); }
79
79
  export function NewArticlePath(params) { return process('/articles/new', params, []); }
@@ -91,7 +91,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
91
91
  end
92
92
 
93
93
  it 'returns a javascript matching to the regexp' do
94
- is_expected.to eq <<~JAVASCRIPT
94
+ expect(subject).to eq <<~JAVASCRIPT
95
95
  #{described_class::PROCESS_FUNC}
96
96
  export function new_article_path(params) { return process('/articles/new', params, []); }
97
97
  JAVASCRIPT
@@ -106,7 +106,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
106
106
  end
107
107
 
108
108
  it 'returns a javascript not matching to the regexp' do
109
- is_expected.to eq <<~JAVASCRIPT
109
+ expect(subject).to eq <<~JAVASCRIPT
110
110
  #{described_class::PROCESS_FUNC}
111
111
  export function articles_path(params) { return process('/articles', params, []); }
112
112
  export function edit_article_path(params) { return process('/articles/' + params.id + '/edit', params, ['id']); }
@@ -123,7 +123,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
123
123
  end
124
124
 
125
125
  it 'returns a javascript matching to the regexp' do
126
- is_expected.to eq <<~JAVASCRIPT
126
+ expect(subject).to eq <<~JAVASCRIPT
127
127
  #{described_class::PROCESS_FUNC}
128
128
  export function new_article_path(params) { return process('/articles/new', params, []); }
129
129
  JAVASCRIPT
@@ -138,7 +138,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
138
138
  end
139
139
 
140
140
  it 'returns a javascript not matching to the regexp' do
141
- is_expected.to eq <<~JAVASCRIPT
141
+ expect(subject).to eq <<~JAVASCRIPT
142
142
  #{described_class::PROCESS_FUNC}
143
143
  export function articles_path(params) { return process('/articles', params, []); }
144
144
  export function edit_article_path(params) { return process('/articles/' + params.id + '/edit', params, ['id']); }
@@ -9,12 +9,12 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
9
9
  subject { described_class::PROCESS_FUNC }
10
10
 
11
11
  it 'returns a typescript function' do
12
- is_expected.to eq <<~TYPESCRIPT
12
+ expect(subject).to eq <<~TYPESCRIPT
13
13
  type Value = string | number
14
14
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
15
15
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
16
16
  if (!params) return route
17
- var query = [];
17
+ var query: string[] = [];
18
18
  for (var param in params) if (params.hasOwnProperty(param)) {
19
19
  if (keys.indexOf(param) === -1) {
20
20
  query.push(param + "=" + encodeURIComponent(params[param].toString()));
@@ -40,7 +40,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
40
40
 
41
41
  context 'without camelize option' do
42
42
  it 'returns a typescript with snake_case functions' do
43
- is_expected.to eq <<~TYPESCRIPT
43
+ expect(subject).to eq <<~TYPESCRIPT
44
44
  #{described_class::PROCESS_FUNC}
45
45
  export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
46
46
  export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
@@ -58,7 +58,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
58
58
  end
59
59
 
60
60
  it 'returns a javascript with lowerCamelCase functions' do
61
- is_expected.to eq <<~TYPESCRIPT
61
+ expect(subject).to eq <<~TYPESCRIPT
62
62
  #{described_class::PROCESS_FUNC}
63
63
  export function articlesPath(params?: Record<string, Value>) { return process('/articles', params, []); }
64
64
  export function newArticlePath(params?: Record<string, Value>) { return process('/articles/new', params, []); }
@@ -76,7 +76,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
76
76
  end
77
77
 
78
78
  it 'returns a javascript with UpperCamelCase functions' do
79
- is_expected.to eq <<~TYPESCRIPT
79
+ expect(subject).to eq <<~TYPESCRIPT
80
80
  #{described_class::PROCESS_FUNC}
81
81
  export function ArticlesPath(params?: Record<string, Value>) { return process('/articles', params, []); }
82
82
  export function NewArticlePath(params?: Record<string, Value>) { return process('/articles/new', params, []); }
@@ -94,7 +94,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
94
94
  end
95
95
 
96
96
  it 'returns a javascript matching to the regexp' do
97
- is_expected.to eq <<~TYPESCRIPT
97
+ expect(subject).to eq <<~TYPESCRIPT
98
98
  #{described_class::PROCESS_FUNC}
99
99
  export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
100
100
  TYPESCRIPT
@@ -109,7 +109,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
109
109
  end
110
110
 
111
111
  it 'returns a javascript not matching to the regexp' do
112
- is_expected.to eq <<~TYPESCRIPT
112
+ expect(subject).to eq <<~TYPESCRIPT
113
113
  #{described_class::PROCESS_FUNC}
114
114
  export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
115
115
  export function edit_article_path(params: Params<'id'>) { return process('/articles/' + params.id + '/edit', params, ['id']); }
@@ -126,7 +126,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
126
126
  end
127
127
 
128
128
  it 'returns a javascript matching to the regexp' do
129
- is_expected.to eq <<~TYPESCRIPT
129
+ expect(subject).to eq <<~TYPESCRIPT
130
130
  #{described_class::PROCESS_FUNC}
131
131
  export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
132
132
  TYPESCRIPT
@@ -141,7 +141,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
141
141
  end
142
142
 
143
143
  it 'returns a javascript not matching to the regexp' do
144
- is_expected.to eq <<~TYPESCRIPT
144
+ expect(subject).to eq <<~TYPESCRIPT
145
145
  #{described_class::PROCESS_FUNC}
146
146
  export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
147
147
  export function edit_article_path(params: Params<'id'>) { return process('/articles/' + params.id + '/edit', params, ['id']); }
@@ -20,7 +20,7 @@ RSpec.describe JSRailsRoutes::RouteSet do
20
20
 
21
21
  it 'returns an array of matching route sets' do
22
22
  # See spec/support/test_app.rb
23
- is_expected.to match [
23
+ expect(subject).to match [
24
24
  be_a(described_class).and(have_attributes(name: 'Rails')).and(be_match),
25
25
  be_a(described_class).and(have_attributes(name: 'Admin::Engine')).and(be_match)
26
26
  ]
@@ -46,8 +46,8 @@ RSpec.describe JSRailsRoutes::RouteSet do
46
46
  end
47
47
 
48
48
  it "doesn't include the excluded route" do
49
- is_expected.to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /articles/))
50
- is_expected.not_to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /users/))
49
+ expect(subject).to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /articles/))
50
+ expect(subject).not_to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /users/))
51
51
  end
52
52
  end
53
53
  end
@@ -78,7 +78,11 @@ RSpec.describe JSRailsRoutes::RouteSet do
78
78
  end
79
79
 
80
80
  context 'when routes are empty' do
81
- before { allow(route_set).to receive(:routes).and_return([]) }
81
+ let(:routes) do
82
+ ActionDispatch::Routing::RouteSet.new.tap do |routes|
83
+ routes.draw {} # rubocop:disable Lint/EmptyBlock
84
+ end
85
+ end
82
86
 
83
87
  it { is_expected.to be false }
84
88
  end
@@ -19,6 +19,14 @@ RSpec.describe JSRailsRoutes::Route do
19
19
  it { is_expected.to eq 'articles' }
20
20
  end
21
21
 
22
+ describe '#name=' do
23
+ subject { route.name = value }
24
+
25
+ let(:value) { 'foo' }
26
+
27
+ it { expect { subject }.to change(route, :name).to(value) }
28
+ end
29
+
22
30
  describe '#path' do
23
31
  subject { route.path }
24
32
 
@@ -25,10 +25,10 @@ RSpec.describe JSRailsRoutes do
25
25
  end
26
26
 
27
27
  describe '.generate' do
28
- include_context 'run in a sandbox'
29
-
30
28
  subject { described_class.generate(task) }
31
29
 
30
+ include_context 'run in a sandbox'
31
+
32
32
  let(:task) { 'js:routes' }
33
33
  let(:app_root) { JSRailsRoutes::SpecHelper::TestApp.root }
34
34
 
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,7 @@ SimpleCov.start
8
8
  require 'rails/all'
9
9
  require 'js_rails_routes'
10
10
 
11
- Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
11
+ Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }
12
12
 
13
13
  RSpec.configure do |config|
14
14
  config.expect_with :rspec do |expectations|
@@ -27,8 +27,7 @@ module JSRailsRoutes
27
27
  'Empty::Engine'
28
28
  end
29
29
 
30
- routes.draw do
31
- end
30
+ routes.draw {} # rubocop:disable Lint/EmptyBlock
32
31
  end
33
32
  end
34
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_rails_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Yuku Takahashi
7
+ - Qiita Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-24 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,26 +16,26 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.16'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
41
  - !ruby/object:Gem::Dependency
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.7'
75
+ version: '3.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.7'
82
+ version: '3.8'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.58.1
89
+ version: 1.27.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.58.1
96
+ version: 1.27.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.27'
103
+ version: '2.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.27'
110
+ version: '2.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,30 @@ dependencies:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 0.16.1
118
+ - - "!="
119
+ - !ruby/object:Gem::Version
120
+ version: 0.18.0
121
+ - - "!="
122
+ - !ruby/object:Gem::Version
123
+ version: 0.18.1
124
+ - - "!="
125
+ - !ruby/object:Gem::Version
126
+ version: 0.18.2
127
+ - - "!="
128
+ - !ruby/object:Gem::Version
129
+ version: 0.18.3
130
+ - - "!="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.18.4
133
+ - - "!="
134
+ - !ruby/object:Gem::Version
135
+ version: 0.18.5
136
+ - - "!="
137
+ - !ruby/object:Gem::Version
138
+ version: 0.19.0
139
+ - - "!="
140
+ - !ruby/object:Gem::Version
141
+ version: 0.19.1
118
142
  type: :development
119
143
  prerelease: false
120
144
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,18 +146,42 @@ dependencies:
122
146
  - - "~>"
123
147
  - !ruby/object:Gem::Version
124
148
  version: 0.16.1
149
+ - - "!="
150
+ - !ruby/object:Gem::Version
151
+ version: 0.18.0
152
+ - - "!="
153
+ - !ruby/object:Gem::Version
154
+ version: 0.18.1
155
+ - - "!="
156
+ - !ruby/object:Gem::Version
157
+ version: 0.18.2
158
+ - - "!="
159
+ - !ruby/object:Gem::Version
160
+ version: 0.18.3
161
+ - - "!="
162
+ - !ruby/object:Gem::Version
163
+ version: 0.18.4
164
+ - - "!="
165
+ - !ruby/object:Gem::Version
166
+ version: 0.18.5
167
+ - - "!="
168
+ - !ruby/object:Gem::Version
169
+ version: 0.19.0
170
+ - - "!="
171
+ - !ruby/object:Gem::Version
172
+ version: 0.19.1
125
173
  description:
126
174
  email:
127
- - taka84u9@gmail.com
175
+ - engineers@qiita.com
128
176
  executables: []
129
177
  extensions: []
130
178
  extra_rdoc_files: []
131
179
  files:
132
- - ".codeclimate.yml"
180
+ - ".github/workflows/test.yml"
133
181
  - ".gitignore"
134
182
  - ".rspec"
135
183
  - ".rubocop.yml"
136
- - ".travis.yml"
184
+ - ".rubocop_todo.yml"
137
185
  - CHANGELOG.md
138
186
  - Gemfile
139
187
  - LICENSE
@@ -166,10 +214,11 @@ files:
166
214
  - spec/support/shared_contexts/run_in_a_sandbox.rb
167
215
  - spec/support/test_app.rb
168
216
  - spec/tmp/.keep
169
- homepage: https://github.com/yuku-t/js_rails_routes
217
+ homepage: https://github.com/increments/js_rails_routes
170
218
  licenses:
171
219
  - MIT
172
- metadata: {}
220
+ metadata:
221
+ rubygems_mfa_required: 'true'
173
222
  post_install_message:
174
223
  rdoc_options: []
175
224
  require_paths:
@@ -178,15 +227,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
227
  requirements:
179
228
  - - ">="
180
229
  - !ruby/object:Gem::Version
181
- version: 2.3.0
230
+ version: 2.6.0
182
231
  required_rubygems_version: !ruby/object:Gem::Requirement
183
232
  requirements:
184
233
  - - ">="
185
234
  - !ruby/object:Gem::Version
186
235
  version: '0'
187
236
  requirements: []
188
- rubyforge_project:
189
- rubygems_version: 2.7.6
237
+ rubygems_version: 3.0.3
190
238
  signing_key:
191
239
  specification_version: 4
192
240
  summary: Generate a ES6 module that contains Rails routes.
data/.codeclimate.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- engines:
3
- duplication:
4
- enabled: true
5
- config:
6
- languages:
7
- - ruby
8
- fixme:
9
- enabled: true
10
- rubocop:
11
- enabled: true
12
- ratings:
13
- paths:
14
- - "**.rb"
15
- exclude_paths:
16
- - spec/
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
7
-
8
- notifications:
9
- email: false
10
-
11
- script:
12
- - bundle exec rake rubocop
13
- - bundle exec rake spec
14
-
15
- after_success:
16
- - bundle exec codeclimate-test-reporter