2424 "\n cucumber:\n secret_key_base: #{ cucumber_secret } "
2525end
2626
27+ base_record = if Rails ::VERSION ::MAJOR >= 5
28+ 'ApplicationRecord'
29+ else
30+ 'ActiveRecord::Base'
31+ end
32+
2733# Generate some test models
2834generate :model , 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
29- inject_into_file 'app/models/post.rb' , " belongs_to :author, class_name: 'User'\n belongs_to :category\n accepts_nested_attributes_for :author\n " , after : "class Post < ActiveRecord::Base\n "
30- # Rails 3.2.3 model generator declare attr_accessible
31- if Rails ::VERSION ::MAJOR == 3
32- inject_into_file 'app/models/post.rb' ,
33- " attr_accessible :author\n " ,
34- before : 'end'
35- end
35+ post_model_setup = if Rails ::VERSION ::MAJOR >= 5
36+ <<-MODEL
37+ belongs_to :author, class_name: 'User'
38+ belongs_to :category, optional: true
39+ accepts_nested_attributes_for :author
40+ MODEL
41+ else
42+ <<-MODEL
43+ belongs_to :author, class_name: 'User'
44+ belongs_to :category
45+ accepts_nested_attributes_for :author
46+ MODEL
47+ end
48+ inject_into_file 'app/models/post.rb' ,
49+ post_model_setup ,
50+ after : "class Post < #{ base_record } \n "
51+
3652generate :model , 'user type:string first_name:string last_name:string username:string age:integer'
3753inject_into_file 'app/models/user.rb' ,
3854 " has_many :posts, foreign_key: 'author_id'\n " ,
39- after : "class User < ActiveRecord::Base\n "
55+ after : "class User < #{ base_record } \n "
56+
4057generate :model , 'publisher --migration=false --parent=User'
58+
4159generate :model , 'category name:string description:text'
4260inject_into_file 'app/models/category.rb' ,
4361 " has_many :posts\n accepts_nested_attributes_for :posts\n " ,
44- after : "class Category < ActiveRecord::Base\n "
62+ after : "class Category < #{ base_record } \n "
63+
4564generate :model , 'store name:string'
4665
4766# Generate a model with string ids
@@ -65,13 +84,7 @@ def set_id
6584
6685inject_into_file 'app/models/tag.rb' ,
6786 id_model_setup ,
68- after : "class Tag < ActiveRecord::Base\n "
69-
70- if Rails ::VERSION ::MAJOR == 3 && Rails ::VERSION ::MINOR == 1 # Rails 3.1 Gotcha
71- gsub_file 'app/models/tag.rb' ,
72- /self\. primary_key.*$/ ,
73- 'define_attr_method :primary_key, :id'
74- end
87+ after : "class Tag < #{ base_record } \n "
7588
7689# Configure default_url_options in test environment
7790inject_into_file (
@@ -97,25 +110,14 @@ def set_id
97110
98111$LOAD_PATH. unshift ( File . join ( File . dirname ( __FILE__ ) , '..' , 'lib' ) )
99112
100- if Rails ::VERSION ::MAJOR == 3
101- # we need this routing path, named "logout_path", for testing
102- route <<-ROUTE
103- devise_scope :user do
104- match '/admin/logout' => 'active_admin/devise/sessions#destroy', as: :logout
105- end
106- ROUTE
107- end
108-
109113generate :'active_admin:install'
110114
111115run 'rm -r test'
112116run 'rm -r spec'
113117
114- if Rails ::VERSION ::MAJOR > 3
115- inject_into_file 'config/initializers/active_admin.rb' ,
116- " config.download_links = %i[csv xml json xls]\n " ,
117- after : " # == Download Links\n "
118- end
118+ inject_into_file 'config/initializers/active_admin.rb' ,
119+ " config.download_links = %i[csv xml json xls]\n " ,
120+ after : " # == Download Links\n "
119121
120122# Setup a root path for devise
121123route "root to: 'admin/dashboard#index'"
0 commit comments