merit 3.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -20
  3. data/NEWS.md +32 -0
  4. data/README.md +29 -10
  5. data/Rakefile +13 -1
  6. data/app/models/merit/badge.rb +2 -19
  7. data/lib/merit.rb +18 -50
  8. data/lib/merit/{rules_badge_methods.rb → badge_rules_methods.rb} +0 -0
  9. data/lib/merit/base_target_finder.rb +1 -6
  10. data/lib/merit/{model_additions.rb → class_methods.rb} +2 -19
  11. data/lib/merit/controller_extensions.rb +4 -22
  12. data/lib/{generators → merit/generators}/active_record/install_generator.rb +8 -8
  13. data/lib/{generators → merit/generators}/active_record/merit_generator.rb +4 -4
  14. data/lib/{generators → merit/generators}/active_record/remove_generator.rb +5 -5
  15. data/lib/{generators/active_record/templates/add_merit_fields_to_model.rb → merit/generators/active_record/templates/add_merit_fields_to_model.erb} +0 -0
  16. data/lib/{generators/active_record/templates/create_badges_sashes.rb → merit/generators/active_record/templates/create_badges_sashes.erb} +0 -0
  17. data/lib/{generators/active_record/templates/create_merit_actions.rb → merit/generators/active_record/templates/create_merit_actions.erb} +2 -0
  18. data/lib/{generators/active_record/templates/create_merit_activity_logs.rb → merit/generators/active_record/templates/create_merit_activity_logs.erb} +0 -0
  19. data/lib/{generators/active_record/templates/create_sashes.rb → merit/generators/active_record/templates/create_sashes.erb} +0 -0
  20. data/lib/{generators/active_record/templates/create_scores_and_points.rb → merit/generators/active_record/templates/create_scores_and_points.erb} +1 -1
  21. data/lib/{generators/active_record/templates/remove_merit_fields_from_model.rb → merit/generators/active_record/templates/remove_merit_fields_from_model.erb} +0 -0
  22. data/lib/{generators/active_record/templates/remove_merit_tables.rb → merit/generators/active_record/templates/remove_merit_tables.erb} +0 -0
  23. data/lib/merit/generators/install_generator.rb +21 -0
  24. data/lib/{generators/merit → merit/generators}/merit_generator.rb +7 -2
  25. data/lib/{generators/merit → merit/generators}/remove_generator.rb +7 -2
  26. data/lib/{generators/merit/templates/merit.rb → merit/generators/templates/merit.erb} +13 -14
  27. data/lib/{generators/merit/templates/merit_badge_rules.rb → merit/generators/templates/merit_badge_rules.erb} +0 -0
  28. data/lib/{generators/merit/templates/merit_point_rules.rb → merit/generators/templates/merit_point_rules.erb} +0 -0
  29. data/lib/{generators/merit/templates/merit_rank_rules.rb → merit/generators/templates/merit_rank_rules.erb} +0 -0
  30. data/lib/merit/judge.rb +6 -5
  31. data/{app/models/merit/action.rb → lib/merit/models/action_concern.rb} +12 -10
  32. data/lib/merit/models/active_record/action.rb +11 -0
  33. data/lib/merit/models/active_record/{merit/activity_log.rb → activity_log.rb} +4 -6
  34. data/lib/merit/models/active_record/{merit/badges_sash.rb → badges_sash.rb} +4 -4
  35. data/lib/merit/models/active_record/{merit/sash.rb → sash.rb} +5 -2
  36. data/lib/merit/models/active_record/{merit/score.rb → score.rb} +4 -1
  37. data/lib/merit/models/badges_sash_concern.rb +13 -0
  38. data/lib/merit/models/base/badges_sash.rb +1 -1
  39. data/lib/merit/models/base/sash.rb +1 -1
  40. data/lib/merit/models/sash_concern.rb +53 -0
  41. data/lib/merit/{rules_points_methods.rb → point_rules_methods.rb} +0 -0
  42. data/lib/merit/{rules_rank_methods.rb → rank_rules_methods.rb} +3 -18
  43. data/merit.gemspec +7 -5
  44. data/test/dummy/app/controllers/comments_controller.rb +1 -1
  45. data/test/dummy/app/controllers/registrations_controller.rb +1 -1
  46. data/test/dummy/app/models/address.rb +1 -12
  47. data/test/dummy/app/models/comment.rb +3 -25
  48. data/test/dummy/app/models/user.rb +1 -18
  49. data/test/dummy/config/application.rb +8 -10
  50. data/test/dummy/config/application_api_only.rb +28 -0
  51. data/test/dummy/config/environment_api_only.rb +7 -0
  52. data/test/dummy/config/initializers/new_framework_defaults.rb +3 -0
  53. data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -0
  54. data/test/dummy/db/schema.rb +56 -59
  55. data/test/integration/navigation_test.rb +3 -3
  56. data/test/test_helper.rb +11 -12
  57. data/test/unit/base_target_finder_test.rb +7 -26
  58. data/test/unit/merit_unit_test.rb +13 -17
  59. data/test/unit/rule_unit_test.rb +15 -8
  60. data/test/unit/rules_matcher_test.rb +9 -6
  61. data/test/unit/sash_finder_test.rb +5 -5
  62. data/test/unit/sash_test.rb +16 -0
  63. data/test/unit/score_test.rb +1 -1
  64. data/test/unit/target_finder_test.rb +13 -13
  65. metadata +63 -73
  66. data/UPGRADING.md +0 -256
  67. data/lib/generators/active_record/templates/add_target_data_to_merit_actions.rb +0 -5
  68. data/lib/generators/active_record/upgrade_generator.rb +0 -40
  69. data/lib/generators/merit/install_generator.rb +0 -16
  70. data/lib/generators/merit/upgrade_generator.rb +0 -7
  71. data/lib/merit/models/active_record/merit/action.rb +0 -12
  72. data/lib/merit/models/mongoid/merit/action.rb +0 -18
  73. data/lib/merit/models/mongoid/merit/activity_log.rb +0 -11
  74. data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -22
  75. data/lib/merit/models/mongoid/merit/sash.rb +0 -30
  76. data/lib/merit/models/mongoid/merit/score.rb +0 -45
  77. data/test/dummy/db/migrate/20140906225844_create_players.rb +0 -8
  78. data/test/dummy/public/javascripts/application.js +0 -2
  79. data/test/dummy/public/javascripts/controls.js +0 -965
  80. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  81. data/test/dummy/public/javascripts/effects.js +0 -1123
  82. data/test/dummy/public/javascripts/prototype.js +0 -6001
  83. data/test/dummy/public/javascripts/rails.js +0 -191
  84. data/test/orm/active_record.rb +0 -2
  85. data/test/orm/mongoid.rb +0 -6
  86. data/test/orm_models/active_record.rb +0 -11
  87. data/test/orm_models/mongoid.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f485a4853da5aa06c851c133b85206b798755c41
