canard 0.5.0.pre → 0.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.hound.yml +3 -0
  3. data/.rubocop.yml +27 -0
  4. data/.rubocop_todo.yml +37 -0
  5. data/.travis.yml +1 -1
  6. data/Gemfile +7 -6
  7. data/README.md +40 -37
  8. data/Rakefile +5 -2
  9. data/canard.gemspec +8 -7
  10. data/lib/ability.rb +14 -13
  11. data/lib/canard.rb +4 -2
  12. data/lib/canard/abilities.rb +7 -9
  13. data/lib/canard/adapters/active_record.rb +32 -29
  14. data/lib/canard/adapters/mongoid.rb +18 -11
  15. data/lib/canard/find_abilities.rb +8 -9
  16. data/lib/canard/railtie.rb +11 -16
  17. data/lib/canard/user_model.rb +66 -67
  18. data/lib/canard/version.rb +3 -1
  19. data/lib/generators/ability_definition.rb +16 -14
  20. data/lib/generators/canard/ability/ability_generator.rb +16 -12
  21. data/lib/generators/rspec/ability/ability_generator.rb +9 -9
  22. data/lib/tasks/canard.rake +6 -6
  23. data/test/abilities/administrators.rb +2 -2
  24. data/test/canard/abilities_test.rb +14 -21
  25. data/test/canard/ability_test.rb +40 -52
  26. data/test/canard/adapters/active_record_test.rb +71 -135
  27. data/test/canard/adapters/mongoid_test.rb +61 -132
  28. data/test/canard/canard_test.rb +8 -10
  29. data/test/canard/find_abilities_test.rb +9 -11
  30. data/test/canard/user_model_test.rb +22 -32
  31. data/test/dummy/Rakefile +3 -1
  32. data/test/dummy/app/abilities/admins.rb +4 -4
  33. data/test/dummy/app/abilities/authors.rb +3 -3
  34. data/test/dummy/app/abilities/editors.rb +2 -2
  35. data/test/dummy/app/abilities/guests.rb +3 -3
  36. data/test/dummy/app/abilities/users.rb +4 -4
  37. data/test/dummy/app/controllers/application_controller.rb +2 -0
  38. data/test/dummy/app/models/activity.rb +3 -1
  39. data/test/dummy/app/models/member.rb +3 -3
  40. data/test/dummy/app/models/mongoid_user.rb +5 -3
  41. data/test/dummy/app/models/plain_ruby_non_user.rb +2 -2
  42. data/test/dummy/app/models/plain_ruby_user.rb +3 -3
  43. data/test/dummy/app/models/post.rb +3 -1
  44. data/test/dummy/app/models/user.rb +3 -2
  45. data/test/dummy/app/models/user_without_role.rb +4 -4
  46. data/test/dummy/app/models/user_without_role_mask.rb +3 -3
  47. data/test/dummy/config.ru +3 -1
  48. data/test/dummy/config/application.rb +9 -8
  49. data/test/dummy/config/boot.rb +4 -2
  50. data/test/dummy/config/environment.rb +3 -1
  51. data/test/dummy/config/environments/development.rb +2 -0
  52. data/test/dummy/config/environments/test.rb +4 -2
  53. data/test/dummy/config/initializers/secret_token.rb +2 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -1
  55. data/test/dummy/config/initializers/wrap_parameters.rb +3 -1
  56. data/test/dummy/config/mongoid3.yml +5 -1
  57. data/test/dummy/config/routes.rb +2 -0
  58. data/test/dummy/db/migrate/20120430083231_initialize_db.rb +7 -7
  59. data/test/dummy/db/schema.rb +11 -11
  60. data/test/dummy/script/rails +4 -2
  61. data/test/support/reloadable.rb +14 -15
  62. data/test/test_helper.rb +7 -13
  63. metadata +18 -18
  64. data/test/dummy/config/mongoid2.yml +0 -9
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
4
+ require File.expand_path('application', __dir__)
3
5
 
4
6
  # Initialize the rails application
5
7
  Dummy::Application.initialize!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -9,7 +11,7 @@ Dummy::Application.configure do
9
11
 
10
12
  # Configure static asset server for tests with Cache-Control for performance
11
13
  config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
14
+ config.static_cache_control = 'public, max-age=3600'
13
15
 
14
16
  # Log error messages when you accidentally call methods on nil
15
17
  config.whiny_nils = true
@@ -22,7 +24,7 @@ Dummy::Application.configure do
22
24
  config.action_dispatch.show_exceptions = false
23
25
 
