maestrano-rails-test 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +273 -0
- data/Rakefile +38 -0
- data/app/controllers/maestrano/rails/metadata_controller.rb +8 -0
- data/app/controllers/maestrano/rails/saml_base_controller.rb +40 -0
- data/app/controllers/maestrano/rails/web_hook_controller.rb +16 -0
- data/lib/generators/active_record/maestrano_group_generator.rb +38 -0
- data/lib/generators/active_record/maestrano_user_generator.rb +38 -0
- data/lib/generators/active_record/templates/migration.rb +13 -0
- data/lib/generators/maestrano/USAGE +2 -0
- data/lib/generators/maestrano/group_generator.rb +11 -0
- data/lib/generators/maestrano/install_generator.rb +31 -0
- data/lib/generators/maestrano/orm_helpers.rb +75 -0
- data/lib/generators/maestrano/templates/group_users_controller.rb +26 -0
- data/lib/generators/maestrano/templates/groups_controller.rb +36 -0
- data/lib/generators/maestrano/templates/maestrano.rb +126 -0
- data/lib/generators/maestrano/templates/saml_controller.rb +52 -0
- data/lib/generators/maestrano/user_generator.rb +11 -0
- data/lib/generators/mongoid/maestrano_group_generator.rb +26 -0
- data/lib/generators/mongoid/maestrano_user_generator.rb +26 -0
- data/lib/maestrano-rails.rb +1 -0
- data/lib/maestrano/rails.rb +11 -0
- data/lib/maestrano/rails/controllers/maestrano_security.rb +32 -0
- data/lib/maestrano/rails/models/maestrano_auth_resource.rb +116 -0
- data/lib/maestrano/rails/routing/routes.rb +28 -0
- data/lib/maestrano/rails/version.rb +5 -0
- data/test/controllers/generic_controller_test.rb +56 -0
- data/test/controllers/group_users_controller_test.rb +23 -0
- data/test/controllers/groups_controller_test.rb +24 -0
- data/test/controllers/metadata_controller_test.rb +25 -0
- data/test/controllers/saml_controller_test.rb +123 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +44 -0
- data/test/dummy/log/test.log +6611 -0
- data/test/dummy_activerecord/README.rdoc +261 -0
- data/test/dummy_activerecord/Rakefile +7 -0
- data/test/dummy_activerecord/app/assets/javascripts/application.js +15 -0
- data/test/dummy_activerecord/app/assets/javascripts/pages.js +2 -0
- data/test/dummy_activerecord/app/assets/stylesheets/application.css +13 -0
- data/test/dummy_activerecord/app/assets/stylesheets/pages.css +4 -0
- data/test/dummy_activerecord/app/controllers/application_controller.rb +3 -0
- data/test/dummy_activerecord/app/controllers/maestrano/account/group_users_controller.rb +27 -0
- data/test/dummy_activerecord/app/controllers/maestrano/account/groups_controller.rb +37 -0
- data/test/dummy_activerecord/app/controllers/maestrano/auth/saml_controller.rb +14 -0
- data/test/dummy_activerecord/app/controllers/pages_controller.rb +4 -0
- data/test/dummy_activerecord/app/helpers/application_helper.rb +2 -0
- data/test/dummy_activerecord/app/helpers/pages_helper.rb +2 -0
- data/test/dummy_activerecord/app/models/admin.rb +5 -0
- data/test/dummy_activerecord/app/models/admin/monster.rb +2 -0
- data/test/dummy_activerecord/app/models/mno_crew.rb +7 -0
- data/test/dummy_activerecord/app/models/mno_monster.rb +9 -0
- data/test/dummy_activerecord/app/models/monster.rb +2 -0
- data/test/dummy_activerecord/app/views/layouts/application.html.erb +14 -0
- data/test/dummy_activerecord/app/views/pages/home.html.erb +2 -0
- data/test/dummy_activerecord/config.ru +4 -0
- data/test/dummy_activerecord/config/application.rb +56 -0
- data/test/dummy_activerecord/config/boot.rb +10 -0
- data/test/dummy_activerecord/config/database.yml +25 -0
- data/test/dummy_activerecord/config/environment.rb +5 -0
- data/test/dummy_activerecord/config/environments/development.rb +37 -0
- data/test/dummy_activerecord/config/environments/production.rb +67 -0
- data/test/dummy_activerecord/config/environments/test.rb +37 -0
- data/test/dummy_activerecord/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_activerecord/config/initializers/inflections.rb +15 -0
- data/test/dummy_activerecord/config/initializers/maestrano.rb +85 -0
- data/test/dummy_activerecord/config/initializers/mime_types.rb +5 -0
- data/test/dummy_activerecord/config/initializers/secret_token.rb +7 -0
- data/test/dummy_activerecord/config/initializers/session_store.rb +8 -0
- data/test/dummy_activerecord/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy_activerecord/config/locales/en.yml +5 -0
- data/test/dummy_activerecord/config/routes.rb +63 -0
- data/test/dummy_activerecord/db/development.sqlite3 +0 -0
- data/test/dummy_activerecord/db/migrate/20140526125222_create_monsters.rb +8 -0
- data/test/dummy_activerecord/db/migrate/20140526125242_create_admin_monsters.rb +8 -0
- data/test/dummy_activerecord/db/migrate/20140526144828_create_mno_monsters.rb +13 -0
- data/test/dummy_activerecord/db/migrate/20140526151139_create_mno_crews.rb +11 -0
- data/test/dummy_activerecord/db/schema.rb +44 -0
- data/test/dummy_activerecord/db/test.sqlite3 +0 -0
- data/test/dummy_activerecord/log/development.log +76 -0
- data/test/dummy_activerecord/log/test.log +326 -0
- data/test/dummy_activerecord/public/404.html +26 -0
- data/test/dummy_activerecord/public/422.html +26 -0
- data/test/dummy_activerecord/public/500.html +25 -0
- data/test/dummy_activerecord/public/favicon.ico +0 -0
- data/test/dummy_activerecord/script/rails +6 -0
- data/test/dummy_mongoid/README.rdoc +261 -0
- data/test/dummy_mongoid/Rakefile +7 -0
- data/test/dummy_mongoid/app/assets/javascripts/application.js +15 -0
- data/test/dummy_mongoid/app/assets/javascripts/pages.js +2 -0
- data/test/dummy_mongoid/app/assets/stylesheets/application.css +13 -0
- data/test/dummy_mongoid/app/assets/stylesheets/pages.css +4 -0
- data/test/dummy_mongoid/app/controllers/application_controller.rb +3 -0
- data/test/dummy_mongoid/app/controllers/maestrano/account/group_users_controller.rb +27 -0
- data/test/dummy_mongoid/app/controllers/maestrano/account/groups_controller.rb +37 -0
- data/test/dummy_mongoid/app/controllers/maestrano/auth/saml_controller.rb +14 -0
- data/test/dummy_mongoid/app/controllers/pages_controller.rb +4 -0
- data/test/dummy_mongoid/app/helpers/application_helper.rb +2 -0
- data/test/dummy_mongoid/app/helpers/pages_helper.rb +2 -0
- data/test/dummy_mongoid/app/models/mno_crew.rb +11 -0
- data/test/dummy_mongoid/app/models/mno_monster.rb +14 -0
- data/test/dummy_mongoid/app/models/monster.rb +3 -0
- data/test/dummy_mongoid/app/views/layouts/application.html.erb +14 -0
- data/test/dummy_mongoid/app/views/pages/home.html.erb +2 -0
- data/test/dummy_mongoid/config.ru +4 -0
- data/test/dummy_mongoid/config/application.rb +59 -0
- data/test/dummy_mongoid/config/boot.rb +10 -0
- data/test/dummy_mongoid/config/environment.rb +5 -0
- data/test/dummy_mongoid/config/environments/development.rb +37 -0
- data/test/dummy_mongoid/config/environments/production.rb +67 -0
- data/test/dummy_mongoid/config/environments/test.rb +37 -0
- data/test/dummy_mongoid/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_mongoid/config/initializers/inflections.rb +15 -0
- data/test/dummy_mongoid/config/initializers/maestrano.rb +85 -0
- data/test/dummy_mongoid/config/initializers/mime_types.rb +5 -0
- data/test/dummy_mongoid/config/initializers/secret_token.rb +7 -0
- data/test/dummy_mongoid/config/initializers/session_store.rb +8 -0
- data/test/dummy_mongoid/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy_mongoid/config/locales/en.yml +5 -0
- data/test/dummy_mongoid/config/mongoid.yml +80 -0
- data/test/dummy_mongoid/config/routes.rb +63 -0
- data/test/dummy_mongoid/db/migrate/20140526125222_create_monsters.rb +8 -0
- data/test/dummy_mongoid/db/migrate/20140526125242_create_admin_monsters.rb +8 -0
- data/test/dummy_mongoid/db/migrate/20140526144828_create_mno_monsters.rb +13 -0
- data/test/dummy_mongoid/db/migrate/20140526151139_create_mno_crews.rb +11 -0
- data/test/dummy_mongoid/db/schema.rb +44 -0
- data/test/dummy_mongoid/public/404.html +26 -0
- data/test/dummy_mongoid/public/422.html +26 -0
- data/test/dummy_mongoid/public/500.html +25 -0
- data/test/dummy_mongoid/public/favicon.ico +0 -0
- data/test/dummy_mongoid/script/rails +6 -0
- data/test/generators/group/active_record_generator_test.rb +79 -0
- data/test/generators/group/mongoid_generator_test.rb +76 -0
- data/test/generators/group_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +45 -0
- data/test/generators/user/active_record_generator_test.rb +79 -0
- data/test/generators/user/mongoid_generator_test.rb +76 -0
- data/test/generators/user_generator_test.rb +39 -0
- data/test/maestrano-rails_test.rb +7 -0
- data/test/models/maestrano_group_via_test.rb +66 -0
- data/test/models/maestrano_user_via_test.rb +70 -0
- data/test/test_files/config/routes.rb +58 -0
- data/test/test_helper.rb +42 -0
- data/test/tmp/app/models/monster.rb +20 -0
- metadata +418 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
development:
|
2
|
+
# Configure available database sessions. (required)
|
3
|
+
sessions:
|
4
|
+
# Defines the default session. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: dummy_development
|
9
|
+
# Provides the hosts the default session can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
options:
|
14
|
+
# Change whether the session persists in safe mode by default.
|
15
|
+
# (default: false)
|
16
|
+
# safe: false
|
17
|
+
|
18
|
+
# Change the default consistency model to :eventual or :strong.
|
19
|
+
# :eventual will send reads to secondaries, :strong sends everything
|
20
|
+
# to master. (default: :eventual)
|
21
|
+
# consistency: :eventual
|
22
|
+
|
23
|
+
# How many times Moped should attempt to retry an operation after
|
24
|
+
# failure. (default: 30)
|
25
|
+
# max_retries: 30
|
26
|
+
|
27
|
+
# The time in seconds that Moped should wait before retrying an
|
28
|
+
# operation on failure. (default: 1)
|
29
|
+
# retry_interval: 1
|
30
|
+
# Configure Mongoid specific options. (optional)
|
31
|
+
options:
|
32
|
+
# Configuration for whether or not to allow access to fields that do
|
33
|
+
# not have a field definition on the model. (default: true)
|
34
|
+
# allow_dynamic_fields: true
|
35
|
+
|
36
|
+
# Enable the identity map, needed for eager loading. (default: false)
|
37
|
+
# identity_map_enabled: false
|
38
|
+
|
39
|
+
# Includes the root model name in json serialization. (default: false)
|
40
|
+
# include_root_in_json: false
|
41
|
+
|
42
|
+
# Include the _type field in serializaion. (default: false)
|
43
|
+
# include_type_for_serialization: false
|
44
|
+
|
45
|
+
# Preload all models in development, needed when models use
|
46
|
+
# inheritance. (default: false)
|
47
|
+
# preload_models: false
|
48
|
+
|
49
|
+
# Protect id and type from mass assignment. (default: true)
|
50
|
+
# protect_sensitive_fields: true
|
51
|
+
|
52
|
+
# Raise an error when performing a #find and the document is not found.
|
53
|
+
# (default: true)
|
54
|
+
# raise_not_found_error: true
|
55
|
+
|
56
|
+
# Raise an error when defining a scope with the same name as an
|
57
|
+
# existing method. (default: false)
|
58
|
+
# scope_overwrite_exception: false
|
59
|
+
|
60
|
+
# Skip the database version check, used when connecting to a db without
|
61
|
+
# admin access. (default: false)
|
62
|
+
# skip_version_check: false
|
63
|
+
|
64
|
+
# User Active Support's time zone in conversions. (default: true)
|
65
|
+
# use_activesupport_time_zone: true
|
66
|
+
|
67
|
+
# Ensure all times are UTC in the app side. (default: false)
|
68
|
+
# use_utc: false
|
69
|
+
test:
|
70
|
+
sessions:
|
71
|
+
default:
|
72
|
+
database: dummy_test
|
73
|
+
hosts:
|
74
|
+
- localhost:27017
|
75
|
+
options:
|
76
|
+
consistency: :strong
|
77
|
+
# In the test environment we lower the retries and retry interval to
|
78
|
+
# low amounts for fast failures.
|
79
|
+
max_retries: 1
|
80
|
+
retry_interval: 0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
get "pages/home"
|
3
|
+
|
4
|
+
maestrano_routes
|
5
|
+
|
6
|
+
root to: 'pages#home'
|
7
|
+
# The priority is based upon order of creation:
|
8
|
+
# first created -> highest priority.
|
9
|
+
|
10
|
+
# Sample of regular route:
|
11
|
+
# match 'products/:id' => 'catalog#view'
|
12
|
+
# Keep in mind you can assign values other than :controller and :action
|
13
|
+
|
14
|
+
# Sample of named route:
|
15
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
16
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
17
|
+
|
18
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
19
|
+
# resources :products
|
20
|
+
|
21
|
+
# Sample resource route with options:
|
22
|
+
# resources :products do
|
23
|
+
# member do
|
24
|
+
# get 'short'
|
25
|
+
# post 'toggle'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# collection do
|
29
|
+
# get 'sold'
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Sample resource route with sub-resources:
|
34
|
+
# resources :products do
|
35
|
+
# resources :comments, :sales
|
36
|
+
# resource :seller
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Sample resource route with more complex sub-resources
|
40
|
+
# resources :products do
|
41
|
+
# resources :comments
|
42
|
+
# resources :sales do
|
43
|
+
# get 'recent', :on => :collection
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
|
47
|
+
# Sample resource route within a namespace:
|
48
|
+
# namespace :admin do
|
49
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
50
|
+
# # (app/controllers/admin/products_controller.rb)
|
51
|
+
# resources :products
|
52
|
+
# end
|
53
|
+
|
54
|
+
# You can have the root of your site routed with "root"
|
55
|
+
# just remember to delete public/index.html.
|
56
|
+
# root :to => 'welcome#index'
|
57
|
+
|
58
|
+
# See how all your routes lay out with "rake routes"
|
59
|
+
|
60
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
61
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
62
|
+
# match ':controller(/:action(/:id))(.:format)'
|
63
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20140526151139) do
|
15
|
+
|
16
|
+
create_table "admin_monsters", :force => true do |t|
|
17
|
+
t.datetime "created_at", :null => false
|
18
|
+
t.datetime "updated_at", :null => false
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table "mno_crews", :force => true do |t|
|
22
|
+
t.string "name"
|
23
|
+
t.string "provider"
|
24
|
+
t.string "uid"
|
25
|
+
t.datetime "created_at", :null => false
|
26
|
+
t.datetime "updated_at", :null => false
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "mno_monsters", :force => true do |t|
|
30
|
+
t.string "first_name"
|
31
|
+
t.string "last_name"
|
32
|
+
t.string "email"
|
33
|
+
t.string "provider"
|
34
|
+
t.string "uid"
|
35
|
+
t.datetime "created_at", :null => false
|
36
|
+
t.datetime "updated_at", :null => false
|
37
|
+
end
|
38
|
+
|
39
|
+
create_table "monsters", :force => true do |t|
|
40
|
+
t.datetime "created_at", :null => false
|
41
|
+
t.datetime "updated_at", :null => false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
if TEST_ORM == :active_record
|
4
|
+
require "generators/active_record/maestrano_group_generator"
|
5
|
+
|
6
|
+
class ActiveRecordGroupGeneratorTest < Rails::Generators::TestCase
|
7
|
+
tests ActiveRecord::Generators::MaestranoGroupGenerator
|
8
|
+
destination File.expand_path("../../../tmp", __FILE__)
|
9
|
+
setup :prepare_destination
|
10
|
+
|
11
|
+
|
12
|
+
context "normal model" do
|
13
|
+
setup { copy_model('monster') }
|
14
|
+
|
15
|
+
should "create the right migration" do
|
16
|
+
run_generator %w(monster)
|
17
|
+
assert_migration "db/migrate/add_maestrano_to_monsters.rb", /def self.up/
|
18
|
+
end
|
19
|
+
|
20
|
+
should "edit the model content" do
|
21
|
+
run_generator %w(monster)
|
22
|
+
assert_file "app/models/monster.rb", /maestrano_group_via/
|
23
|
+
end
|
24
|
+
|
25
|
+
should "not include parameters in rails 4" do
|
26
|
+
ActiveRecord::Generators::MaestranoGroupGenerator.any_instance.stubs(:rails_3?).returns(false)
|
27
|
+
run_generator %w(monster)
|
28
|
+
assert_file "app/models/monster.rb" do |content|
|
29
|
+
assert_no_match /attr_protected :provider/, content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
should "not include parameters if rails 3 and strong_parameter present" do
|
34
|
+
ActiveRecord::Generators::MaestranoGroupGenerator.any_instance.stubs(:rails_3?).returns(true)
|
35
|
+
ActiveRecord::Generators::MaestranoGroupGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(true)
|
36
|
+
run_generator %w(monster)
|
37
|
+
assert_file "app/models/monster.rb" do |content|
|
38
|
+
assert_no_match /attr_protected :provider/, content
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "include parameters if rails 3 and strong_parameter not present" do
|
43
|
+
ActiveRecord::Generators::MaestranoGroupGenerator.any_instance.stubs(:rails_3?).returns(true)
|
44
|
+
ActiveRecord::Generators::MaestranoGroupGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(false)
|
45
|
+
run_generator %w(monster)
|
46
|
+
assert_file "app/models/monster.rb" do |content|
|
47
|
+
assert_match /attr_protected :provider/, content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "namespaced model" do
|
53
|
+
setup { copy_model('admin/monster') }
|
54
|
+
|
55
|
+
should "create the right migration" do
|
56
|
+
run_generator %w(admin/monster)
|
57
|
+
assert_migration "db/migrate/add_maestrano_to_admin_monsters.rb", /def self.up/
|
58
|
+
end
|
59
|
+
|
60
|
+
should "edit the model content" do
|
61
|
+
run_generator %w(admin/monster)
|
62
|
+
assert_file "app/models/admin/monster.rb", /maestrano_group_via/
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Copy model like: 'monster' or 'admin/monster'
|
67
|
+
def copy_model(relative_model_path)
|
68
|
+
model_path = File.expand_path("../../../dummy_activerecord/app/models/#{relative_model_path}.rb", __FILE__)
|
69
|
+
if (path_ary = relative_model_path.split('/')) && path_ary.size > 1
|
70
|
+
destination = File.join(destination_root, "app", "models",*path_ary[0..-2])
|
71
|
+
else
|
72
|
+
destination = File.join(destination_root, "app", "models")
|
73
|
+
end
|
74
|
+
|
75
|
+
FileUtils.mkdir_p(destination)
|
76
|
+
FileUtils.cp model_path, destination
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|