4
- data.tar.gz: c148037a475f47d09b9a774da2fc8669ec016212
2
+ SHA256:
3
+ metadata.gz: 80cd3f1c6e1d7bac792d556e3b5145c82f0e3db9bd5b07eb6487c2de7f029613
4
+ data.tar.gz: ba6e5ee3691603cf88f3871b23bd875bb755fe2206c24f790d3ce427f6c2430f
5
5
  SHA512:
6
- metadata.gz: e43c8bb0a86b3d57adfeaa8816d566a8e9d4705d75a9ac926ce5e6dcc9c27eb1fd96bd145c353818275ea241a91475c9d3a7700f0d35d28532b1f54b794864c0
7
- data.tar.gz: 5f137da4113ebfb20f398fd733aa0b65285a3a8f6aa9758dae9536d13bab161fb2bef80da3d492468564cbaa9a933143343146b3dcd4f7d369a6022a6535cb44
6
+ metadata.gz: 639a9e1f07a6c5505a41ee412fb4d8de43184c125ca254b941501863b92ebc15c9495f1714d4edba4f286166e895c4962b62ed249a546eddc9b1201b8154dfdb
7
+ data.tar.gz: ba40fb0d27815c0f1e523cf445eef9b44f5fa06682562e067405216bb4b56c748af0574baaa7e9d4b5d3ec935dd2f7002bb03fa0655eb6d73805acc568079097
data/Gemfile CHANGED
@@ -2,27 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- version = ENV['RAILS_VERSION'] || '5.0.3'
6
- gem 'rails', version
7
-
8
- case ENV['ORM']
9
- when 'active_record'
10
- gem 'activerecord'
11
- when 'mongoid'
12
- gem 'mongoid'
13
- end
5
+ gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', 6.0)}"
14
6
 
