Work in progress: has_many_polymorphs does not work with rails 3.2 because of intrusive changes in rails internals. I think we need to rip out this dependency...

This commit is contained in:
Reinier Balt 2012-04-05 22:19:47 +02:00
parent a83c8b3f92
commit 86afd42148
162 changed files with 704 additions and 8724 deletions

View file

@ -1,113 +0,0 @@
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session['user_id'] = user ? users(user).id : nil
end
def content_type(type)
@request.env['Content-Type'] = type
end
def accept(accept)
@request.env["HTTP_ACCEPT"] = accept
end
def authorize_as(user)
if user
@request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}"
accept 'application/xml'
content_type 'application/xml'
else
@request.env["HTTP_AUTHORIZATION"] = nil
accept nil
content_type nil
end
end
# http://project.ioni.st/post/217#post-217
#
# def test_new_publication
# assert_difference(Publication, :count) do
# post :create, :publication => {...}
# # ...
# end
# end
#
def assert_difference(object, method = nil, difference = 1)
initial_value = object.send(method)
yield
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
end
def assert_no_difference(object, method, &block)
assert_difference object, method, 0, &block
end
# Assert the block redirects to the login
#
# assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
#
def assert_requires_login(login = nil)
yield HttpLoginProxy.new(self, login)
end
def assert_http_authentication_required(login = nil)
yield XmlLoginProxy.new(self, login)
end
def reset!(*instance_vars)
instance_vars = [:controller, :request, :response] unless instance_vars.any?
instance_vars.collect! { |v| "@#{v}".to_sym }
instance_vars.each do |var|
instance_variable_set(var, instance_variable_get(var).class.new)
end
end
end
class BaseLoginProxy
attr_reader :controller
attr_reader :options
def initialize(controller, login)
@controller = controller
@login = login
end
private
def authenticated
raise NotImplementedError
end
def check
raise NotImplementedError
end
def method_missing(method, *args)
@controller.reset!
authenticate
@controller.send(method, *args)
check
end
end
class HttpLoginProxy < BaseLoginProxy
protected
def authenticate
@controller.login_as @login if @login
end
def check
@controller.assert_redirected_to :controller => 'account', :action => 'login'
end
end
class XmlLoginProxy < BaseLoginProxy
protected
def authenticate
@controller.accept 'application/xml'
@controller.authorize_as @login if @login
end
def check
@controller.assert_response 401
end
end

View file

@ -1,6 +1,6 @@
require_dependency "user"
module LoginSystem
module LoginSystem
def current_user
get_current_user
@ -29,7 +29,7 @@ module LoginSystem
protected
# overwrite this if you want to restrict access to only a few actions
# or if you want to check if the user has the correct rights
# or if you want to check if the user has the correct rights
# example:
#
# # only allow nonbobs
@ -42,7 +42,7 @@ module LoginSystem
# overwrite this method if you only want to protect certain actions of the controller
# example:
#
#
# # don't protect the login and the about method
# def protect?(action)
# if ['action', 'about'].include?(action)
@ -59,7 +59,8 @@ module LoginSystem
# cookie and log the user back in if appropriate
def login_from_cookie
return unless cookies[:auth_token] && !logged_in?
user = User.find_by_remember_token(cookies[:auth_token])
token = cookies[:auth_token]
user = User.find_by_remember_token(token)
if user && user.remember_token?
session['user_id'] = user.id
set_current_user(user)
@ -67,7 +68,7 @@ module LoginSystem
cookies[:auth_token] = { :value => current_user.remember_token , :expires => current_user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
flash[:notice] = t('login.successful')
end
end
end
def login_or_feed_token_required
if ['rss', 'atom', 'txt', 'ics'].include?(params[:format])
@ -79,15 +80,15 @@ module LoginSystem
login_required
end
# login_required filter. add
# login_required filter. add
#
# before_filter :login_required
#
# if the controller should be under any rights management.
# if the controller should be under any rights management.
# for finer access control you can overwrite
#
#
# def authorize?(user)
#
#
def login_required
if not protect?(action_name)
@ -107,13 +108,13 @@ module LoginSystem
return true
end
# store current location so that we can
# store current location so that we can
# come back after the user logged in
store_location unless params[:format] == 'js'
# call overwriteable reaction to unauthorized access
access_denied
return false
return false
end
def login_optional
@ -131,7 +132,7 @@ module LoginSystem
return true
end
return true
return true
end
def logged_in?
@ -150,7 +151,7 @@ module LoginSystem
end
# overwrite if you want to have special behavior in case the user is not authorized
# to access the current operation.
# to access the current operation.
# the default action is to redirect to the login screen
# example use :
# a popup window might just close itself for instance
@ -164,7 +165,7 @@ module LoginSystem
format.atom { basic_auth_denied }
format.text { basic_auth_denied }
end
end
end
# store current uri in the session.
# we can return to this location by calling return_location
@ -195,8 +196,8 @@ module LoginSystem
authdata = request.env[location].to_s.split
end
end
if authdata and authdata[0] == 'Basic'
user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
if authdata and authdata[0] == 'Basic'
user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
else
user, pass = ['', '']
end

View file

@ -1,5 +0,0 @@
module NamePartFinder
def find_by_namepart(namepart)
find_by_name(namepart) || find(:first, :conditions => ["name LIKE ?", namepart + '%'])
end
end

View file

View file

@ -1,38 +0,0 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:selenium => :env_to_selenium}, 'Run features that require selenium') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'selenium'
end
Cucumber::Rake::Task.new({:selenium_wip => :env_to_selenium}, 'Run unfinished features that require selenium') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'selenium_wip'
end
task :env_to_selenium => 'db:test:prepare' do
ENV['RAILS_ENV'] = 'selenium'
end
desc 'Run all features'
task :all => [:ok, :wip, :selenium, :selenium_wip]
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end

