fume-cancan 0.0.4 → 0.1.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
  SHA1:
3
- metadata.gz: a44cc9b04b6d1dce0cb5e99fa29d73b93dfc1a8f
4
- data.tar.gz: 7d62ff91b18c8cf9da74e6c381fb56c5ebceb538
3
+ metadata.gz: 49048bf3e95080da8b9a522ba0f5e6fe9808c82e
4
+ data.tar.gz: 95622c50b92c2a5f4196a72dfefd6c9060af8e75
5
5
  SHA512:
6
- metadata.gz: a56a4a62973747c678f2207665a2ccf3c2ce3d0b2f280a80e08fdd8d90cf2f8f6b03e86935bd71f4f25a4dd9df213e8d5b01907113b548bccbe55a7d43b96ddb
7
- data.tar.gz: 38e1776396e523a9124bc002a986d88aed19e09237ed4c88ac941307f1ebb3996560a8fc68d62005d07ae759fe03507ba3f6f6a039f72b9cf4171bedbd5dd5c2
6
+ metadata.gz: 78ba7d9f003ebd9847add1f13c2fc7bda6423edb4602fa6f83e88fd262aa6de5a5f60ec2f3e58e28e6b4d61771a7b14f7384f0263433f99bc4f3257742f3efa9
7
+ data.tar.gz: 4fc64c2553bfcd534aabbe9e90f28b2f441594bcfcaf82b39b87ce426e133ebb3bc81a0e26b476ee45a9a68a84dfcc98a8ba6906e4a909756159848c8a34cdbd
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  /.bundle
4
4
  /.config
5
5
  /.yardoc
6
- /Gemfile.lock
7
6
  /InstalledFiles
8
7
  /_yardoc
9
8
  /coverage
@@ -15,3 +14,8 @@
15
14
  /tmp
16
15
  /tags
17
16
  /spec/internal/log/
