chanko 2.3.0 → 3.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/.github/workflows/master_and_pr.yml +6 -30
- data/.gitignore +1 -1
- data/CHANGELOG.md +8 -1
- data/README.md +3 -43
- data/chanko.gemspec +3 -4
- data/gemfiles/Gemfile_rails_6.1.rb +2 -4
- data/gemfiles/Gemfile_rails_7.0.rb +6 -0
- data/gemfiles/Gemfile_rails_7.1.rb +6 -0
- data/lib/chanko/function.rb +4 -13
- data/lib/chanko/railtie.rb +0 -13
- data/lib/chanko/unit/extender/extension.rb +0 -2
- data/lib/chanko/unit/extender.rb +0 -1
- data/lib/chanko/unit.rb +0 -12
- data/lib/chanko/version.rb +1 -1
- data/lib/generators/chanko/unit/templates/unit.rb.erb +3 -28
- data/lib/generators/chanko/unit/unit_generator.rb +22 -13
- data/spec/chanko/function_spec.rb +2 -52
- data/spec/chanko/test_spec.rb +1 -14
- data/spec/chanko/unit_spec.rb +0 -63
- data/spec/dummy/app/units/entry_deletion/entry_deletion.rb +0 -16
- data/spec/dummy/app/views/units/example_unit +1 -0
- data/spec/dummy/config/application.rb +8 -13
- data/spec/fixtures/units/example_unit/example_unit.rb +2 -2
- metadata +13 -21
- data/gemfiles/Gemfile_rails_5.0.rb +0 -6
- data/gemfiles/Gemfile_rails_5.0.rb.lock +0 -203
- data/gemfiles/Gemfile_rails_5.1.rb +0 -6
- data/gemfiles/Gemfile_rails_5.1.rb.lock +0 -203
- data/gemfiles/Gemfile_rails_5.2.rb +0 -6
- data/gemfiles/Gemfile_rails_5.2.rb.lock +0 -209
- data/gemfiles/Gemfile_rails_6.0.rb +0 -8
- data/gemfiles/Gemfile_rails_6.0.rb.lock +0 -238
- data/gemfiles/Gemfile_rails_6.1.rb.lock +0 -241
- data/lib/chanko/unit/extender/active_record_class_methods.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72b1ce54ea0cf5bbf3d56237723d00c9383213d67534c21531ed568465d95435
|
4
|
+
data.tar.gz: 74c763b3087ac11d7ddaa4700995240681ceafd6fcfa1dcf26785d547a20e934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec921fb9b47ca4f5878f902a01de61a8e5c96d4f671a1a3f991c3d047f2102c24245697a27e05e0af928acaa7b5345bf8cd79465082a3aabffaf2e66f26a7d68
|
7
|
+
data.tar.gz: a6f855b9f756b034f9098718bc1ad2c0e112f5ad0a616ac2a9023767ba92228c4f41a6cb0e1a21bf53910140dc2a8bf1480180a6aec0b1cbe8b75dd829be7d47
|
@@ -10,45 +10,21 @@ jobs:
|
|
10
10
|
strategy:
|
11
11
|
matrix:
|
12
12
|
rails_version:
|
13
|
-
- "5.0"
|
14
|
-
- "5.1"
|
15
|
-
- "5.2"
|
16
|
-
- "6.0"
|
17
13
|
- "6.1"
|
14
|
+
- "7.0"
|
15
|
+
- "7.1"
|
18
16
|
ruby_version:
|
19
|
-
- "2.7"
|
20
17
|
- "3.1"
|
21
|
-
|
22
|
-
- "
|
23
|
-
- "classic"
|
18
|
+
- "3.2"
|
19
|
+
- "3.3"
|
24
20
|
eager_load:
|
25
21
|
- "true"
|
26
22
|
- "false"
|
27
|
-
|
28
|
-
- rails_version: "5.0"
|
29
|
-
ruby_version: "3.1"
|
30
|
-
- rails_version: "5.1"
|
31
|
-
ruby_version: "3.1"
|
32
|
-
- rails_version: "5.2"
|
33
|
-
ruby_version: "3.1"
|
34
|
-
- rails_version: "5.0"
|
35
|
-
autoloader: "zeitwerk"
|
36
|
-
- rails_version: "5.1"
|
37
|
-
autoloader: "zeitwerk"
|
38
|
-
- rails_version: "5.2"
|
39
|
-
autoloader: "zeitwerk"
|
40
|
-
- rails_version: "5.0"
|
41
|
-
autoloader: "classic"
|
42
|
-
- rails_version: "5.1"
|
43
|
-
autoloader: "classic"
|
44
|
-
- rails_version: "5.2"
|
45
|
-
autoloader: "classic"
|
46
|
-
name: Test on Rails ${{ matrix.rails_version }} & Ruby ${{ matrix.ruby_version }} & Autoloader ${{ matrix.autoloader }} & EagerLoad ${{ matrix.eager_load }}
|
23
|
+
name: Test on Rails ${{ matrix.rails_version }} & Ruby ${{ matrix.ruby_version }} & EagerLoad ${{ matrix.eager_load }}
|
47
24
|
env:
|
48
25
|
BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb
|
49
26
|
CI: true
|
50
27
|
EAGER_LOAD: ${{ matrix.eager_load }}
|
51
|
-
AUTOLOADER : ${{ matrix.autoloader }}
|
52
28
|
steps:
|
53
29
|
- uses: actions/checkout@v3
|
54
30
|
- uses: ruby/setup-ruby@v1
|
@@ -58,7 +34,7 @@ jobs:
|
|
58
34
|
- name: rspec
|
59
35
|
run: bundle exec rspec
|
60
36
|
- name: Coveralls
|
61
|
-
if: matrix.rails_version == '
|
37
|
+
if: matrix.rails_version == '7.1' && matrix.ruby_version == '3.3'
|
62
38
|
uses: coverallsapp/github-action@master
|
63
39
|
with:
|
64
40
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
##
|
1
|
+
## 3.0.0
|
2
|
+
* Support Rails 6,1. 7.0, 7.1.
|
3
|
+
* Support Ruby >= 3.0.
|
4
|
+
* Drop support for Rails <= 6.0.
|
5
|
+
* Drop support for Ruby 2.
|
6
|
+
* Drop support for classic loader.
|
7
|
+
* The functionality to extend the view_paths has been discontinued.
|
8
|
+
* The functionality to extend the models has been discontinued.
|
2
9
|
|
3
10
|
## 2.3.0
|
4
11
|
* Support Rails 5.0, 5.1, 5,2, 6.0, 6,1.
|
data/README.md
CHANGED
@@ -10,11 +10,9 @@ With Chanko, you can release many features concurrently and manage target users
|
|
10
10
|
When any errors are raised from chanko's features,
|
11
11
|
it will be automatically hidden and fallback to its normal behavior.
|
12
12
|
|
13
|
-
|
14
13
|
## Requirements
|
15
|
-
* Ruby >=
|
16
|
-
* Rails >=
|
17
|
-
|
14
|
+
* Ruby >= 3.0.0
|
15
|
+
* Rails >= 6.1.0
|
18
16
|
|
19
17
|
## Usage
|
20
18
|
Add to your Gemfile.
|
@@ -63,11 +61,6 @@ end
|
|
63
61
|
= invoke(:example_unit, :render_example)
|
64
62
|
```
|
65
63
|
|
66
|
-
```
|
67
|
-
-# app/units/example_unit/views/_example.html.slim
|
68
|
-
= foo
|
69
|
-
```
|
70
|
-
|
71
64
|
## Unit
|
72
65
|
You can see [the real example of an unit module file](https://github.com/cookpad/chanko/blob/master/spec/dummy/app/units/entry_deletion/entry_deletion.rb).
|
73
66
|
|
@@ -120,39 +113,7 @@ end
|
|
120
113
|
```
|
121
114
|
|
122
115
|
### render
|
123
|
-
|
124
|
-
So you can render app/units/example_unit/views/_example.html.slim in invoking.
|
125
|
-
|
126
|
-
```ruby
|
127
|
-
scope(:view) do
|
128
|
-
function(:render_example) do
|
129
|
-
render "/example", :foo => hello("world")
|
130
|
-
end
|
131
|
-
end
|
132
|
-
```
|
133
|
-
|
134
|
-
### models
|
135
|
-
In models block, you can expand model features by `expand` method.
|
136
|
-
The expanded methods are available via unit proxy like `User.unit.active`,
|
137
|
-
`User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
models do
|
141
|
-
expand(:User) do
|
142
|
-
scope :active, lambda { where(:deleted_at => nil) }
|
143
|
-
|
144
|
-
def active?
|
145
|
-
deleted_at.nil?
|
146
|
-
end
|
147
|
-
|
148
|
-
class_methods do
|
149
|
-
def gc_all_soft_deleted_users
|
150
|
-
where.not(deleted_at: nil).delete_all
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
```
|
116
|
+
In version 2 and earlier, Chanko extended Rails' search path to include the views path of the unit. This functionality has been discontinued. To maintain the views path under the unit, you will need to manually create a symbolic link in app/views/units to access it.
|
156
117
|
|
157
118
|
### shared
|
158
119
|
You can call methods defined by `shared` in invoking.
|
@@ -174,7 +135,6 @@ helpers do
|
|
174
135
|
end
|
175
136
|
```
|
176
137
|
|
177
|
-
|
178
138
|
## Example
|
179
139
|
https://github.com/cookpad/chanko/tree/master/spec/dummy
|
180
140
|
Chanko provides an example rails application in spec/dummy directory.
|
data/chanko.gemspec
CHANGED
@@ -12,12 +12,11 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.homepage = "https://github.com/cookpad/chanko"
|
13
13
|
|
14
14
|
gem.files = `git ls-files`.split($/)
|
15
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
16
|
gem.require_paths = ["lib"]
|
18
|
-
gem.required_ruby_version = '>=
|
17
|
+
gem.required_ruby_version = '>= 3.0.0'
|
19
18
|
|
20
|
-
gem.add_dependency "rails", ">=
|
19
|
+
gem.add_dependency "rails", ">= 6.1.0"
|
21
20
|
gem.add_development_dependency "byebug"
|
22
21
|
gem.add_development_dependency "coffee-rails", ">= 3.0.10"
|
23
22
|
gem.add_development_dependency "jquery-rails"
|
@@ -28,7 +27,7 @@ Gem::Specification.new do |gem|
|
|
28
27
|
gem.add_development_dependency "simplecov"
|
29
28
|
gem.add_development_dependency 'simplecov-lcov'
|
30
29
|
gem.add_development_dependency "slim"
|
31
|
-
gem.add_development_dependency "sqlite3"
|
30
|
+
gem.add_development_dependency "sqlite3", ">= 1.4"
|
32
31
|
gem.add_development_dependency "thin"
|
33
32
|
gem.add_development_dependency "uglifier"
|
34
33
|
end
|
data/lib/chanko/function.rb
CHANGED
@@ -22,12 +22,10 @@ module Chanko
|
|
22
22
|
|
23
23
|
def invoke(context, options = {})
|
24
24
|
with_unit_stack(context) do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
result
|
30
|
-
end
|
25
|
+
capture_exception(context) do
|
26
|
+
result = context.instance_eval(&block)
|
27
|
+
result = decorate(result, context, options[:type]) if context.view? && result.present?
|
28
|
+
result
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -59,13 +57,6 @@ module Chanko
|
|
59
57
|
context.units.pop
|
60
58
|
end
|
61
59
|
|
62
|
-
def with_unit_view_path(context)
|
63
|
-
context.view_paths.unshift unit.resolver if context.respond_to?(:view_paths)
|
64
|
-
yield
|
65
|
-
ensure
|
66
|
-
context.view_paths.paths.shift if context.respond_to?(:view_paths)
|
67
|
-
end
|
68
|
-
|
69
60
|
def capture_exception(context)
|
70
61
|
yield
|
71
62
|
rescue Exception => exception
|
data/lib/chanko/railtie.rb
CHANGED
@@ -7,11 +7,6 @@ module Chanko
|
|
7
7
|
ActiveSupport.on_load :action_controller do
|
8
8
|
::ActionController::Base.send(:include, Controller, Invoker, UnitProxyProvider)
|
9
9
|
end
|
10
|
-
ActiveSupport.on_load :active_record do
|
11
|
-
::ActiveRecord::Base.send(:include, UnitProxyProvider)
|
12
|
-
::ActiveRecord::Relation.send(:include, UnitProxyProvider)
|
13
|
-
::ActiveRecord::Associations::CollectionAssociation.send(:include, UnitProxyProvider)
|
14
|
-
end
|
15
10
|
end
|
16
11
|
|
17
12
|
|
@@ -21,14 +16,6 @@ module Chanko
|
|
21
16
|
Chanko::Loader.prepare_eager_load(mode: :zeitwerk)
|
22
17
|
end
|
23
18
|
|
24
|
-
initializer("chanko.classic.prepare_eager_load", after: :load_environment_config) do |app|
|
25
|
-
# Rails5 doens't load environments/*.rb files before :set_autoload_paths.
|
26
|
-
# In other words, at this stage, config.eager_load cannot be determined to be true or false.
|
27
|
-
# But classic loader does not freeze paths on :set_autoload_paths.
|
28
|
-
# After all, It's ok if it is executed after :set_autoload_paths on Rails5 and Rails6(classic).
|
29
|
-
Chanko::Loader.prepare_eager_load(mode: :classic)
|
30
|
-
end
|
31
|
-
|
32
19
|
initializer("chanko.eager_load_units", before: :eager_load!) do |app|
|
33
20
|
# This is why we need handmade eager-loading
|
34
21
|
# https://github.com/cookpad/chanko/pull/38
|
data/lib/chanko/unit/extender.rb
CHANGED
data/lib/chanko/unit.rb
CHANGED
@@ -33,10 +33,6 @@ module Chanko
|
|
33
33
|
Helper.define(unit_name, &block)
|
34
34
|
end
|
35
35
|
|
36
|
-
def models(&block)
|
37
|
-
extender.instance_eval(&block)
|
38
|
-
end
|
39
|
-
|
40
36
|
def active_if(*conditions, &block)
|
41
37
|
@active_if = ActiveIf.new(*conditions, &block)
|
42
38
|
end
|
@@ -70,10 +66,6 @@ module Chanko
|
|
70
66
|
UnitProxy.generate_prefix(unit_name)
|
71
67
|
end
|
72
68
|
|
73
|
-
def view_path
|
74
|
-
Rails.root.join("#{Config.units_directory_path}/#{unit_name}/views").to_s
|
75
|
-
end
|
76
|
-
|
77
69
|
def find_function(identifier, label)
|
78
70
|
scope = ScopeFinder.find(identifier)
|
79
71
|
target = scope.ancestors.find {|klass| scopes[klass] }
|
@@ -93,10 +85,6 @@ module Chanko
|
|
93
85
|
@shared_methods ||= {}
|
94
86
|
end
|
95
87
|
|
96
|
-
def resolver
|
97
|
-
@resolver ||= Config.resolver.new(view_path)
|
98
|
-
end
|
99
|
-
|
100
88
|
def extender
|
101
89
|
@extender ||= Extender.new(to_prefix)
|
102
90
|
end
|
data/lib/chanko/version.rb
CHANGED
@@ -14,7 +14,7 @@ module <%= class_name %>
|
|
14
14
|
# ```
|
15
15
|
|
16
16
|
# ## raise_error
|
17
|
-
# `raise_error` is used to force an unit to raise up errors
|
17
|
+
# `raise_error` is used to force an unit to raise up errors occurred in invoking.
|
18
18
|
# You can force to raise up errors also by `Config.raise_error`.
|
19
19
|
#
|
20
20
|
# ```
|
@@ -34,36 +34,11 @@ module <%= class_name %>
|
|
34
34
|
# ```
|
35
35
|
|
36
36
|
# ## render
|
37
|
-
#
|
38
|
-
# So you can render <%= "#{directory}/views/_example.html.erb" %> in invoking.
|
39
|
-
#
|
37
|
+
# If you want to place the views path under the unit, create a symbolic link under app/views/units and refer to it.
|
40
38
|
# ```
|
41
39
|
# scope(:view) do
|
42
40
|
# function(:function_name) do
|
43
|
-
# render "/example", :foo => "bar"
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
# ```
|
47
|
-
|
48
|
-
# ## models
|
49
|
-
# In models block, you can expand model features by `expand` method.
|
50
|
-
# The expanded methods are available via unit proxy like `User.unit.active`,
|
51
|
-
# `User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
|
52
|
-
#
|
53
|
-
# ```
|
54
|
-
# models do
|
55
|
-
# expand(:User) do
|
56
|
-
# scope :active, lambda { where(:deleted_at => nil) }
|
57
|
-
#
|
58
|
-
# def active?
|
59
|
-
# deleted_at.nil?
|
60
|
-
# end
|
61
|
-
#
|
62
|
-
# class_methods do
|
63
|
-
# def gc_all_soft_deleted_users
|
64
|
-
# where.not(deleted_at: nil).delete_all
|
65
|
-
# end
|
66
|
-
# end
|
41
|
+
# render "/units/<%= file_name.underscore %>/example", :foo => "bar"
|
67
42
|
# end
|
68
43
|
# end
|
69
44
|
# ```
|
@@ -6,44 +6,53 @@ module Chanko
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
8
|
def create_unit_directory
|
9
|
-
empty_directory(
|
9
|
+
empty_directory(unit_directory)
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_unit_file
|
13
|
-
template("unit.rb.erb", "#{
|
13
|
+
template("unit.rb.erb", "#{unit_directory}/#{file_name}.rb")
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
create_file("#{
|
16
|
+
def create_views_unit_directory
|
17
|
+
create_file("#{unit_directory}/views/.gitkeep", "")
|
18
18
|
end
|
19
19
|
|
20
20
|
ASSETS_TYPES.each do |type|
|
21
|
-
define_method("create_#{type}
|
22
|
-
create_file("#{
|
21
|
+
define_method("create_#{type}_unit_directory") do
|
22
|
+
create_file("#{unit_directory}/#{type}/.gitkeep", "")
|
23
23
|
end
|
24
|
-
end
|
25
24
|
|
26
|
-
|
27
|
-
define_method("create_#{type}_symlink") do
|
25
|
+
define_method("create_#{type}_unit_symlink") do
|
28
26
|
create_assets_symlink(type)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
30
|
+
def create_views_symlink
|
31
|
+
from = "app/views/#{units_directory_name}/#{file_name}"
|
32
|
+
to = "../../../#{relative_unit_directory}/views"
|
33
|
+
create_link(from, to)
|
34
|
+
end
|
35
|
+
|
32
36
|
private
|
33
37
|
|
34
38
|
def create_assets_symlink(type)
|
35
|
-
from = "app/assets/#{type}/#{
|
36
|
-
to = "../../../../#{
|
39
|
+
from = "app/assets/#{type}/#{units_directory_name}/#{file_name}"
|
40
|
+
to = "../../../../#{relative_unit_directory}/#{type}"
|
37
41
|
create_link(from, to)
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
44
|
+
def relative_unit_directory
|
45
|
+
Pathname.new(unit_directory).relative_path_from(Rails.root)
|
46
|
+
end
|
47
|
+
|
48
|
+
def unit_directory
|
41
49
|
"#{Chanko::Config.units_directory_path}/#{file_name}"
|
42
50
|
end
|
43
51
|
|
44
|
-
def
|
52
|
+
def units_directory_name
|
45
53
|
Chanko::Config.units_directory_path.split("/").last
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
58
|
+
|
@@ -6,24 +6,7 @@ module Chanko
|
|
6
6
|
Loader.load(:example_unit)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
klass = Class.new(ActionView::Base) do
|
11
|
-
def current_unit
|
12
|
-
units.last
|
13
|
-
end
|
14
|
-
|
15
|
-
def units
|
16
|
-
@units ||= []
|
17
|
-
end
|
18
|
-
|
19
|
-
def path
|
20
|
-
view_paths.first.to_s
|
21
|
-
end
|
22
|
-
end
|
23
|
-
klass.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def rails6_action_view_instance
|
9
|
+
def action_view_instance
|
27
10
|
klass = Class.new(ActionView::Base.with_empty_template_cache) do
|
28
11
|
def current_unit
|
29
12
|
units.last
|
@@ -32,32 +15,12 @@ module Chanko
|
|
32
15
|
def units
|
33
16
|
@units ||= []
|
34
17
|
end
|
35
|
-
|
36
|
-
def path
|
37
|
-
view_paths.first.to_s
|
38
|
-
end
|
39
18
|
end
|
40
|
-
|
41
19
|
klass.with_view_paths([], {}, nil)
|
42
20
|
end
|
43
21
|
|
44
22
|
let(:context) do
|
45
|
-
|
46
|
-
when 5
|
47
|
-
rails5_action_view_instance
|
48
|
-
when 6
|
49
|
-
rails6_action_view_instance
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
let(:context_without_view_paths) do
|
54
|
-
Class.new do
|
55
|
-
include Chanko::Invoker
|
56
|
-
|
57
|
-
def units
|
58
|
-
@units ||= []
|
59
|
-
end
|
60
|
-
end.new
|
23
|
+
action_view_instance
|
61
24
|
end
|
62
25
|
|
63
26
|
let(:options) do
|
@@ -68,19 +31,6 @@ module Chanko
|
|
68
31
|
it "invokes block with given context and stacked unit" do
|
69
32
|
expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
|
70
33
|
end
|
71
|
-
|
72
|
-
context "when context is a view" do
|
73
|
-
it "invokes with unit's view path" do
|
74
|
-
expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "when context does not have view_paths" do
|
79
|
-
it "invokes successfully" do
|
80
|
-
expect(described_class.new(unit, :label) { "test" }.
|
81
|
-
invoke(context_without_view_paths, options)).to eq("test")
|
82
|
-
end
|
83
|
-
end
|
84
34
|
end
|
85
35
|
end
|
86
36
|
end
|
data/spec/chanko/test_spec.rb
CHANGED
@@ -3,24 +3,11 @@ require "chanko/test"
|
|
3
3
|
|
4
4
|
module Chanko
|
5
5
|
describe Test do
|
6
|
-
|
7
|
-
Class.new(ActionView::Base).new
|
8
|
-
end
|
9
|
-
|
10
|
-
def rails6_action_view_instance
|
6
|
+
let(:view) do
|
11
7
|
klass = Class.new(ActionView::Base.with_empty_template_cache)
|
12
8
|
klass.with_view_paths(nil, {}, nil)
|
13
9
|
end
|
14
10
|
|
15
|
-
let(:view) do
|
16
|
-
case Rails::VERSION::MAJOR
|
17
|
-
when 5
|
18
|
-
rails5_action_view_instance
|
19
|
-
when 6
|
20
|
-
rails6_action_view_instance
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
11
|
describe "#enable_unit" do
|
25
12
|
it "forces to enable specified unit" do
|
26
13
|
enable_unit(:inactive_unit)
|
data/spec/chanko/unit_spec.rb
CHANGED
@@ -188,68 +188,5 @@ module Chanko
|
|
188
188
|
expect(view.__example_unit_test).to eq("test")
|
189
189
|
end
|
190
190
|
end
|
191
|
-
|
192
|
-
describe ".models" do
|
193
|
-
before do
|
194
|
-
stub_const("ExampleModel", model_class)
|
195
|
-
unit.models do
|
196
|
-
expand(:ExampleModel) do
|
197
|
-
scope :active, lambda { where(:deleted_at => nil) }
|
198
|
-
|
199
|
-
has_one :user
|
200
|
-
|
201
|
-
def test
|
202
|
-
"test"
|
203
|
-
end
|
204
|
-
|
205
|
-
class_methods do
|
206
|
-
def test
|
207
|
-
"test"
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
let(:model_class) do
|
215
|
-
Class.new do
|
216
|
-
include UnitProxyProvider
|
217
|
-
|
218
|
-
def self.scope(name, *args)
|
219
|
-
singleton_class.class_eval do
|
220
|
-
define_method(name) { "scoped" }
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def self.has_one(name, *args)
|
225
|
-
singleton_class.class_eval do
|
226
|
-
define_method(name) { args }
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
it "defines instance methods with prefix" do
|
233
|
-
expect(ExampleModel.new.__example_unit_test).to eq("test")
|
234
|
-
end
|
235
|
-
|
236
|
-
it "defines class methods with prefix" do
|
237
|
-
expect(ExampleModel.__example_unit_test).to eq("test")
|
238
|
-
end
|
239
|
-
|
240
|
-
it "defines scope method with prefix" do
|
241
|
-
expect(ExampleModel.__example_unit_active).to eq("scoped")
|
242
|
-
end
|
243
|
-
|
244
|
-
it "defines has_one association method with prefix" do
|
245
|
-
expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe ".view_path" do
|
250
|
-
it "returns path for its view directory" do
|
251
|
-
expect(unit.view_path).to eq("#{Config.units_directory_path}/example_unit/views")
|
252
|
-
end
|
253
|
-
end
|
254
191
|
end
|
255
192
|
end
|
@@ -19,22 +19,6 @@ module EntryDeletion
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
models do
|
23
|
-
expand(:Entry) do
|
24
|
-
scope :active, lambda { where(:deleted_at => nil) }
|
25
|
-
|
26
|
-
def soft_delete
|
27
|
-
update_attributes(:deleted_at => Time.now)
|
28
|
-
end
|
29
|
-
|
30
|
-
class_methods do
|
31
|
-
def gc_all_soft_deleted_users
|
32
|
-
where.not(deleted_at: nil).delete_all
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
22
|
helpers do
|
39
23
|
def link_to_deletion(entry)
|
40
24
|
link_to "Delete", entry, :method => :delete
|
@@ -0,0 +1 @@
|
|
1
|
+
../../../../fixtures/units/example_unit/views
|