15
7
  group :development, :test do
16
- gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
17
- gem 'sqlite3', '~> 1.3.8', :platforms => [:ruby, :mswin, :mingw]
18
- end
19
-
20
- platforms :rbx do
21
- gem 'rubysl', '~> 2.0'
22
- gem 'psych'
23
- gem 'racc'
24
- gem 'minitest', '~> 5.10', '!= 5.10.2'
25
- gem 'rubinius-developer_tools'
8
+ gem 'sqlite3', '~> 1.4'
26
9
  end
27
10
 
28
- gem 'coveralls', require: false
11
+ gem 'coveralls', '~> 0.8.23', require: false
data/NEWS.md CHANGED
@@ -2,6 +2,38 @@
2
2
 
3
3
  User-visible changes worth mentioning.
4
4
 
5
+ ## 4.0.2
6
+
7
+ - [#355, #356] Add index on merit_actions.processed column
8
+ - [#354] Fix Rails autoloader deprecation warnings
9
+ Requires wrapping `Merit::Badge.create` with `Rails.application.reloader.to_prepare`
10
+ - Test with Ruby 3 and Rails 6.1 (excludes Rails 5.2 with Ruby 3, that errors out)
11
+ - [#288] Don’t send “removed badge” notifications when user doesn’t have the badge
12
+
13
+ ## 4.0.1
14
+
15
+ - [#351] Fix bug on generating migrations
16
+
17
+ ## 4.0.0
18
+
19
+ - Stop testing on Rails 5.1
20
+ - Drop support for mongoid
21
+ - Drop v2 upgrade generators
22
+ - Enable Zeitwerk gem mode (and renames internal merit constants)
23
+
24
+ ## 3.0.3
25
+
26
+ - Test against Ruby 2.6 and Rails 6
27
+ - Use `find_each` in favor of `map` in `Merit::Action.check_unprocessed`
28
+ - Allow finding badges defined with symbol names
29
+ - Remove `Badge#last_granted` method (deprecated in merit <2.0)
30
+
31
+ ## 3.0.2
32
+
33
+ - [#287] Make Sash an optional dependency, fixing issues in Rails 5.1.
34
+ - [#297] Initialize merit once both for API or non-API apps
35
+ - Updates dependencies
36
+
5
37
  ## 3.0.1
6
38
 
7
39
  - [#282] Run action controller load hook only once
data/README.md CHANGED
@@ -38,8 +38,7 @@ and Rankings.
38
38
  2. Run `rails g merit:install`. This creates several migrations.
39
39
  3. Run `rails g merit MODEL_NAME` (e.g. `user`). This creates a migration and adds `has_merit` to MODEL_NAME.
40
40
  4. Run `rake db:migrate`
41
- 5. Define badges in `config/initializers/merit.rb`. You can also define ORM:
42
- `:active_record` (default) or `:mongoid`.
41
+ 5. Define badges in `config/initializers/merit.rb`
43
42
  6. Configure reputation rules for your application in `app/models/merit/*`
44
43
 
45
44
 
@@ -59,12 +58,16 @@ Create badges in `config/initializers/merit.rb`
59
58
  ### Example
60
59
 
61
60
  ```ruby
62
- Merit::Badge.create!(
63
- id: 1,
64
- name: "year-member",
65
- description: "Active member for a year",
66
- custom_fields: { difficulty: :silver }
67
- )
61
+ # config/initializers/merit.rb
62
+
63
+ Rails.application.reloader.to_prepare do
64
+ Merit::Badge.create!(
65
+ id: 1,
66
+ name: "year-member",
67
+ description: "Active member for a year",
68
+ custom_fields: { difficulty: :silver }
69
+ )
70
+ end
68
71
  ```
69
72
 
70
73
  ## Defining Rules
@@ -114,6 +117,19 @@ grant_on ['users#create', 'users#update'], badge: 'autobiographer', temporary: t
114
117
  end
115
118
  ```
116
119
 
120
+ If your controller is under a namespace other than root (example:
121
+ `Api::ModelController`) then for merit to find your object automatically you
122
+ must specify the model class and not forget that your action is of the form
123
+ `namespace/models#action`.
124
+
125
+ See an example of a `Post` model that belongs to user:
126
+
127
+ ```ruby
128
+ grant_on 'api/posts#create', badge: 'first-post', model_name: 'Post', to: :user do |post|
129
+ post.user.posts.count >= 1
130
+ end
131
+ ```
132
+
117
133
  ## Other Actions
118
134
 
119
135
  ```ruby
@@ -293,8 +309,8 @@ warning, with a comment to check the configuration for the rule.
293
309
 
294
310
  # Getting Notifications
295
311
 
296
- You can get observers notified any time merit changes reputation in your
297
- application.
312
+ You can get observers notified any time merit automatically changes reputation
313
+ in your application.
298
314
 
299
315
  It needs to implement the `update` method, which receives as parameter the
300
316
  following hash:
@@ -325,6 +341,9 @@ end
325
341
  config.add_observer 'ReputationChangeObserver'
326
342
  ```
327
343
 
344
+ **NOTE:** Observers won’t get notified if you grant reputation with
345
+ direct calls to `add_badge` or `add_point`.
346
+
328
347
  # I18n
329
348
 
330
349
  Merit uses default messages with I18n for notify alerts. To customize your app, you can set up your locale file:
data/Rakefile CHANGED
@@ -8,7 +8,11 @@ end
8
8
  require 'rake/testtask'
9
9
 
10
10
  desc 'Default: run tests for all ORMs.'
11
- task default: :test
11
+ task default: [:setup, :test, :api_test]
12
+
13
+ task :setup do
14
+ system "cd test/dummy && rake db:migrate && rake db:test:prepare"
15
+ end
12
16
 
13
17
  Rake::TestTask.new(:test) do |t|
14
18
  t.libs << 'lib'
@@ -17,6 +21,14 @@ Rake::TestTask.new(:test) do |t|
17
21
  t.verbose = true
18
22
  end
19
23
 
24
+ Rake::TestTask.new(:api_test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.test_files = FileList['test/**/*_test.rb'].exclude(/navigation_test.rb/)
28
+ t.verbose = true
29
+ t.options = '-- -api-only'
30
+ end
31
+
20
32
  begin
21
33
  require 'rdoc/task'
22
34
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -18,7 +18,7 @@ module Merit
18
18
  end
19
19
 
20
20
  def by_name(name)
21
- find { |b| b.name == name.to_s }
21
+ find { |b| b.name.to_s == name.to_s }
22
22
  end
23
23
 
24
24
  def by_level(level)
@@ -26,14 +26,6 @@ module Merit
26
26
  end
27
27
  end
28
28
 
29
- def _mongoid_sash_in(sashes)
30
- {:sash_id.in => sashes}
31
- end
32
-
33
- def _active_record_sash_in(sashes)
34
- {sash_id: sashes}
35
- end
36
-
37
29
  class << self
38
30
  def find_by_name_and_level(name, level)
39
31
  badges = Merit::Badge.by_name(name)
@@ -45,22 +37,13 @@ module Merit
45
37
  badge
46
38
  end
47
39
 
48
- # DEPRECATED: `last_granted` will be removed from merit, please refer to:
49
- # https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
50
- def last_granted(options = {})
51
- warn '[merit] [DEPRECATION] `last_granted` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-last-granted-badges'
52
- options[:since_date] ||= 1.month.ago
53
- options[:limit] ||= 10
54
- BadgesSash.last_granted(options)
55
- end
56
-
57
40
  # Defines Badge#meritable_models method, to get related
58
41
  # entries with certain badge. For instance, Badge.find(3).users
59
42
  # orm-specified
60
43
  def _define_related_entries_method(meritable_class_name)
61
44
  define_method(:"#{meritable_class_name.underscore.pluralize}") do
62
45
  sashes = BadgesSash.where(badge_id: id).pluck(:sash_id)
63
- meritable_class_name.constantize.where(send "_#{Merit.orm}_sash_in", sashes)
46
+ meritable_class_name.constantize.where(sash_id: sashes)
64
47
  end
65
48
  end
66
49
  end
data/lib/merit.rb CHANGED
@@ -1,17 +1,4 @@
1
- require 'merit/rule'
2
- require 'merit/rules_badge_methods'
3
- require 'merit/rules_points_methods'
4
- require 'merit/rules_rank_methods'
5
- require 'merit/rules_matcher'
6
- require 'merit/controller_extensions'
7
- require 'merit/model_additions'
8
- require 'merit/judge'
9
- require 'merit/reputation_change_observer'
10
- require 'merit/sash_finder'
11
- require 'merit/base_target_finder'
12
- require 'merit/target_finder'
13
- require 'merit/models/base/sash'
14
- require 'merit/models/base/badges_sash'
1
+ require 'zeitwerk'
15
2
 
16
3
  module Merit
17
4
  def self.setup
@@ -24,7 +11,6 @@ module Merit
24
11
  @config.checks_on_each_request
25
12
  end
26
13
 
27
- # # Define ORM
28
14
  def self.orm
29
15
  @config.orm || :active_record
30
16
  end
@@ -49,11 +35,6 @@ module Merit
49
35
  @config.add_observer(class_name)
50
36
  end
51
37
 
52
- def self.upgrade_target_data_warning
53
- Rails.logger.warn '[merit] Missing column: target_data. Run `rails ' \
54
- 'generate merit:upgrade` and `rake db:migrate` to add it.'
55
- end
56
-
57
38
  class Configuration
58
39
  attr_accessor :checks_on_each_request, :orm, :user_model_name, :observers,
59
40
  :current_user_method
@@ -80,38 +61,25 @@ module Merit
80
61
  config.app_generators.orm Merit.orm
81
62
 
82
63
  initializer 'merit.controller' do |app|
83
- extend_orm_with_has_merit
84
- require_models
85
- ActiveSupport.on_load(:action_controller, run_once: true) do
86
- begin
87
- # Load app rules on boot up
88
- Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
89
- Merit::AppPointRules = Merit::PointRules.new.defined_rules
90
- include Merit::ControllerExtensions
91
- rescue NameError => e
92
- # Trap NameError if installing/generating files
93
- raise e unless
94
- e.to_s =~ /uninitialized constant Merit::(BadgeRules|PointRules)/
64
+ config.to_prepare do
65
+ ActiveSupport.on_load(:active_record) { include Merit }
66
+ ActiveSupport.on_load(app.config.api_only ? :action_controller_api : :action_controller_base) do
67
+ begin
68
+ # Load app rules on boot up
69
+ Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
70
+ Merit::AppPointRules = Merit::PointRules.new.defined_rules
71
+ include Merit::ControllerExtensions
72
+ rescue NameError => e
73
+ # Trap NameError if installing/generating files
74
+ raise e unless
75
+ e.to_s =~ /uninitialized constant Merit::(BadgeRules|PointRules)/
76
+ end
95
77
  end
96
78
  end
97
79
  end
98
-
99
- def require_models
100
- require 'merit/models/base/sash'
101
- require 'merit/models/base/badges_sash'
102
- require "merit/models/#{Merit.orm}/merit/activity_log"
103
- require "merit/models/#{Merit.orm}/merit/badges_sash"
104
- require "merit/models/#{Merit.orm}/merit/sash"
105
- require "merit/models/#{Merit.orm}/merit/score"
106
- end
107
-
108
- def extend_orm_with_has_merit
109
- if Object.const_defined?('ActiveRecord')
110
- ActiveRecord::Base.send :include, Merit
111
- end
112
- if Object.const_defined?('Mongoid')
113
- Mongoid::Document.send :include, Merit
114
- end
115
- end
116
80
  end
117
81
  end
82
+
83
+ loader = Zeitwerk::Loader.for_gem
84
+ loader.setup
85
+ loader.eager_load
@@ -25,12 +25,7 @@ module Merit
25
25
  end
26
26
 
27
27
  def reanimate_target_from_action
28
- if @action.respond_to? :target_data
29
- YAML.load(@action.target_data)
30
- else
31
- Merit.upgrade_target_data_warning
32
- nil
33
- end
28
+ YAML.load(@action.target_data)
34
29
  end
35
30
  end
36
31
  end
@@ -7,10 +7,8 @@ module Merit
7
7
  # That's why MeritableModel belongs_to Sash. Can't use
8
8
  # dependent: destroy as it may raise FK constraint exceptions. See:
9
9
  # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1079-belongs_to-dependent-destroy-should-destroy-self-before-assocation
10
- belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil
11
- attr_accessible :sash if show_attr_accessible?
10
+ belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil, optional: true
12
11
 
13
- send :"_merit_#{Merit.orm}_specific_config"
14
12
  _merit_delegate_methods_to_sash
15
13
  _merit_define_badge_related_entries_method
16
14
  _merit_sash_initializer
@@ -23,26 +21,11 @@ module Merit
23
21
  methods.each { |method| delegate method, to: :_sash }
24
22
  end
25
23
 
26
- def _merit_active_record_specific_config
27
- end
28
-
29
- def _merit_mongoid_specific_config
30
- field :level, type: Integer, default: 0
31
- def find_by_id(id)
32
- where(_id: id).first
33
- end
34
- end
35
-
36
24
  def _merit_define_badge_related_entries_method
37
25
  meritable_class_name = name.demodulize
38
26
  Merit::Badge._define_related_entries_method(meritable_class_name)
39
27
  end
40
28
 
41
- def show_attr_accessible?
42
- defined?(ProtectedAttributes) ||
43
- !defined?(ActionController::StrongParameters)
44
- end
45
-
46
29
  # _sash initializes a sash if doesn't have one yet.
47
30
  # From Rails 3.2 we can override association methods to do so
48
31
  # transparently, but merit supports Rails ~> 3.0.0. See:
@@ -50,7 +33,7 @@ module Merit
50
33
  def _merit_sash_initializer
51
34
  define_method(:_sash) do
52
35
  # TODO: reload.sash is not regression tested
53
- sash || reload.sash || update_attributes(sash: Sash.create)
36
+ sash || reload.sash || update(sash: Sash.create)
54
37
  sash
55
38
  end
56
39
  end
@@ -27,16 +27,8 @@ module Merit
27
27
  had_errors: had_errors?,
28
28
  target_model: controller_path,
29
29
  target_id: target_id,
30
- }.merge(target_data_hash)
31
- end
32
-
33
- def target_data_hash
34
- if Merit::Action.new.respond_to?(:target_data)
35
- { target_data: target_object.to_yaml }
36
- else
37
- Merit.upgrade_target_data_warning
38
- {}
39
- end
30
+ target_data: target_object.to_yaml,
31
+ }
40
32
  end
41
33
 
42
34
  def rules_defined?
@@ -69,21 +61,11 @@ module Merit
69
61
 
70
62
  def target_id
71
63
  target_id = target_object.try(:id)
72
- # If target_id is nil
73
- # then use params[:id].
74
- if target_id.nil? && send("check_#{Merit.orm}_id", params[:id])
64
+ # If target_id is nil use (only digits of) params[:id]
65
+ if target_id.nil? && params[:id].to_s =~ /^[0-9]+$/
75
66
  target_id = params[:id]
76
67
  end
77
68
  target_id
78
69
  end
79
-
80
- # This check avoids trying to set a slug as integer FK
81
- def check_active_record_id(id)
82
- id.to_s =~ /^[0-9]+$/
83
- end
84
-
85
- def check_mongoid_id(id)
86
- id.to_s =~ /^[0-9a-fA-F]{24}$/
87
- end
88
70
  end
89
71
  end
@@ -1,8 +1,8 @@
1
1
  require 'rails/generators/active_record'
2
2
 
3
- module ActiveRecord
4
- module Generators
5
- class InstallGenerator < Rails::Generators::Base
3
+ module Merit
4
+ module Generators::ActiveRecord
5
+ class InstallGenerator < ::Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
@@ -13,19 +13,19 @@ module ActiveRecord
13
13
  end
14
14
 
15
15
  def copy_migrations_and_model
16
- migration_template 'create_merit_actions.rb',
16
+ migration_template 'create_merit_actions.erb',
17
17
  'db/migrate/create_merit_actions.rb'
18
18
 
19
- migration_template 'create_merit_activity_logs.rb',
19
+ migration_template 'create_merit_activity_logs.erb',
20
20
  'db/migrate/create_merit_activity_logs.rb'
21
21
 
22
- migration_template 'create_sashes.rb',
22
+ migration_template 'create_sashes.erb',
23
23
  'db/migrate/create_sashes.rb'
24
24
 
25
- migration_template 'create_badges_sashes.rb',
25
+ migration_template 'create_badges_sashes.erb',
26
26
  'db/migrate/create_badges_sashes.rb'
27
27
 
28
- migration_template 'create_scores_and_points.rb',
28
+ migration_template 'create_scores_and_points.erb',
29
29
  'db/migrate/create_scores_and_points.rb'
30
30
  end
31
31