|
1 | | -# Rails template to build the sample app for specs |
| 1 | +generate :model, 'author name:string{10}:uniq last_name:string birthday:date --force' |
| 2 | +generate :model, 'post title:string:uniq body:text author:references --force' |
2 | 3 |
|
3 | | -generate :model, 'author name:string{10}:uniq last_name:string birthday:date' |
4 | | -generate :model, 'post title:string:uniq body:text author:references' |
5 | | - |
6 | | -#Add validation |
7 | | -inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "Base\n" |
| 4 | +inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "ApplicationRecord\n" |
8 | 5 | inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n" |
9 | 6 |
|
10 | | -# 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" |
12 | | - |
13 | | -# 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__)" |
17 | | - |
18 | | -run "rm Gemfile" |
| 7 | +# Add ransackable_attributes for Ransack 4+ |
| 8 | +inject_into_file "app/models/author.rb", |
| 9 | + " def self.ransackable_attributes(auth_object = nil)\n" \ |
| 10 | + " [\"name\", \"last_name\", \"birthday\", \"created_at\", \"updated_at\"]\n" \ |
| 11 | + " end\n", |
| 12 | + after: "ApplicationRecord\n" |
| 13 | + |
| 14 | +inject_into_file "app/models/post.rb", |
| 15 | + " def self.ransackable_attributes(auth_object = nil)\n" \ |
| 16 | + " [\"title\", \"body\", \"author_id\"]\n" \ |
| 17 | + " end\n" \ |
| 18 | + " def self.ransackable_associations(auth_object = nil)\n" \ |
| 19 | + " [\"author\"]\n" \ |
| 20 | + " end\n", |
| 21 | + after: "ApplicationRecord\n" |
| 22 | + |
| 23 | +# Add our local Active Admin to the load path (Rails 7.1+) |
| 24 | +gsub_file "config/environment.rb", |
| 25 | + 'require_relative "application"', |
| 26 | + "require_relative \"application\"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n" |
19 | 27 |
|
20 | 28 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) |
21 | 29 |
|
|
31 | 39 | "@import \"active_admin_sidebar\";\n", |
32 | 40 | after: "@import \"active_admin/base\";\n" |
33 | 41 |
|
34 | | -if File.file?("app/assets/javascripts/active_admin.js") |
35 | | - inject_into_file "app/assets/javascripts/active_admin.js", |
36 | | - "//= require active_admin_sidebar\n", |
37 | | - after: "//= require active_admin/base\n" |
38 | | -else |
39 | | - inject_into_file "app/assets/javascripts/active_admin.js.coffee", |
40 | | - "#= require active_admin_sidebar\n", |
41 | | - after: "#= require active_admin/base\n" |
42 | | -end |
43 | | - |
44 | | -run "rm -r test" |
45 | | -run "rm -r spec" |
| 42 | +inject_into_file "app/assets/javascripts/active_admin.js", |
| 43 | + "//= require active_admin_sidebar\n", |
| 44 | + after: "//= require active_admin/base\n" |
46 | 45 |
|
| 46 | +run "rm -rf test" |
47 | 47 | route "root :to => 'admin/dashboard#index'" |
48 | | - |
49 | 48 | rake "db:migrate" |
| 49 | + |
| 50 | +run "rm -f Gemfile Gemfile.lock" |
0 commit comments