dusen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +8 -0
  2. data/README.md +4 -0
  3. data/Rakefile +32 -0
  4. data/dusen.gemspec +20 -0
  5. data/lib/dusen/active_record_ext.rb +29 -0
  6. data/lib/dusen/atom.rb +21 -0
  7. data/lib/dusen/description.rb +21 -0
  8. data/lib/dusen/parser.rb +32 -0
  9. data/lib/dusen/query.rb +23 -0
  10. data/lib/dusen/syntax.rb +42 -0
  11. data/lib/dusen/util.rb +34 -0
  12. data/lib/dusen/version.rb +3 -0
  13. data/lib/dusen.rb +10 -0
  14. data/spec/rails-2.3/Gemfile +9 -0
  15. data/spec/rails-2.3/Rakefile +11 -0
  16. data/spec/rails-2.3/app_root/config/boot.rb +128 -0
  17. data/spec/rails-2.3/app_root/config/database.yml +21 -0
  18. data/spec/rails-2.3/app_root/config/environment.rb +14 -0
  19. data/spec/rails-2.3/app_root/config/environments/in_memory.rb +0 -0
  20. data/spec/rails-2.3/app_root/config/environments/mysql.rb +0 -0
  21. data/spec/rails-2.3/app_root/config/environments/postgresql.rb +0 -0
  22. data/spec/rails-2.3/app_root/config/environments/sqlite.rb +0 -0
  23. data/spec/rails-2.3/app_root/config/environments/sqlite3.rb +0 -0
  24. data/spec/rails-2.3/app_root/config/preinitializer.rb +20 -0
  25. data/spec/rails-2.3/app_root/config/routes.rb +13 -0
  26. data/spec/rails-2.3/app_root/log/.gitignore +1 -0
  27. data/spec/rails-2.3/rcov.opts +2 -0
  28. data/spec/rails-2.3/spec.opts +4 -0
  29. data/spec/rails-2.3/spec_helper.rb +24 -0
  30. data/spec/rails-3.0/.rspec +2 -0
  31. data/spec/rails-3.0/Gemfile +9 -0
  32. data/spec/rails-3.0/Rakefile +11 -0
  33. data/spec/rails-3.0/app_root/.gitignore +4 -0
  34. data/spec/rails-3.0/app_root/config/application.rb +31 -0
  35. data/spec/rails-3.0/app_root/config/boot.rb +13 -0
  36. data/spec/rails-3.0/app_root/config/database.yml +4 -0
  37. data/spec/rails-3.0/app_root/config/environment.rb +5 -0
  38. data/spec/rails-3.0/app_root/config/environments/test.rb +35 -0
  39. data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/rails-3.0/app_root/config/initializers/inflections.rb +10 -0
  41. data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +5 -0
  42. data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +7 -0
  43. data/spec/rails-3.0/app_root/config/initializers/session_store.rb +8 -0
  44. data/spec/rails-3.0/app_root/config/routes.rb +3 -0
  45. data/spec/rails-3.0/app_root/lib/tasks/.gitkeep +0 -0
  46. data/spec/rails-3.0/app_root/log/.gitkeep +0 -0
  47. data/spec/rails-3.0/app_root/script/rails +6 -0
  48. data/spec/rails-3.0/rcov.opts +2 -0
  49. data/spec/rails-3.0/spec_helper.rb +21 -0
  50. data/spec/rails-3.2/.rspec +2 -0
  51. data/spec/rails-3.2/Gemfile +11 -0
  52. data/spec/rails-3.2/Rakefile +11 -0
  53. data/spec/rails-3.2/app_root/.gitignore +4 -0
  54. data/spec/rails-3.2/app_root/config/application.rb +31 -0
  55. data/spec/rails-3.2/app_root/config/boot.rb +13 -0
  56. data/spec/rails-3.2/app_root/config/database.yml +4 -0
  57. data/spec/rails-3.2/app_root/config/environment.rb +5 -0
  58. data/spec/rails-3.2/app_root/config/environments/test.rb +35 -0
  59. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +10 -0
  61. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +5 -0
  62. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +7 -0
  63. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +8 -0
  64. data/spec/rails-3.2/app_root/config/routes.rb +3 -0
  65. data/spec/rails-3.2/app_root/log/.gitignore +1 -0
  66. data/spec/rails-3.2/rcov.opts +2 -0
  67. data/spec/rails-3.2/spec_helper.rb +26 -0
  68. data/spec/shared/app_root/app/controllers/application_controller.rb +3 -0
  69. data/spec/shared/app_root/app/models/user.rb +20 -0
  70. data/spec/shared/app_root/db/gem_test.db +0 -0
  71. data/spec/shared/app_root/db/migrate/001_create_users.rb +15 -0
  72. data/spec/shared/dusen/active_record_spec.rb +45 -0
  73. metadata +151 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ doc
2
+ pkg
3
+ *.gem
4
+ .idea
5
+ app_root/log/*
6
+ Gemfile.lock
7
+
8
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Dusen - Maps Google-like queries to ActiveRecord scope chains
2
+ =============================================================
3
+
4
+ TODO
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rake'
2
+ require 'bundler/gem_tasks'
3
+
4
+ desc 'Default: Run all specs.'
5
+ task :default => 'all:spec'
6
+
7
+ namespace :all do
8
+
9
+ desc "Run specs on all spec apps"
10
+ task :spec do
11
+ for_each_directory_of('spec/**/Rakefile') do |directory|
12
+ env = "SPEC=../../#{ENV['SPEC']} " if ENV['SPEC']
13
+ system("cd #{directory} && #{env} bundle exec rake spec")
14
+ end
15
+ end
16
+
17
+ desc "Bundle all spec apps"
18
+ task :bundle do
19
+ for_each_directory_of('spec/**/Gemfile') do |directory|
20
+ system("cd #{directory} && bundle install")
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ def for_each_directory_of(path, &block)
27
+ Dir[path].sort.each do |rakefile|
28
+ directory = File.dirname(rakefile)
29
+ puts '', "\033[44m#{directory}\033[0m", ''
30
+ block.call(directory)
31
+ end
32
+ end
data/dusen.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "dusen/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'dusen'
6
+ s.version = Dusen::VERSION
7
+ s.authors = ["Henning Koch"]
8
+ s.email = 'henning.koch@makandra.de'
9
+ s.homepage = 'https://github.com/makandra/dusen'
10
+ s.summary = 'Maps Google-like queries (words, "phrases", qualified:fields) to ActiveRecord scope chains'
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,29 @@
1
+ module Dusen
2
+ module ActiveRecord
3
+
4
+ def search_syntax(&dsl)
5
+ @dusen_syntax = Dusen::Description.read_syntax(&dsl)
6
+ singleton_class.send(:define_method, :search) do |query_string|
7
+ @dusen_syntax.search(self, query_string)
8
+ end
9
+ end
10
+
11
+ def where_like(conditions)
12
+ scope = self
13
+ conditions.each do |field_or_fields, query|
14
+ fields = Array(field_or_fields).collect do |field|
15
+ Util.qualify_column_name(scope, field)
16
+ end
17
+ query_with_placeholders = fields.collect { |field| "#{field} LIKE ?" }.join(' OR ')
18
+ like_expression = Dusen::Util.like_expression(query)
19
+ bindings = [like_expression] * fields.size
20
+ conditions = [ query_with_placeholders, *bindings ]
21
+ scope = Util.append_scope_conditions(scope, conditions)
22
+ end
23
+ scope
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Base.send(:extend, Dusen::ActiveRecord)
data/lib/dusen/atom.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Dusen
2
+ class Atom
3
+
4
+ attr_reader :field, :value
5
+
6
+ def initialize(*args)
7
+ if args.length == 2
8
+ @field, @value = args
9
+ else
10
+ @field = 'text'
11
+ @value = args.first
12
+ end
13
+ @field = @field.to_s
14
+ end
15
+
16
+ def to_s
17
+ value
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Dusen
2
+ class Description
3
+
4
+ attr_reader :syntax
5
+
6
+ def initialize
7
+ @syntax = Syntax.new
8
+ end
9
+
10
+ def search_by(field, &scoper)
11
+ @syntax.learn_field(field, &scoper)
12
+ end
13
+
14
+ def self.read_syntax(&dsl)
15
+ description = new
16
+ description.instance_eval(&dsl)
17
+ description.syntax
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module Dusen
2
+ class Parser
3
+
4
+ WESTERNISH_WORD_CHARACTER = '\\w\\-\\.@_ÄÖÜäöüß' # this is wrong on so many levels
5
+ TEXT_QUERY = /(?:"([^"]+)"|([#{WESTERNISH_WORD_CHARACTER}]+))/
6
+ FIELD_QUERY = /(\w+)\:#{TEXT_QUERY}/
7
+
8
+ def self.parse(query_string)
9
+ query_string = query_string.dup # we are going to delete substrings in-place
10
+ query = Query.new
11
+ extract_field_query_atoms(query_string, query)
12
+ extract_text_query_atoms(query_string, query)
13
+ query
14
+ end
15
+
16
+ def self.extract_text_query_atoms(query_string, query)
17
+ while query_string.sub!(TEXT_QUERY, '')
18
+ value = "#{$1}#{$2}"
19
+ query << Atom.new(value)
20
+ end
21
+ end
22
+
23
+ def self.extract_field_query_atoms(query_string, query)
24
+ while query_string.sub!(FIELD_QUERY, '')
25
+ field = $1
26
+ value = "#{$2}#{$3}"
27
+ query << Atom.new(field, value)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ module Dusen
2
+ class Query
3
+
4
+ include Enumerable
5
+
6
+ def initialize
7
+ @atoms = []
8
+ end
9
+
10
+ def <<(atom)
11
+ @atoms << atom
12
+ end
13
+
14
+ def to_s
15
+ collect(&:to_s).join(" + ")
16
+ end
17
+
18
+ def each(&block)
19
+ @atoms.each(&block)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ module Dusen
2
+ class Syntax
3
+
4
+ def initialize
5
+ @scopers = {}
6
+ end
7
+
8
+ def learn_field(field, &scoper)
9
+ field = field.to_s
10
+ @scopers[field] = scoper
11
+ end
12
+
13
+ def learn_unknown_field(&unknown_scoper)
14
+ @unknown_scoper = unknown_scoper
15
+ end
16
+
17
+ def search(root_scope, query)
18
+ scope = root_scope
19
+ query = parse(query) if query.is_a?(String)
20
+ query.each do |atom|
21
+ scoper = @scopers[atom.field] || unknown_scoper
22
+ scope = scoper.call(scope, atom.value)
23
+ end
24
+ scope
25
+ end
26
+
27
+ def parse(query)
28
+ Parser.parse(query)
29
+ end
30
+
31
+ private
32
+
33
+ DEFAULT_UNKNOWN_SCOPER = lambda do |scope, *args|
34
+ scope.where('1=2')
35
+ end
36
+
37
+ def unknown_scoper
38
+ @unknown_scoper || DEFAULT_UNKNOWN_SCOPER
39
+ end
40
+
41
+ end
42
+ end
data/lib/dusen/util.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Dusen
2
+ module Util
3
+ extend self
4
+
5
+ def like_expression(phrase)
6
+ "%#{escape_for_like_query(phrase)}%"
7
+ end
8
+
9
+ def escape_for_like_query(phrase)
10
+ phrase.gsub("%", "\\%").gsub("_", "\\_")
11
+ end
12
+
13
+ def qualify_column_name(model, column_name)
14
+ column_name = column_name.to_s
15
+ unless column_name.include?('.')
16
+ quoted_table_name = model.connection.quote_table_name(model.table_name)
17
+ quoted_column_name = model.connection.quote_column_name(column_name)
18
+ column_name = "#{quoted_table_name}.#{quoted_column_name}"
19
+ end
20
+ column_name
21
+ end
22
+
23
+ def append_scope_conditions(scope, conditions)
24
+ if scope.respond_to?(:where)
25
+ # Rails 3
26
+ scope.where(conditions)
27
+ else
28
+ # Rails 2
29
+ scope.scoped(:conditions => conditions)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Dusen
2
+ VERSION = '0.1.0'
3
+ end
data/lib/dusen.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'dusen/util'
2
+ require 'dusen/atom'
3
+ require 'dusen/description'
4
+ require 'dusen/parser'
5
+ require 'dusen/query'
6
+ require 'dusen/syntax'
7
+
8
+ if defined?(ActiveRecord)
9
+ require 'dusen/active_record_ext'
10
+ end
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~>2.3'
4
+ gem 'rspec', '~>1.3'
5
+ gem 'rspec-rails', '~>1.3'
6
+ gem 'sqlite3'
7
+ gem 'ruby-debug'
8
+
9
+ gem 'dusen', :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.rb']
11
+ end
@@ -0,0 +1,128 @@
1
+ # Allow customization of the rails framework path
2
+ RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
3
+
4
+ # Don't change this file!
5
+ # Configure your app in config/environment.rb and config/environments/*.rb
6
+
7
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
8
+
9
+ module Rails
10
+ class << self
11
+ def boot!
12
+ unless booted?
13
+ preinitialize
14
+ pick_boot.run
15
+ end
16
+ end
17
+
18
+ def booted?
19
+ defined? Rails::Initializer
20
+ end
21
+
22
+ def pick_boot
23
+ (vendor_rails? ? VendorBoot : GemBoot).new
24
+ end
25
+
26
+ def vendor_rails?
27
+ File.exist?(RAILS_FRAMEWORK_ROOT)
28
+ end
29
+
30
+ def preinitialize
31
+ load(preinitializer_path) if File.exist?(preinitializer_path)
32
+ end
33
+
34
+ def preinitializer_path
35
+ "#{RAILS_ROOT}/config/preinitializer.rb"
36
+ end
37
+ end
38
+
39
+ class Boot
40
+ def run
41
+ load_initializer
42
+ Rails::Initializer.run(:set_load_path)
43
+ end
44
+ end
45
+
46
+ class VendorBoot < Boot
47
+ def load_initializer
48
+ require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
+ Rails::Initializer.run(:install_gem_spec_stubs)
50
+ end
51
+ end
52
+
53
+ class GemBoot < Boot
54
+ def load_initializer
55
+ self.class.load_rubygems
56
+ load_rails_gem
57
+ require 'initializer'
58
+ end
59
+
60
+ def load_rails_gem
61
+ if version = self.class.gem_version
62
+ gem 'rails', version
63
+ else
64
+ gem 'rails'
65
+ end
66
+ rescue Gem::LoadError => load_error
67
+ $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.)
68
+ exit 1
69
+ end
70
+
71
+ class << self
72
+ def rubygems_version
73
+ Gem::RubyGemsVersion rescue nil
74
+ end
75
+
76
+ def gem_version
77
+ if defined? RAILS_GEM_VERSION
78
+ RAILS_GEM_VERSION
79
+ elsif ENV.include?('RAILS_GEM_VERSION')
80
+ ENV['RAILS_GEM_VERSION']
81
+ else
82
+ parse_gem_version(read_environment_rb)
83
+ end
84
+ end
85
+
86
+ def load_rubygems
87
+ require 'rubygems'
88
+ min_version = '1.1.1'
89
+ unless rubygems_version >= min_version
90
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
+ exit 1
92
+ end
93
+
94
+ rescue LoadError
95
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
96
+ exit 1
97
+ end
98
+
99
+ def parse_gem_version(text)
100
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
101
+ end
102
+
103
+ private
104
+ def read_environment_rb
105
+ environment_rb = "#{RAILS_ROOT}/config/environment.rb"
106
+ environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
107
+ File.read(environment_rb)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ class Rails::Boot
114
+ def run
115
+ load_initializer
116
+
117
+ Rails::Initializer.class_eval do
118
+ def load_gems
119
+ @bundler_loaded ||= Bundler.require :default, Rails.env
120
+ end
121
+ end
122
+
123
+ Rails::Initializer.run(:set_load_path)
124
+ end
125
+ end
126
+
127
+ # All that for this:
128
+ Rails.boot!
@@ -0,0 +1,21 @@
1
+ in_memory:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ verbosity: quiet
5
+ sqlite:
6
+ adapter: sqlite
7
+ dbfile: plugin_test.sqlite.db
8
+ sqlite3:
9
+ adapter: sqlite3
10
+ dbfile: plugin_test.sqlite3.db
11
+ postgresql:
12
+ adapter: postgresql
13
+ username: postgres
14
+ password: postgres
15
+ database: plugin_test
16
+ mysql:
17
+ adapter: mysql
18
+ host: localhost
19
+ username: root
20
+ password:
21
+ database: plugin_test
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), 'boot')
2
+
3
+ Rails::Initializer.run do |config|
4
+ config.cache_classes = false
5
+ config.whiny_nils = true
6
+ config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
7
+ config.plugin_locators.unshift(
8
+ Class.new(Rails::Plugin::Locator) do
9
+ def plugins
10
+ [Rails::Plugin.new(File.expand_path('.'))]
11
+ end
12
+ end
13
+ ) unless defined?(PluginTestHelper::PluginLocator)
14
+ end
@@ -0,0 +1,20 @@
1
+ begin
2
+ require "rubygems"
3
+ require "bundler"
4
+ rescue LoadError
5
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
6
+ end
7
+
8
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
9
+ raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
10
+ "Run `gem install bundler` to upgrade."
11
+ end
12
+
13
+ begin
14
+ # Set up load paths for all bundled gems
15
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
16
+ Bundler.setup
17
+ rescue Bundler::GemNotFound
18
+ raise RuntimeError, "Bundler couldn't find some gems." +
19
+ "Did you run `bundle install`?"
20
+ end
@@ -0,0 +1,13 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resource :dashboard, :member => { :error => :post }
4
+
5
+ map.resources :songs
6
+
7
+ map.resources :users
8
+
9
+ map.resources :risks
10
+
11
+ map.resources :cakes, :member => { :custom_action => :get }
12
+
13
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,24 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../lib" )
2
+
3
+ # Set the default environment to sqlite3's in_memory database
4
+ ENV['RAILS_ENV'] ||= 'in_memory'
5
+
6
+ # Load the Rails environment and testing framework
7
+ require "#{File.dirname(__FILE__)}/app_root/config/environment"
8
+ require 'spec/rails'
9
+
10
+ # Undo changes to RAILS_ENV
11
+ silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
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
+ print "\033[30m" # dark gray text
18
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
19
+ print "\033[0m"
20
+
21
+ Spec::Runner.configure do |config|
22
+ config.use_transactional_fixtures = true
23
+ config.use_instantiated_fixtures = false
24
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~>3.0.17'
4
+ gem 'rspec'
5
+ gem 'rspec-rails'
6
+ gem 'sqlite3'
7
+ gem 'ruby-debug'
8
+
9
+ gem 'dusen', :path => '../..'
@@ -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.rb']
10
+ t.verbose = false
11
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module SpecApp
10
+ class Application < Rails::Application
11
+ config.encoding = "utf-8"
12
+
13
+ config.cache_classes = true
14
+ config.whiny_nils = true
15
+
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ config.action_dispatch.show_exceptions = false
20
+
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ config.active_support.deprecation = :stderr
26
+
27
+ config.root = File.expand_path('../..', __FILE__)
28
+
29
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/gem_test.db
4
+ verbosity: quiet
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ SpecApp::Application.initialize!