View file

@ -1,53 +0,0 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
end
desc 'Run all features'
task :all => [:ok, :wip]
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'
task :default => :cucumber
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end
end

View file

@ -1,27 +0,0 @@
require 'rake'
namespace :db do
desc "Dump the current SQLite3 or MySQL database to a sql file"
task :dump_sql do
load 'config/environment.rb'
abcs = ActiveRecord::Base.configurations
case abcs[RAILS_ENV]["adapter"]
when 'mysql'
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
File.open("db/#{RAILS_ENV}_data.sql", "w+") do |f|
if abcs[RAILS_ENV]["password"].blank?
f << `mysqldump -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} #{abcs[RAILS_ENV]["database"]}`
else
f << `mysqldump -h #{abcs[RAILS_ENV]["host"]} -u #{abcs[RAILS_ENV]["username"]} -p#{abcs[RAILS_ENV]["password"]} #{abcs[RAILS_ENV]["database"]}`
end
end
when 'sqlite3'
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
File.open("db/#{RAILS_ENV}_data.sql", "w+") do |f|
f << `sqlite3 #{abcs[RAILS_ENV]["database"]} .dump`
end
else
raise "Task not supported by '#{abcs[RAILS_ENV]['adapter']}'"
end
end
end

View file

@ -1,17 +0,0 @@
desc ' Create YAML test fixtures from data in an existing database.
Defaults to development database. Set RAILS_ENV to override (taken from Rails Recipes book).'
task :extract_fixtures => :environment do
sql = "SELECT * FROM %s"
skip_tables = ["schema_info", "sessions", "users"]
ActiveRecord::Base.establish_connection
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
i = "000"
File.open("#{RAILS_ROOT}/db/exported_fixtures/#{table_name}.yml", 'w' ) do |file|
data = ActiveRecord::Base.connection.select_all(sql % table_name)
file.write data.inject({}) { |hash, record|
hash["#{table_name}_#{i.succ!}"] = record
hash
}.to_yaml
end
end
end

View file

@ -1,34 +0,0 @@
desc "Copy third-party gems into ./lib"
task :freeze_other_gems do
# TODO Get this list from parsing environment.rb
libraries = %w(redcloth)
require 'rubygems'
require 'find'
libraries.each do |library|
library_gem = Gem.cache.search(library).sort_by { |g| g.version }.last
puts "Freezing #{library} for #{library_gem.version}..."
# TODO Add dependencies to list of libraries to freeze
#library_gem.dependencies.each { |g| libraries << g }
folder_for_library = "#{library_gem.name}-#{library_gem.version}"
system "cd vendor; gem unpack -v '#{library_gem.version}' #{library_gem.name};"
# Copy files recursively to ./lib
folder_for_library_with_lib = "vendor/#{folder_for_library}/lib/"
Find.find(folder_for_library_with_lib) do |original_file|
destination_file = "./lib/" + original_file.gsub(folder_for_library_with_lib, '')
if File.directory?(original_file)
if !File.exist?(destination_file)
Dir.mkdir destination_file
end
else
File.copy original_file, destination_file
end
end
system "rm -r vendor/#{folder_for_library}"
end
end

View file

@ -1,8 +0,0 @@
desc "Load exported fixtures (in db/exported_fixtures) into the current environment's database"
task :load_exported_fixtures => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
Dir.glob(File.join(RAILS_ROOT, 'db', 'exported_fixtures', '*.{yml,csv}')).each do |fixture_file|
Fixtures.create_fixtures('db/exported_fixtures', File.basename(fixture_file, '.*'))
end
end

View file