24
26
  # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
27
+ config.action_controller.allow_forgery_protection = false
26
28
 
27
29
  # Raise exception on mass assignment protection for Active Record models
28
30
  config.active_record.mass_assignment_sanitizer = :strict
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Your secret key for verifying the integrity of signed cookies.
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
5
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
6
 
5
7
  # Use the database for sessions instead of the cookie-based default,
6
8
  # which shouldn't be used to store highly confidential information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
  #
3
5
  # This file contains settings for ActionController::ParamsWrapper which
@@ -5,7 +7,7 @@
5
7
 
6
8
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
9
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
10
+ wrap_parameters format: [:json]
9
11
  end
10
12
 
11
13
  # Disable root element in JSON by default.
@@ -10,4 +10,8 @@ test:
10
10
  default:
11
11
  database: canard_test
12
12
  hosts:
13
- - localhost:27017
13
+ - localhost:27017
14
+ options:
15
+ connect_timeout: 0.01
16
+ wait_queue_timeout: 0.01
17
+ socket_timeout: 0.01
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.routes.draw do
2
4
  end
@@ -1,19 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class InitializeDb < ActiveRecord::Migration
2
-
3
4
  def change
4
- create_table :users, :force => true do |t|
5
+ create_table :users, force: true do |t|
5
6
  t.integer :roles_mask
6
7
  end
7
- create_table :user_without_roles, :force => true do |t|
8
+ create_table :user_without_roles, force: true do |t|
8
9
  t.integer :roles_mask
9
10
  end
10
- create_table :user_without_role_masks, :force => true do |t|
11
+ create_table :user_without_role_masks, force: true do |t|
11
12
  t.integer :my_roles_mask
12
13
  end
13
-
14
- create_table :members, :force => true do |t|
14
+
15
+ create_table :members, force: true do |t|
15
16
  t.references :user
16
17
  end
17
18
  end
18
-
19
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is auto-generated from the current state of the database. Instead
2
4
  # of editing this file, please use the migrations feature of Active Record to
3
5
  # incrementally modify your database, and then regenerate this schema definition.
@@ -10,22 +12,20 @@
10
12
  #
11
13
  # It's strongly recommended to check this file into your version control system.
12
14
 
13
- ActiveRecord::Schema.define(:version => 20120430083231) do
14
-
15
- create_table "members", :force => true do |t|
16
- t.integer "user_id"
15
+ ActiveRecord::Schema.define(version: 20_120_430_083_231) do
16
+ create_table 'members', force: true do |t|
17
+ t.integer 'user_id'
17
18
  end
18
19
 
19
- create_table "user_without_role_masks", :force => true do |t|
20
- t.integer "my_roles_mask"
20
+ create_table 'user_without_role_masks', force: true do |t|
21
+ t.integer 'my_roles_mask'
21
22
  end
22
23
 
23
- create_table "user_without_roles", :force => true do |t|
24
- t.integer "roles_mask"
24
+ create_table 'user_without_roles', force: true do |t|
25
+ t.integer 'roles_mask'
25
26
  end
26
27
 
27
- create_table "users", :force => true do |t|
28
- t.integer "roles_mask"
28
+ create_table 'users', force: true do |t|
29
+ t.integer 'roles_mask'
29
30
  end
30
-
31
31
  end
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
5
 
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
+ APP_PATH = File.expand_path('../config/application', __dir__)
7
+ require File.expand_path('../config/boot', __dir__)
6
8
  require 'rails/commands'
@@ -1,22 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MiniTest
2
4
  class Unit
3
5
  class TestCase
4
-
5
- def teardown
6
- Object.send(:remove_const, 'Canard') if Object.const_defined?('Canard')
7
- GC.start
8
- end
9
-
10
- def setup
11
- [ 'canard/abilities.rb',
12
- 'canard/user_model.rb',
13
- "canard/find_abilities.rb"
14
- ].each do |file|
15
- file_path = File.join(File.expand_path('../../../lib', __FILE__), file)
16
- load file_path
6
+ def teardown
7
+ Object.send(:remove_const, 'Canard') if Object.const_defined?('Canard')
8
+ GC.start
17
9
  end
18
- end
19
- end
20
10
 
11
+ def setup
12
+ ['canard/abilities.rb',
13
+ 'canard/user_model.rb',
14
+ 'canard/find_abilities.rb'].each do |file|
15
+ file_path = File.join(File.expand_path('../../lib', __dir__), file)
16
+ load file_path
17
+ end
18
+ end
19
+ end
21
20
  end
