|
3 | 3 | generate :model, 'author name:string{10}:uniq last_name:string birthday:date'
|
4 | 4 | generate :model, 'post title:string:uniq body:text author:references'
|
5 | 5 |
|
6 |
| -#Add validation |
7 |
| -inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n\n attr_accessor :last_seen_at\n ransacker :last_seen_at do\n Arel.sql('updated_at')\n end\n", after: "ApplicationRecord\n" |
8 |
| -inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n" |
| 6 | +# Compatibility with old ransack |
| 7 | +inject_into_file "app/models/application_record.rb", after: "primary_abstract_class\n" do |
| 8 | + <<-STRING |
| 9 | +
|
| 10 | + def self.ransackable_attributes(auth_object=nil) |
| 11 | + if respond_to?(:authorizable_ransackable_attributes) |
| 12 | + authorizable_ransackable_attributes |
| 13 | + else |
| 14 | + super |
| 15 | + end |
| 16 | + end |
| 17 | +
|
| 18 | + def self.ransackable_associations(auth_object=nil) |
| 19 | + if respond_to?(:authorizable_ransackable_associations) |
| 20 | + authorizable_ransackable_associations |
| 21 | + else |
| 22 | + super |
| 23 | + end |
| 24 | + end |
| 25 | + STRING |
| 26 | +end |
| 27 | + |
| 28 | +# Virtual attributes |
| 29 | +inject_into_file "app/models/author.rb", after: "ApplicationRecord\n" do |
| 30 | + <<-STRING |
| 31 | + validates_presence_of :name |
| 32 | + validates_uniqueness_of :last_name |
| 33 | +
|
| 34 | + def self.ransackable_attributes(auth_object=nil) |
| 35 | + if respond_to?(:authorizable_ransackable_attributes) |
| 36 | + authorizable_ransackable_attributes |
| 37 | + else |
| 38 | + %w(birthday created_at last_seen_at updated_at) |
| 39 | + end |
| 40 | + end |
| 41 | +
|
| 42 | + attr_accessor :last_seen_at |
| 43 | +
|
| 44 | + ransacker :last_seen_at do |
| 45 | + Arel.sql('updated_at') |
| 46 | + end |
| 47 | + STRING |
| 48 | +end |
9 | 49 |
|
10 | 50 | # Configure default_url_options in test environment
|
11 |
| -inject_into_file "config/environments/test.rb", " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n" |
| 51 | +inject_into_file "config/environments/test.rb", after: "config.cache_classes = true\n" do |
| 52 | + " config.action_mailer.default_url_options = { :host => 'example.com' }\n" |
| 53 | +end |
12 | 54 |
|
13 | 55 | # Add our local Active Admin to the load path
|
14 |
| -inject_into_file "config/environment.rb", |
15 |
| - "\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n", |
16 |
| - after: "require File.expand_path('../application', __FILE__)" |
| 56 | +inject_into_file "config/environment.rb", after: "require File.expand_path('../application', __FILE__)" do |
| 57 | + "\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n" |
| 58 | +end |
17 | 59 |
|
18 | 60 | run "rm Gemfile"
|
19 | 61 |
|
|
23 | 65 | generate :'formtastic:install'
|
24 | 66 |
|
25 | 67 | # Install active_admin_date_time_datetimepicker assets
|
26 |
| -inject_into_file "app/assets/stylesheets/active_admin.scss", |
27 |
| - "@import \"active_admin_datetimepicker\";\n", |
28 |
| - after: "@import \"active_admin/base\";\n" |
| 68 | +inject_into_file "app/assets/stylesheets/active_admin.scss" do |
| 69 | + "@import \"active_admin_datetimepicker\";\n" |
| 70 | +end |
29 | 71 |
|
30 |
| -inject_into_file "app/assets/javascripts/active_admin.js", |
31 |
| - "//= require active_admin_datetimepicker\n", |
32 |
| - after: "//= require active_admin/base\n" |
| 72 | +inject_into_file "app/assets/javascripts/active_admin.js" do |
| 73 | + "//= require active_admin_datetimepicker\n" |
| 74 | +end |
33 | 75 |
|
34 | 76 | run "rm -r test"
|
35 | 77 | run "rm -r spec"
|
|
0 commit comments