Nicolae Claudius
13 years ago
14 changed files with 259 additions and 142 deletions
@ -0,0 +1,36 @@
|
||||
module ActionView |
||||
class LookupContext |
||||
module ViewPaths |
||||
def find_all_templates(name, partial = false, locals = {}) |
||||
prefixes.collect do |prefix| |
||||
view_paths.collect do |resolver| |
||||
temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) |
||||
temp_args[1] = temp_args[1][0] |
||||
resolver.find_all(*temp_args) |
||||
end |
||||
end.flatten! |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
# Bugfix: building an sti model from an association fails |
||||
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti |
||||
# https://github.com/rails/rails/issues/815 |
||||
# https://github.com/rails/rails/pull/1686 |
||||
ActiveRecord::Reflection::AssociationReflection.class_eval do |
||||
def klass_with_sti(*opts) |
||||
sti_col = klass.inheritance_column |
||||
if sti_col and (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass |
||||
new_klass |
||||
else |
||||
klass |
||||
end |
||||
end |
||||
def build_association(*opts, &block) |
||||
klass_with_sti(*opts).new(*opts, &block) |
||||
end |
||||
def create_association(*opts, &block) |
||||
klass_with_sti(*opts).create(*opts, &block) |
||||
end |
||||
end |
@ -0,0 +1,40 @@
|
||||
SwitchUserController.skip_before_filter :authenticate_user! |
||||
|
||||
SwitchUser.setup do |config| |
||||
# provider may be :devise or :authlogic |
||||
config.provider = :devise |
||||
|
||||
# available_users is a hash, |
||||
# key is the model name of user (:user, :admin, or any name you use), |
||||
# value is a block that return the users that can be switched. |
||||
config.available_users = { :user => lambda { User.all } } |
||||
|
||||
# available_users_identifiers is a hash, |
||||
# keys in this hash should match a key in the available_users hash |
||||
# value is the name of the identifying column to find by, |
||||
# defaults to id |
||||
# this hash is to allow you to specify a different column to |
||||
# expose for instance a username on a User model instead of id |
||||
config.available_users_identifiers = { :user => :id } |
||||
|
||||
# available_users_names is a hash, |
||||
# keys in this hash should match a key in the available_users hash |
||||
# value is the column name which will be displayed in select box |
||||
config.available_users_names = { :user => :email } |
||||
|
||||
# controller_guard is a block, |
||||
# if it returns true, the request will continue, |
||||
# else the request will be refused and returns "Permission Denied" |
||||
# if you switch from "admin" to user, the current_user param is "admin" |
||||
config.controller_guard = lambda { |current_user, request| Rails.env.development? } |
||||
|
||||
# view_guard is a block, |
||||
# if it returns true, the switch user select box will be shown, |
||||
# else the select box will not be shown |
||||
# if you switch from admin to "user", the current_user param is "user" |
||||
config.view_guard = lambda { |current_user, request| Rails.env.development? } |
||||
|
||||
# redirect_path is a block, it returns which page will be redirected |
||||
# after switching a user. |
||||
config.redirect_path = lambda { |request, params| '/' } |
||||
end |
@ -1,14 +1,28 @@
|
||||
# more sample users |
||||
users = [User.find_by_email('user@entrydns.net')] |
||||
for i in 1..5 do |
||||
name = "user#{i}" |
||||
user = User.create!( |
||||
:first_name => name, |
||||
:last_name => name, |
||||
:email => "#{name}@entrydns.net", |
||||
:password => 'useruser', |
||||
:password_confirmation => 'useruser' |
||||
) |
||||
user.confirm! |
||||
users << user unless i > 3 |
||||
end |
||||
|
||||
user = User.find_by_email('user@entrydns.net') |
||||
entrydns_org = Domain.find_by_name('entrydns.org') |
||||
for user in users |
||||
50.times do |
||||
domain = Factory.build(:domain, :user => user) |
||||
domain.setup(FactoryGirl.generate(:email)) |
||||
domain.save! |
||||
domain.soa_record.update_serial! |
||||
end |
||||
|
||||
100.times do |
||||
domain = Factory.build(:domain, :user => user) |
||||
domain.setup(FactoryGirl.generate(:email)) |
||||
domain.save! |
||||
domain.soa_record.update_serial! |
||||
end |
||||
|
||||
100.times do |
||||
Factory.create(:a, :user => user, :domain => entrydns_org) |
||||
50.times do |
||||
Factory.create(:a, :user => user, :domain => entrydns_org) |
||||
end |
||||
end |
Loading…
Reference in new issue