22
21
  end
@@ -1,33 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
- gem 'minitest'
3
4
  require 'minitest/autorun'
4
5
  require 'active_record'
5
6
  require 'mongoid'
6
7
 
7
8
  # Configure Rails Environment
8
- environment = ENV["RAILS_ENV"] = 'test'
9
- rails_root = File.expand_path('../dummy', __FILE__)
9
+ environment = ENV['RAILS_ENV'] = 'test'
10
+ rails_root = File.expand_path('dummy', __dir__)
10
11
  database_yml = File.expand_path('config/database.yml', rails_root)
11
12
 
12
13
  ActiveRecord::Base.configurations = YAML.load_file(database_yml)
13
14
 
14
15
  config = ActiveRecord::Base.configurations[environment]
15
- db = File.expand_path(config['database'], rails_root)
16
+ db = File.expand_path(config['database'], rails_root)
16
17
 
17
18
  # Drop the test database and migrate up
18
19
  FileUtils.rm(db) if File.exist?(db)
19
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => db)
20
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: db)
20
21
  ActiveRecord::Base.connection
21
22
  ActiveRecord::Migration.verbose = false
22
23
  ActiveRecord::Migrator.up File.expand_path('db/migrate', rails_root)
23
24
 
24
25
  # Load mongoid config
25
- if Mongoid::VERSION < '3'
26
- ENV["MONGOID_ENV"] = "test"
27
- Mongoid.load!(File.expand_path('config/mongoid2.yml', rails_root))
28
- else
29
- Mongoid.load!(File.expand_path('config/mongoid3.yml', rails_root), :test)
30
- end
26
+ Mongoid.load!(File.expand_path('config/mongoid3.yml', rails_root), :test)
31
27
  Mongoid.logger.level = :info
32
28
 
33
29
  # Load dummy rails app
@@ -37,5 +33,3 @@ Rails.backtrace_cleaner.remove_silencers!
37
33
 
38
34
  # Load support files (reloadable reloads canard)
39
35
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
40
-
41
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.pre
4
+ version: 0.6.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - James McCarthy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -25,39 +25,39 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: mongoid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.3
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 3.2.3
33
+ version: '3.0'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: 3.2.3
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 3.2.3
40
+ version: '3.0'
47
41
  - !ruby/object:Gem::Dependency
48
- name: mongoid
42
+ name: rails
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
51
48
  - - "~>"
52
49
  - !ruby/object:Gem::Version
53
- version: '3.0'
50
+ version: '3.2'
54
51
  type: :development
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
54
  requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.2'
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '3.0'
60
+ version: '3.2'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: cancancan
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,9 @@ extensions: []
95
95
  extra_rdoc_files: []
96
96
  files:
97
97
  - ".gitignore"
98
+ - ".hound.yml"
99
+ - ".rubocop.yml"
100
+ - ".rubocop_todo.yml"
98
101
  - ".travis.yml"
99
102
  - Gemfile
100
103
  - MIT-LICENSE
@@ -153,7 +156,6 @@ files:
153
156
  - test/dummy/config/initializers/session_store.rb
154
157
  - test/dummy/config/initializers/wrap_parameters.rb
155
158
  - test/dummy/config/locales/en.yml
156
- - test/dummy/config/mongoid2.yml
157
159
  - test/dummy/config/mongoid3.yml
158
160
  - test/dummy/config/routes.rb
159
161
  - test/dummy/db/migrate/20120430083231_initialize_db.rb
@@ -181,8 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
183
  version: 1.3.1
182
184
  requirements:
183
185
  - cancan's community supported Rails4+ compatible cancancan fork.
184
- rubyforge_project: canard
185
- rubygems_version: 2.6.10
186
+ rubygems_version: 3.0.2
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Adds role based authorisation to Rails by combining RoleModel and CanCanCan.
@@ -222,7 +223,6 @@ test_files:
222
223
  - test/dummy/config/initializers/session_store.rb
223
224
  - test/dummy/config/initializers/wrap_parameters.rb
224
225
  - test/dummy/config/locales/en.yml
225
- - test/dummy/config/mongoid2.yml
226
226
  - test/dummy/config/mongoid3.yml
227
227
  - test/dummy/config/routes.rb
228
228
  - test/dummy/db/migrate/20120430083231_initialize_db.rb
@@ -1,9 +0,0 @@
1
- development:
2
- database: canard_development
3
- host: localhost
4
- port: 27017
5
-
6
- test:
7
- database: canard_test
8
- host: localhost
9
- port: 27017