17
+ /vendor/bundler/
18
+ /.rubocop_todo.yml
19
+ /Gemfile.lock
20
+ /gemfiles/*.gemfile.lock
21
+ /spec/internal/db/*.sqlite
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --require spec_helper
@@ -0,0 +1,35 @@
1
+ Style/AccessModifierIndentation:
2
+ EnforcedStyle: outdent
3
+
4
+ Style/BlockComments:
5
+ Enabled: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/EmptyLinesAroundAccessModifier:
11
+ Enabled: false
12
+
13
+ Style/FileName:
14
+ Enabled: false
15
+
16
+ Style/EmptyLines:
17
+ Enabled: false
18
+
19
+ Style/PercentLiteralDelimiters:
20
+ Enabled: false
21
+
22
+ Style/StringLiterals:
23
+ Enabled: false
24
+
25
+ Style/SpaceInsideBrackets:
26
+ Enabled: false
27
+
28
+ Style/Semicolon:
29
+ Enabled: false
30
+
31
+ Style/UnneededPercentQ:
32
+ Enabled: false
33
+
34
+ Metrics/LineLength:
35
+ Max: 120
@@ -1,4 +1,7 @@
1
1
  rvm:
2
- - 2.1.0
3
- - 2.0.0
4
- - 1.9.3
2
+ - 2.2.5
3
+ - 2.3.1
4
+
5
+ gemfile:
6
+ - Gemfile
7
+ - gemfiles/rails4_2.gemfile
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "rails", "~> 5.0.0"
4
+
3
5
  # Specify your gem's dependencies in fume-cancan.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -13,15 +13,26 @@ Add this line to your application's Gemfile:
13
13
 
14
14
  ## Usage
15
15
 
16
- Ability:
17
-
18
- can :manage, :admin
19
-
20
- Controller:
21
-
22
- class Admin::BaseController < ApplicationController
23
- authorize_object :admin
24
- end
16
+ ### authorize_object
17
+
18
+ ~~~~ruby
19
+ # Ability:
20
+ can :manage, :admin
21
+
22
+ # Controller:
23
+ class Admin::BaseController < ApplicationController
24
+ authorize_object :admin
25
+ end
26
+ ~~~~
27
+
28
+ ### with_scope
29
+
30
+ ~~~~ruby
31
+ # Controller:
32
+ class Topics < ApplicationController
33
+ load_and_authorize_resource with_scope: -> (base) { base.where(online: true) }
34
+ end
35
+ ~~~~
25
36
 
26
37
  ## Contributing
27
38
 
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require "bundler/gem_tasks"
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
5
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :all
7
+ run Combustion::Application
@@ -27,7 +27,9 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency "cancancan"
29
29
 
30
- spec.add_development_dependency "rspec-rails", "3.1.0"
31
- spec.add_development_dependency "combustion", "0.5.2"
30
+ spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "rspec-rails", "3.5.2"
32
+ spec.add_development_dependency "combustion", "0.5.5"
33
+ spec.add_development_dependency "sqlite3"
32
34
  spec.add_development_dependency "rspec-do_action", "0.0.4"
33
35
  end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 4.2.7"
4
+
5
+ # Specify your gem's dependencies in fume-cancan.gemspec
6
+ gemspec path: ".."
@@ -1,4 +1,5 @@
1
1
  require "cancan"
2
2
 
3
3
  require "fume/cancan/version"
4
- require "fume/cancan/controller_extensions"
4
+ require "fume/cancan/with_scope"
5
+ require "fume/cancan/controller_extensions"
@@ -11,7 +11,7 @@ module Fume
11
11
  object = args.shift || options[:object]
12
12
 
13
13
  filter_options = options.slice(:only, :except)
14
- before_filter(filter_options || {}) do |controller|
14
+ before_action(filter_options || {}) do |controller|
15
15
  controller.send :authorize_object!, object, options
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Fume
2
2
  module Cancan
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0".freeze
4
4
  end
5
- end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Fume
2
+ module Cancan
3
+ module WithScope
4
+ def resource_base
5
+ base = super
6
+
7
+ if (with_scope = @options[:with_scope])
8
+ @controller.instance_exec(super, &with_scope)
9
+ else
10
+ base
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ CanCan::ControllerResource.send :prepend, ::Fume::Cancan::WithScope
@@ -1,9 +1,13 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  def index
3
- render text: "OK"
3
+ render plain: "OK"
4
+ end
5
+
6
+ def show
7
+ render plain: "FOUND"
4
8
  end
5
9
 
6
10
  def current_ability
7
11
  @current_ability ||= Ability.new
8
12
  end
9
- end
13
+ end
@@ -1,3 +1,7 @@
1
1
  class Ability
2
2
  include CanCan::Ability
3
- end
3
+
4
+ def initialize
5
+ can :manage, Topic
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Topic < ActiveRecord::Base
2
+ scope :online, -> { where(online: true) }
3
+ end
@@ -1,3 +1,6 @@
1
1
  ActiveRecord::Schema.define do
2
- #
2
+ create_table(:topics, force: true) do |t|
3
+ t.string :title
4
+ t.boolean :online, default: false
5
+ end
3
6
  end
File without changes
@@ -46,4 +46,4 @@ RSpec.describe Fume::Cancan::ControllerExtensions, type: :controller do
46
46
  define_method :is_expected_access_denied, -> { expect { do_action }.to raise_error CanCan::AccessDenied }
47
47
  define_method :is_expected_response_ok, -> { do_action; expect(response.body).to eq "OK" }
48
48
  end
49
- end
49
+ end
@@ -0,0 +1,22 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe Fume::Cancan::WithScope, type: :controller do
4
+ describe "#with_scope" do
5
+ controller(ApplicationController) {}
6
+ let!(:topic) { Topic.create!(title: "TITLE", online: false) }
7
+ let(:params) { { id: topic.id } }
8
+
9
+ action { get :show, Rails.version.start_with?("4.") ? params : { params: params } }
10
+
11
+ context "when undefine with_scope option" do
12
+ controller { load_and_authorize_resource :topic, parent: false }
13
+ it { expect(response.body).to eq "FOUND" }
14
+ end
15
+
16
+ context "when define with_scope option" do
17
+ controller { load_and_authorize_resource :topic, parent: false, with_scope: -> (base) { base.online } }
18
+ skip_do_action
19
+ it { expect { do_action }.to raise_error(ActiveRecord::RecordNotFound) }
20
+ end
21
+ end
22
+ end
@@ -7,7 +7,7 @@ Coveralls.wear!
7
7
 
8
8
  require "pry-nav"
9
9
  require 'combustion'
10
- Combustion.initialize! :action_controller
10
+ Combustion.initialize! :active_record, :action_controller
11
11
  require "rspec/rails"
12
12
  require "rspec-do_action"
13
13
 
@@ -1,14 +1,16 @@
1
- # This file was generated by the `rails generate rspec:install` command. Conventionally, all
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
2
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
5
6
  #
6
7
  # Given that it is always loaded, you are encouraged to keep this file as
7
8
  # light-weight as possible. Requiring heavyweight dependencies from this file
8
9
  # will add to the boot time of your test suite on EVERY test run, even for an
9
10
  # individual file that may not need all of that loaded. Instead, consider making
10
11
  # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
12
14
  #
13
15
  # The `.rspec` file also contains a few flags that are not defaults but that
14
16
  # users commonly want.
@@ -22,10 +24,10 @@ RSpec.configure do |config|
22
24
  # This option will default to `true` in RSpec 4. It makes the `description`
23
25
  # and `failure_message` of custom matchers include text for helper methods
24
26
  # defined using `chain`, e.g.:
25
- # be_bigger_than(2).and_smaller_than(4).description
26
- # # => "be bigger than 2 and smaller than 4"
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
27
29
  # ...rather than:
28
- # # => "be bigger than 2"
30
+ # # => "be bigger than 2"
29
31
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
32
  end
31
33
 
@@ -38,23 +40,39 @@ RSpec.configure do |config|
38
40
  mocks.verify_partial_doubles = true
39
41
  end
40
42
 
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
41
50
  # The settings below are suggested to provide a good initial experience
42
51
  # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
43
59
 
44
- # These two settings work together to allow you to limit a spec run
45
- # to individual examples or groups you care about by tagging them with
46
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
- # get run.
48
- config.filter_run :focus
49
- config.run_all_when_everything_filtered = true
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
50
64
 
51
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
- # For more details, see:
53
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
56
70
  config.disable_monkey_patching!
57
71
 
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
58
76
  # Many RSpec users commonly either run the entire suite or an individual
59
77
  # file, and it's useful to allow more verbose output when running an
60
78
  # individual spec file.
@@ -81,4 +99,5 @@ RSpec.configure do |config|
81
99
  # test failures related to randomization by passing the same `--seed` value
82
100
  # as the one that triggered the failure.
83
101
  Kernel.srand config.seed
102
+ =end
84
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fume-cancan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sunteya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,34 +94,62 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec-rails
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - '='
102
116
  - !ruby/object:Gem::Version
103
- version: 3.1.0
117
+ version: 3.5.2
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - '='
109
123
  - !ruby/object:Gem::Version
110
- version: 3.1.0
124
+ version: 3.5.2
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: combustion
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - '='
116
130
  - !ruby/object:Gem::Version
117
- version: 0.5.2
131
+ version: 0.5.5
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - '='
123
137
  - !ruby/object:Gem::Version
124
- version: 0.5.2
138
+ version: 0.5.5
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: rspec-do_action
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -145,21 +173,28 @@ extra_rdoc_files: []
145
173
  files:
146
174
  - ".gitignore"
147
175
  - ".rspec"
176
+ - ".rubocop.yml"
148
177
  - ".travis.yml"
149
178
  - Gemfile
150
179
  - LICENSE.txt
151
180
  - README.md
152
181
  - Rakefile
182
+ - config.ru
153
183
  - fume-cancan.gemspec
184
+ - gemfiles/rails4_2.gemfile
154
185
  - lib/fume-cancan.rb
155
186
  - lib/fume/cancan/controller_extensions.rb
156
187
  - lib/fume/cancan/version.rb
157
- - spec/fume/cancan/controller_extensions_spec.rb
188
+ - lib/fume/cancan/with_scope.rb
158
189
  - spec/internal/app/controllers/application_controller.rb
159
190
  - spec/internal/app/models/ability.rb
191
+ - spec/internal/app/models/topic.rb
160
192
  - spec/internal/config/database.yml
161
193
  - spec/internal/config/routes.rb
162
194
  - spec/internal/db/schema.rb
195
+ - spec/internal/public/favicon.ico
196
+ - spec/lib/fume/cancan/controller_extensions_spec.rb
197
+ - spec/lib/fume/cancan/with_scope_spec.rb
163
198
  - spec/rails_helper.rb
164
199
  - spec/spec_helper.rb
165
200
  homepage: https://github.com/sunteya/fume-cancan
@@ -182,16 +217,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
217
  version: '0'
183
218
  requirements: []
184
219
  rubyforge_project:
185
- rubygems_version: 2.2.2
220
+ rubygems_version: 2.5.1
186
221
  signing_key:
187
222
  specification_version: 4
188
223
  summary: fume helper methods for CanCan
189
224
  test_files:
190
- - spec/fume/cancan/controller_extensions_spec.rb
191
225
  - spec/internal/app/controllers/application_controller.rb
192
226
  - spec/internal/app/models/ability.rb
227
+ - spec/internal/app/models/topic.rb
193
228
  - spec/internal/config/database.yml
194
229
  - spec/internal/config/routes.rb
195
230
  - spec/internal/db/schema.rb
231
+ - spec/internal/public/favicon.ico
232
+ - spec/lib/fume/cancan/controller_extensions_spec.rb
233
+ - spec/lib/fume/cancan/with_scope_spec.rb
196
234
  - spec/rails_helper.rb
197
235
  - spec/spec_helper.rb
236
+ has_rdoc: