edge_rider 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rvmrc +2 -0
- data/.travis.yml +15 -0
- data/README.md +41 -0
- data/Rakefile +55 -0
- data/edge_rider.gemspec +20 -0
- data/lib/edge_rider/collect_column.rb +23 -0
- data/lib/edge_rider/collect_ids.rb +53 -0
- data/lib/edge_rider/development.rb +27 -0
- data/lib/edge_rider/to_id_query.rb +12 -0
- data/lib/edge_rider/to_sql.rb +13 -0
- data/lib/edge_rider/traverse_association.rb +40 -0
- data/lib/edge_rider/util.rb +32 -0
- data/lib/edge_rider/version.rb +3 -0
- data/lib/edge_rider.rb +10 -0
- data/spec/rails-2.3/Gemfile +13 -0
- data/spec/rails-2.3/Rakefile +11 -0
- data/spec/rails-2.3/app_root/config/boot.rb +130 -0
- data/spec/rails-2.3/app_root/config/database.yml +6 -0
- data/spec/rails-2.3/app_root/config/environment.rb +16 -0
- data/spec/rails-2.3/app_root/config/environments/test.rb +0 -0
- data/spec/rails-2.3/app_root/config/initializers/fix_missing_source_file.rb +1 -0
- data/spec/rails-2.3/app_root/config/preinitializer.rb +22 -0
- data/spec/rails-2.3/app_root/config/routes.rb +15 -0
- data/spec/rails-2.3/app_root/log/.gitignore +1 -0
- data/spec/rails-2.3/rcov.opts +2 -0
- data/spec/rails-2.3/spec/spec_helper.rb +25 -0
- data/spec/rails-2.3/spec.opts +4 -0
- data/spec/rails-3.0/.rspec +2 -0
- data/spec/rails-3.0/Gemfile +12 -0
- data/spec/rails-3.0/Rakefile +11 -0
- data/spec/rails-3.0/app_root/.gitignore +4 -0
- data/spec/rails-3.0/app_root/config/application.rb +33 -0
- data/spec/rails-3.0/app_root/config/boot.rb +15 -0
- data/spec/rails-3.0/app_root/config/database.yml +6 -0
- data/spec/rails-3.0/app_root/config/environment.rb +7 -0
- data/spec/rails-3.0/app_root/config/environments/test.rb +37 -0
- data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/rails-3.0/app_root/config/initializers/inflections.rb +12 -0
- data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +7 -0
- data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +9 -0
- data/spec/rails-3.0/app_root/config/initializers/session_store.rb +10 -0
- data/spec/rails-3.0/app_root/config/routes.rb +5 -0
- data/spec/rails-3.0/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails-3.0/app_root/log/.gitkeep +0 -0
- data/spec/rails-3.0/app_root/script/rails +6 -0
- data/spec/rails-3.0/rcov.opts +2 -0
- data/spec/rails-3.0/spec/spec_helper.rb +23 -0
- data/spec/rails-3.2/.rspec +2 -0
- data/spec/rails-3.2/Gemfile +13 -0
- data/spec/rails-3.2/Rakefile +11 -0
- data/spec/rails-3.2/app_root/.gitignore +4 -0
- data/spec/rails-3.2/app_root/config/application.rb +33 -0
- data/spec/rails-3.2/app_root/config/boot.rb +15 -0
- data/spec/rails-3.2/app_root/config/database.yml +6 -0
- data/spec/rails-3.2/app_root/config/environment.rb +7 -0
- data/spec/rails-3.2/app_root/config/environments/test.rb +37 -0
- data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/rails-3.2/app_root/config/initializers/inflections.rb +12 -0
- data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +7 -0
- data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +9 -0
- data/spec/rails-3.2/app_root/config/initializers/session_store.rb +10 -0
- data/spec/rails-3.2/app_root/config/routes.rb +5 -0
- data/spec/rails-3.2/app_root/log/.gitignore +1 -0
- data/spec/rails-3.2/rcov.opts +2 -0
- data/spec/rails-3.2/spec/spec_helper.rb +25 -0
- data/spec/shared/app_root/app/controllers/application_controller.rb +5 -0
- data/spec/shared/app_root/app/models/allow_setting_id_on_create.rb +21 -0
- data/spec/shared/app_root/app/models/forum.rb +10 -0
- data/spec/shared/app_root/app/models/post.rb +9 -0
- data/spec/shared/app_root/app/models/profile.rb +8 -0
- data/spec/shared/app_root/app/models/topic.rb +12 -0
- data/spec/shared/app_root/app/models/user.rb +12 -0
- data/spec/shared/app_root/config/database.sample.yml +6 -0
- data/spec/shared/app_root/config/database.travis_ci.yml +6 -0
- data/spec/shared/app_root/db/migrate/001_create_test_tables.rb +45 -0
- data/spec/shared/spec/edge_rider/collect_column_spec.rb +50 -0
- data/spec/shared/spec/edge_rider/collect_ids_spec.rb +73 -0
- data/spec/shared/spec/edge_rider/to_id_query_spec.rb +29 -0
- data/spec/shared/spec/edge_rider/to_sql_spec.rb +14 -0
- data/spec/shared/spec/edge_rider/traverse_association_spec.rb +133 -0
- data/spec/shared/spec/edge_rider/util_spec.rb +5 -0
- metadata +159 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/.travis.yml
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Edge Rider [![Build Status](https://secure.travis-ci.org/makandra/edge_rider.png?branch=master)](https://travis-ci.org/makandra/edge_rider)
|
2
|
+
====================================
|
3
|
+
|
4
|
+
Power tools for Active Record relations (scopes)
|
5
|
+
-------------------------------------------------
|
6
|
+
|
7
|
+
TODO: Write README
|
8
|
+
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
In your `Gemfile` say:
|
14
|
+
|
15
|
+
gem 'edge_rider'
|
16
|
+
|
17
|
+
Now run `bundle install` and restart your server.
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
Development
|
22
|
+
-----------
|
23
|
+
|
24
|
+
- Test applications for various Rails versions lives in `spec`.
|
25
|
+
- You need to create a MySQL database and put credentials into `spec/shared/app_root/config/database.yml`.
|
26
|
+
- You can bundle all test applications by saying `bundle exec rake all:bundle`
|
27
|
+
- You can run specs from the project root by saying `bundle exec rake all:spec`.
|
28
|
+
|
29
|
+
If you would like to contribute:
|
30
|
+
|
31
|
+
- Fork the repository.
|
32
|
+
- Push your changes **with passing specs**.
|
33
|
+
- Send me a pull request.
|
34
|
+
|
35
|
+
I'm very eager to keep this gem leightweight and on topic. If you're unsure whether a change would make it into the gem, [talk to me beforehand](mailto:henning.koch@makandra.de).
|
36
|
+
|
37
|
+
|
38
|
+
Credits
|
39
|
+
-------
|
40
|
+
|
41
|
+
Henning Koch from [makandra](http://makandra.com/)
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
desc 'Default: Run all specs.'
|
5
|
+
task :default => 'all:spec'
|
6
|
+
|
7
|
+
namespace :travis_ci do
|
8
|
+
|
9
|
+
desc 'Things to do before Travis CI begins'
|
10
|
+
task :prepare do
|
11
|
+
Rake::Task['travis_ci:create_database'].invoke &&
|
12
|
+
Rake::Task['travis_ci:create_database_yml'].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Creates a test database'
|
16
|
+
task :create_database do
|
17
|
+
system("mysql -e 'create database edge_rider_test;'")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Creates a database.yml'
|
21
|
+
task :create_database_yml do
|
22
|
+
config_dir = "spec/shared/app_root/config"
|
23
|
+
system("cp #{config_dir}/database.travis_ci.yml #{config_dir}/database.yml")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :all do
|
29
|
+
|
30
|
+
desc "Run specs on all spec apps"
|
31
|
+
task :spec do
|
32
|
+
success = true
|
33
|
+
for_each_directory_of('spec/**/Rakefile') do |directory|
|
34
|
+
env = "SPEC=../../#{ENV['SPEC']} " if ENV['SPEC']
|
35
|
+
success &= system("cd #{directory} && #{env} bundle exec rake spec")
|
36
|
+
end
|
37
|
+
fail "Tests failed" unless success
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Bundle all spec apps"
|
41
|
+
task :bundle do
|
42
|
+
for_each_directory_of('spec/**/Gemfile') do |directory|
|
43
|
+
system("cd #{directory} && rm -f Gemfile.lock && bundle install")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def for_each_directory_of(path, &block)
|
50
|
+
Dir[path].sort.each do |rakefile|
|
51
|
+
directory = File.dirname(rakefile)
|
52
|
+
puts '', "\033[44m#{directory}\033[0m", ''
|
53
|
+
block.call(directory)
|
54
|
+
end
|
55
|
+
end
|
data/edge_rider.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "edge_rider/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'edge_rider'
|
6
|
+
s.version = EdgeRider::VERSION
|
7
|
+
s.authors = ["Henning Koch"]
|
8
|
+
s.email = 'henning.koch@makandra.de'
|
9
|
+
s.homepage = 'https://github.com/makandra/edge_rider'
|
10
|
+
s.summary = 'Power tools for ActiveRecord relations (scopes)'
|
11
|
+
s.description = s.summary
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency('rails')
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EdgeRider
|
2
|
+
module CollectColumn
|
3
|
+
|
4
|
+
def collect_column(column_name, find_options = {})
|
5
|
+
distinct = find_options.delete(:distinct)
|
6
|
+
qualified_column_name = EdgeRider::Util.qualify_column_name(self, column_name)
|
7
|
+
if respond_to?(:pluck) # Rails 3.2+
|
8
|
+
scope = scoped({})
|
9
|
+
scope = scope.uniq if distinct
|
10
|
+
scope.pluck(qualified_column_name)
|
11
|
+
else # Rails 2
|
12
|
+
select = distinct ? "DISTINCT #{qualified_column_name}" : qualified_column_name
|
13
|
+
query = scoped(find_options.merge(:select => select)).to_sql
|
14
|
+
raw_values = connection.select_values(query)
|
15
|
+
column = columns_hash[column_name.to_s] or raise "Could not retrieve column information: #{column_name}"
|
16
|
+
raw_values.collect { |value| column.type_cast(value) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::Base.extend(self)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module EdgeRider
|
2
|
+
module CollectIds
|
3
|
+
|
4
|
+
class Uncollectable < StandardError; end
|
5
|
+
|
6
|
+
module Array
|
7
|
+
|
8
|
+
def collect_ids
|
9
|
+
collect do |obj|
|
10
|
+
case obj
|
11
|
+
when Fixnum then obj
|
12
|
+
when ActiveRecord::Base then obj.id
|
13
|
+
else raise Uncollectable, "Cannot collect an id from #{obj.inspect}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
::Array.send(:include, Array)
|
21
|
+
|
22
|
+
module ActiveRecordValue
|
23
|
+
|
24
|
+
def collect_ids
|
25
|
+
[id]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
::ActiveRecord::Base.send(:include, ActiveRecordValue)
|
31
|
+
|
32
|
+
module ActiveRecordScope
|
33
|
+
|
34
|
+
def collect_ids
|
35
|
+
collect_column(:id)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
::ActiveRecord::Base.send(:extend, ActiveRecordScope)
|
41
|
+
|
42
|
+
module Fixnum
|
43
|
+
|
44
|
+
def collect_ids
|
45
|
+
[self]
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
::Fixnum.send(:include, Fixnum)
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module EdgeRider
|
2
|
+
module Development
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def drop_all_tables
|
6
|
+
connection = ::ActiveRecord::Base.connection
|
7
|
+
connection.tables.each do |table|
|
8
|
+
connection.drop_table table
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def migrate_test_database
|
13
|
+
print "\033[30m" # dark gray text
|
14
|
+
drop_all_tables
|
15
|
+
::ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
16
|
+
print "\033[0m"
|
17
|
+
end
|
18
|
+
|
19
|
+
def selects_star_with_conditions_pattern(table, conditions)
|
20
|
+
table = Regexp.quote(table)
|
21
|
+
conditions = Regexp.quote(conditions) unless conditions.is_a?(Regexp)
|
22
|
+
/\ASELECT (`#{table}`\.)?\* FROM `#{table}`\s+WHERE \(?#{conditions}\)?\s*\z/
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module EdgeRider
|
2
|
+
module TraverseAssociation
|
3
|
+
|
4
|
+
class UnsupportedAssociation < StandardError; end
|
5
|
+
class UnknownAssociation < StandardError; end
|
6
|
+
|
7
|
+
def traverse_association(*associations)
|
8
|
+
|
9
|
+
scope = scoped({})
|
10
|
+
|
11
|
+
associations.each_with_index do |association, index|
|
12
|
+
|
13
|
+
reflection = scope.reflect_on_association(association) or raise UnknownAssociation, "Could not find association: #{self.name}##{association}"
|
14
|
+
foreign_key = reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name
|
15
|
+
|
16
|
+
raise NotImplementedError if reflection.options[:conditions].present?
|
17
|
+
|
18
|
+
if reflection.macro == :belongs_to
|
19
|
+
ids = scope.collect_column(foreign_key, :distinct => true)
|
20
|
+
scope = EdgeRider::Util.exclusive_query(reflection.klass, :id => ids)
|
21
|
+
elsif reflection.macro == :has_many || reflection.macro == :has_one
|
22
|
+
if reflection.through_reflection
|
23
|
+
scope = scope.traverse_association(reflection.through_reflection.name, reflection.source_reflection.name)
|
24
|
+
else
|
25
|
+
ids = scope.collect_ids
|
26
|
+
scope = EdgeRider::Util.exclusive_query(reflection.klass, foreign_key => ids)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
raise UnsupportedAssociation, "Unsupport association type: #{reflection.macro}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
scope
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
ActiveRecord::Base.extend(self)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EdgeRider
|
4
|
+
module Util
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def qualify_column_name(model, column_name)
|
8
|
+
column_name = column_name.to_s
|
9
|
+
unless column_name.include?('.')
|
10
|
+
quoted_table_name = model.connection.quote_table_name(model.table_name)
|
11
|
+
quoted_column_name = model.connection.quote_column_name(column_name)
|
12
|
+
column_name = "#{quoted_table_name}.#{quoted_column_name}"
|
13
|
+
end
|
14
|
+
column_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def exclusive_query(model, conditions)
|
18
|
+
if Rails.version < '3'
|
19
|
+
model.send(:with_exclusive_scope) do
|
20
|
+
model.scoped(:conditions => conditions)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
model.unscoped.where(conditions)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def scope?(object)
|
28
|
+
object.respond_to?(:scoped)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/edge_rider.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'edge_rider/version'
|
4
|
+
require 'edge_rider/util'
|
5
|
+
|
6
|
+
require 'edge_rider/collect_column'
|
7
|
+
require 'edge_rider/collect_ids'
|
8
|
+
require 'edge_rider/traverse_association'
|
9
|
+
require 'edge_rider/to_id_query'
|
10
|
+
require 'edge_rider/to_sql'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem 'rails', '~>2.3'
|
4
|
+
gem 'rspec', '~>1.3'
|
5
|
+
gem 'rspec-rails', '~>1.3'
|
6
|
+
gem 'mysql2', '~>0.2.0'
|
7
|
+
gem 'ruby-debug', :platforms => :ruby_18
|
8
|
+
gem 'test-unit', '~>1.2', :platforms => :ruby_19
|
9
|
+
gem 'database_cleaner'
|
10
|
+
gem 'andand'
|
11
|
+
gem 'has_defaults'
|
12
|
+
|
13
|
+
gem 'edge_rider', :path => '../..'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc 'Default: Run all specs for a specific rails version.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs for a specific rails version"
|
8
|
+
Spec::Rake::SpecTask.new() do |t|
|
9
|
+
t.spec_opts = ['--options', "\"spec.opts\""]
|
10
|
+
t.spec_files = defined?(SPEC) ? SPEC : FileList['**/*_spec.rb', '../shared/spec/**/*_spec.rb']
|
11
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Allow customization of the rails framework path
|
4
|
+
RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
|
5
|
+
|
6
|
+
# Don't change this file!
|
7
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
8
|
+
|
9
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
10
|
+
|
11
|
+
module Rails
|
12
|
+
class << self
|
13
|
+
def boot!
|
14
|
+
unless booted?
|
15
|
+
preinitialize
|
16
|
+
pick_boot.run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def booted?
|
21
|
+
defined? Rails::Initializer
|
22
|
+
end
|
23
|
+
|
24
|
+
def pick_boot
|
25
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
26
|
+
end
|
27
|
+
|
28
|
+
def vendor_rails?
|
29
|
+
File.exist?(RAILS_FRAMEWORK_ROOT)
|
30
|
+
end
|
31
|
+
|
32
|
+
def preinitialize
|
33
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def preinitializer_path
|
37
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Boot
|
42
|
+
def run
|
43
|
+
load_initializer
|
44
|
+
Rails::Initializer.run(:set_load_path)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class VendorBoot < Boot
|
49
|
+
def load_initializer
|
50
|
+
require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
|
51
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class GemBoot < Boot
|
56
|
+
def load_initializer
|
57
|
+
self.class.load_rubygems
|
58
|
+
load_rails_gem
|
59
|
+
require 'initializer'
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_rails_gem
|
63
|
+
if version = self.class.gem_version
|
64
|
+
gem 'rails', version
|
65
|
+
else
|
66
|
+
gem 'rails'
|
67
|
+
end
|
68
|
+
rescue Gem::LoadError => load_error
|
69
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
|
73
|
+
class << self
|
74
|
+
def rubygems_version
|
75
|
+
Gem::RubyGemsVersion rescue nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def gem_version
|
79
|
+
if defined? RAILS_GEM_VERSION
|
80
|
+
RAILS_GEM_VERSION
|
81
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
82
|
+
ENV['RAILS_GEM_VERSION']
|
83
|
+
else
|
84
|
+
parse_gem_version(read_environment_rb)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def load_rubygems
|
89
|
+
require 'rubygems'
|
90
|
+
min_version = '1.1.1'
|
91
|
+
unless rubygems_version >= min_version
|
92
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
rescue LoadError
|
97
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse_gem_version(text)
|
102
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
def read_environment_rb
|
107
|
+
environment_rb = "#{RAILS_ROOT}/config/environment.rb"
|
108
|
+
environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
|
109
|
+
File.read(environment_rb)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class Rails::Boot
|
116
|
+
def run
|
117
|
+
load_initializer
|
118
|
+
|
119
|
+
Rails::Initializer.class_eval do
|
120
|
+
def load_gems
|
121
|
+
@bundler_loaded ||= Bundler.require :default, Rails.env
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
Rails::Initializer.run(:set_load_path)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# All that for this:
|
130
|
+
Rails.boot!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
4
|
+
|
5
|
+
Rails::Initializer.run do |config|
|
6
|
+
config.cache_classes = false
|
7
|
+
config.whiny_nils = true
|
8
|
+
config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
|
9
|
+
config.plugin_locators.unshift(
|
10
|
+
Class.new(Rails::Plugin::Locator) do
|
11
|
+
def plugins
|
12
|
+
[Rails::Plugin.new(File.expand_path('.'))]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
) unless defined?(PluginTestHelper::PluginLocator)
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
MissingSourceFile::REGEXPS.push([/^cannot load such file -- (.+)$/i, 1])
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
rescue LoadError
|
7
|
+
raise "Could not load the bundler gem. Install it with `gem install bundler`."
|
8
|
+
end
|
9
|
+
|
10
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
|
11
|
+
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
|
12
|
+
"Run `gem install bundler` to upgrade."
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
# Set up load paths for all bundled gems
|
17
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
|
18
|
+
Bundler.setup
|
19
|
+
rescue Bundler::GemNotFound
|
20
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
21
|
+
"Did you run `bundle install`?"
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ActionController::Routing::Routes.draw do |map|
|
4
|
+
|
5
|
+
map.resource :dashboard, :member => { :error => :post }
|
6
|
+
|
7
|
+
map.resources :songs
|
8
|
+
|
9
|
+
map.resources :users
|
10
|
+
|
11
|
+
map.resources :risks
|
12
|
+
|
13
|
+
map.resources :cakes, :member => { :custom_action => :get }
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$: << File.join(File.dirname(__FILE__), "/../../lib" )
|
4
|
+
|
5
|
+
ENV['RAILS_ENV'] = 'test'
|
6
|
+
|
7
|
+
# Load the Rails environment and testing framework
|
8
|
+
require "#{File.dirname(__FILE__)}/../app_root/config/environment"
|
9
|
+
require 'spec/rails'
|
10
|
+
require 'edge_rider/development'
|
11
|
+
DatabaseCleaner.strategy = :truncation
|
12
|
+
|
13
|
+
# Requires supporting files with custom matchers and macros, etc in ./support/ and its subdirectories.
|
14
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
15
|
+
|
16
|
+
# Run the migrations
|
17
|
+
EdgeRider::Development.migrate_test_database
|
18
|
+
|
19
|
+
Spec::Runner.configure do |config|
|
20
|
+
config.use_transactional_fixtures = false
|
21
|
+
config.use_instantiated_fixtures = false
|
22
|
+
config.before(:each) do
|
23
|
+
DatabaseCleaner.clean
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
desc 'Default: Run all specs for a specific rails version.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs for a specific rails version"
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
t.pattern = defined?(SPEC) ? SPEC : ['**/*_spec.rb', '../shared/spec/**/*_spec.rb']
|
10
|
+
t.verbose = false
|
11
|
+
end
|