@ -1,50 +0,0 @@
namespace :query_trace do
desc "Enables the query_trace plugin. Must restart server to take effect."
task :on => :environment do
unless File.exist?("#{RAILS_ROOT}/vendor/query_trace.tar.gz")
Dir.chdir("#{RAILS_ROOT}/vendor") do
url = "https://terralien.devguard.com/svn/projects/plugins/query_trace"
puts "Loading query_trace from #{url}..."
system "svn co #{url} query_trace"
system "tar zcf query_trace.tar.gz --exclude=.svn query_trace"
FileUtils.rm_rf("query_trace")
end
end
Dir.chdir("#{RAILS_ROOT}/vendor/plugins") do
system "tar zxf ../query_trace.tar.gz query_trace"
end
puts "QueryTrace plugin enabled. Must restart server to take effect."
end
desc "Disables the query_trace plugin. Must restart server to take effect."
task :off => :environment do
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_trace")
puts "QueryTrace plugin disabled. Must restart server to take effect."
end
end
namespace :query_analyzer do
desc "Enables the query_analyzer plugin. Must restart server to take effect."
task :on => :environment do
unless File.exist?("#{RAILS_ROOT}/vendor/query_analyzer.tar.gz")
Dir.chdir("#{RAILS_ROOT}/vendor") do
url = "http://svn.nfectio.us/plugins/query_analyzer"
puts "Loading query_analyzer from #{url}..."
system "svn co #{url} query_analyzer"
system "tar zcf query_analyzer.tar.gz --exclude=.svn query_analyzer"
FileUtils.rm_rf("query_analyzer")
end
end
Dir.chdir("#{RAILS_ROOT}/vendor/plugins") do
system "tar zxf ../query_analyzer.tar.gz query_analyzer"
end
puts "QueryAnalyzer plugin enabled. Must restart server to take effect."
end
desc "Disables the query_analyzer plugin. Must restart server to take effect."
task :off => :environment do
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_analyzer")
puts "QueryAnalyzer plugin disabled. Must restart server to take effect."
end
end

View file

@ -1,23 +0,0 @@
namespace :tracks do
desc 'Replace the password of USER with a new one.'
task :password => :environment do
require "highline/import"
user = User.find_by_login(ENV['USER'])
if user.nil?
puts "Sorry, we couldn't find user '#{ENV['USER']}'. To specify a different user, pass USER=username to this task."
exit 0
end
puts "Changing Tracks password for #{ENV['USER']}."
password = ask("New password: ") { |q| q.echo = false }
password_confirmation = ask('Retype new password: ') { |q| q.echo = false }
begin
user.change_password(password, password_confirmation)
rescue ActiveRecord::RecordInvalid
puts "Sorry, we couldn't change #{ENV['USER']}'s password: "
user.errors.each_full { |msg| puts "- #{msg}\n" }
end
end
end

View file

@ -1,144 +0,0 @@
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
rspec_gem_dir = nil
Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
end
rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
if rspec_gem_dir && (test ?d, rspec_plugin_dir)
raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
end
if rspec_gem_dir
$LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
elsif File.exist?(rspec_plugin_dir)
$LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
end
# Don't load rspec if running "rake gems:*"
unless ARGV.any? {|a| a =~ /^gems/}
begin
require 'spec/rake/spectask'
rescue MissingSourceFile
module Spec
module Rake
class SpecTask
def initialize(name)
task name do
# if rspec-rails is a configured gem, this will output helpful material and exit ...
require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
# ... otherwise, do this:
raise <<-MSG
#{"*" * 80}
* You are trying to run an rspec rake task defined in
* #{__FILE__},
* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
#{"*" * 80}
MSG
end
end
end
end
end
end
Rake.application.instance_variable_get('@tasks').delete('default')
spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
task :noop do
end
task :default => :spec
task :stats => "spec:statsetup"
desc "Run all specs in spec directory (excluding plugin specs)"
Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
end
namespace :spec do
desc "Run all specs in spec directory with RCov (excluding plugin specs)"
Spec::Rake::SpecTask.new(:rcov) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
t.rcov = true
t.rcov_opts = lambda do
IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
end
end
desc "Print Specdoc for all specs (excluding plugin specs)"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['spec/**/*_spec.rb']
end
desc "Print Specdoc for all plugin examples"
Spec::Rake::SpecTask.new(:plugin_doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
end
[:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
desc "Run the code examples in spec/#{sub}"
Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
end
end
desc "Run the code examples in vendor/plugins (except RSpec's own)"
Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
end
namespace :plugins do
desc "Runs the examples for rspec_on_rails"
Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
end
end
# Setup specs for stats
task :statsetup do
require 'code_statistics'
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
end
namespace :db do
namespace :fixtures do
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
task :load => :environment do
ActiveRecord::Base.establish_connection(Rails.env)
base_dir = File.join(Rails.root, 'spec', 'fixtures')
fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
require 'active_record/fixtures'
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
end
end
end
end
end
end

View file

@ -1,15 +0,0 @@
desc "Initialises the installation, copy the *.tmpl files and directories to versions named without the .tmpl extension. It won't overwrite the files and directories if you've already copied them. You need to manually copy database.yml.tmpl -> database.yml and fill in the details before you run this task."
task :setup_tracks => :environment do
# Check the root directory for template files
FileList["*.tmpl"].each do |template_file|
f = File.basename(template_file) # with suffix
f_only = File.basename(template_file,".tmpl") # without suffix
if File.exists?(f_only)
puts f_only + " already exists"
else
cp_r(f, f_only)
puts f_only + " created"
end
end
end

View file

@ -1,40 +0,0 @@
desc "Updates sqlite/sqlite3 databases created under Tracks 1.03 to the format required for Tracks 1.04. After this is done, you should be able to keep up to date with changes in the schema by running rake db:migrate."
task :upgrade_sqlite_db => :environment do
# Change the three lines below appropriately for your setup
old_db = "tracks_103.db"
new_db = "tracks_104.db"
cmd = "sqlite3"
replace_string = "update todos set done='f' where done=0;\nupdate todos set done='t' where done=1;\nupdate contexts set hide='f' where hide=0;\nupdate contexts set hide='t' where hide=1;\nupdate projects set done='f' where done=0;\nupdate projects set done='t' where done=1;\nCREATE TABLE 'schema_info' (\n 'version' INTEGER default NULL\n);\nINSERT INTO \"schema_info\" VALUES(1);\nCOMMIT;"
# cd to the db directory
cd("db") do
# Dump the old db into the temp file and replace the tinyints with booleans
`#{cmd} #{old_db} .dump | sed "s/tinyint(4) NOT NULL default '0'/boolean default 'f'/" > temp.sql`
# Create a second sqldump file for writing
sqldump = File.open("temp2.sql", "w+")
File.open("temp.sql") do |file|
file.each_line do |line|
# If COMMIT is on the line, insert the replace string
# else just write the line back in
# This effectively replaces COMMIT with the replace string
if /COMMIT/ =~ line
sqldump.write replace_string
else
sqldump.write line
end
end
sqldump.close
end
# Read the second dump back in to a new db
system "#{cmd} #{new_db} < temp2.sql"
puts "Created the a new database called #{new_db}."
# Clean up the temp files
rm("temp.sql")
rm("temp2.sql")
puts "Temporary files cleaned up."
end
# rake db:migrate
puts "Now check the database and run 'rake db:migrate' in the root of your Tracks installation."
end

View file

@ -1,27 +0,0 @@
module Tracks
class Config
def self.salt
SITE_CONFIG['salt']
end
def self.auth_schemes
SITE_CONFIG['authentication_schemes'] || []
end
def self.openid_enabled?
auth_schemes.include?('open_id')
end
def self.cas_enabled?
auth_schemes.include?('cas')
end
def self.prefered_auth?
if SITE_CONFIG['prefered_auth']
SITE_CONFIG['prefered_auth']
else
auth_schemes.first
end
end
end
end

View file

@ -1,59 +0,0 @@
module Tracks
module TodoList
# TODO: this module should be deprecated. This could mostly (all?) be replaced by named scopes)
def not_done_todos(opts={})
@not_done_todos ||= self.find_not_done_todos(opts)
end
def done_todos
@done_todos ||= self.find_done_todos
end
def deferred_todos
@deferred_todos ||= self.find_deferred_todos
end
def find_not_done_todos(opts={})
with_not_done_scope(opts) do
self.todos.find(:all, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
end
end
def find_deferred_todos(opts={})
self.todos.find_in_state(:all, :deferred, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
end
def find_done_todos
self.todos.completed.all(:order => "todos.completed_at DESC", :limit => self.user.prefs.show_number_completed)
end
def not_done_todo_count(opts={})
with_not_done_scope(opts) do
self.todos.count
end
end
def with_not_done_scope(opts={})
conditions = ["todos.state = ?", 'active']
if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true)
conditions = ["(todos.state = ? OR todos.state = ?)", 'active', 'project_hidden']
end
if opts.has_key?(:tag)
conditions = ["todos.state = ? AND taggings.tag_id = ?", 'active', opts[:tag]]
end
self.todos.send :with_scope, :find => {:conditions => conditions, :include => [:taggings]} do
yield
end
end
def done_todo_count
self.todos.count_in_state(:completed)
end
def deferred_todo_count
self.todos.count_in_state(:deferred)
end
end
end