edge_rider 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +10 -0
  2. data/.rvmrc +2 -0
  3. data/.travis.yml +15 -0
  4. data/README.md +41 -0
  5. data/Rakefile +55 -0
  6. data/edge_rider.gemspec +20 -0
  7. data/lib/edge_rider/collect_column.rb +23 -0
  8. data/lib/edge_rider/collect_ids.rb +53 -0
  9. data/lib/edge_rider/development.rb +27 -0
  10. data/lib/edge_rider/to_id_query.rb +12 -0
  11. data/lib/edge_rider/to_sql.rb +13 -0
  12. data/lib/edge_rider/traverse_association.rb +40 -0
  13. data/lib/edge_rider/util.rb +32 -0
  14. data/lib/edge_rider/version.rb +3 -0
  15. data/lib/edge_rider.rb +10 -0
  16. data/spec/rails-2.3/Gemfile +13 -0
  17. data/spec/rails-2.3/Rakefile +11 -0
  18. data/spec/rails-2.3/app_root/config/boot.rb +130 -0
  19. data/spec/rails-2.3/app_root/config/database.yml +6 -0
  20. data/spec/rails-2.3/app_root/config/environment.rb +16 -0
  21. data/spec/rails-2.3/app_root/config/environments/test.rb +0 -0
  22. data/spec/rails-2.3/app_root/config/initializers/fix_missing_source_file.rb +1 -0
  23. data/spec/rails-2.3/app_root/config/preinitializer.rb +22 -0
  24. data/spec/rails-2.3/app_root/config/routes.rb +15 -0
  25. data/spec/rails-2.3/app_root/log/.gitignore +1 -0
  26. data/spec/rails-2.3/rcov.opts +2 -0
  27. data/spec/rails-2.3/spec/spec_helper.rb +25 -0
  28. data/spec/rails-2.3/spec.opts +4 -0
  29. data/spec/rails-3.0/.rspec +2 -0
  30. data/spec/rails-3.0/Gemfile +12 -0
  31. data/spec/rails-3.0/Rakefile +11 -0
  32. data/spec/rails-3.0/app_root/.gitignore +4 -0
  33. data/spec/rails-3.0/app_root/config/application.rb +33 -0
  34. data/spec/rails-3.0/app_root/config/boot.rb +15 -0
  35. data/spec/rails-3.0/app_root/config/database.yml +6 -0
  36. data/spec/rails-3.0/app_root/config/environment.rb +7 -0
  37. data/spec/rails-3.0/app_root/config/environments/test.rb +37 -0
  38. data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +9 -0
  39. data/spec/rails-3.0/app_root/config/initializers/inflections.rb +12 -0
  40. data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +7 -0
  41. data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +9 -0
  42. data/spec/rails-3.0/app_root/config/initializers/session_store.rb +10 -0
  43. data/spec/rails-3.0/app_root/config/routes.rb +5 -0
  44. data/spec/rails-3.0/app_root/lib/tasks/.gitkeep +0 -0
  45. data/spec/rails-3.0/app_root/log/.gitkeep +0 -0
  46. data/spec/rails-3.0/app_root/script/rails +6 -0
  47. data/spec/rails-3.0/rcov.opts +2 -0
  48. data/spec/rails-3.0/spec/spec_helper.rb +23 -0
  49. data/spec/rails-3.2/.rspec +2 -0
  50. data/spec/rails-3.2/Gemfile +13 -0
  51. data/spec/rails-3.2/Rakefile +11 -0
  52. data/spec/rails-3.2/app_root/.gitignore +4 -0
  53. data/spec/rails-3.2/app_root/config/application.rb +33 -0
  54. data/spec/rails-3.2/app_root/config/boot.rb +15 -0
  55. data/spec/rails-3.2/app_root/config/database.yml +6 -0
  56. data/spec/rails-3.2/app_root/config/environment.rb +7 -0
  57. data/spec/rails-3.2/app_root/config/environments/test.rb +37 -0
  58. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +9 -0
  59. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +12 -0
  60. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +7 -0
  61. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +9 -0
  62. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +10 -0
  63. data/spec/rails-3.2/app_root/config/routes.rb +5 -0
  64. data/spec/rails-3.2/app_root/log/.gitignore +1 -0
  65. data/spec/rails-3.2/rcov.opts +2 -0
  66. data/spec/rails-3.2/spec/spec_helper.rb +25 -0
  67. data/spec/shared/app_root/app/controllers/application_controller.rb +5 -0
  68. data/spec/shared/app_root/app/models/allow_setting_id_on_create.rb +21 -0
  69. data/spec/shared/app_root/app/models/forum.rb +10 -0
  70. data/spec/shared/app_root/app/models/post.rb +9 -0
  71. data/spec/shared/app_root/app/models/profile.rb +8 -0
  72. data/spec/shared/app_root/app/models/topic.rb +12 -0
  73. data/spec/shared/app_root/app/models/user.rb +12 -0
  74. data/spec/shared/app_root/config/database.sample.yml +6 -0
  75. data/spec/shared/app_root/config/database.travis_ci.yml +6 -0
  76. data/spec/shared/app_root/db/migrate/001_create_test_tables.rb +45 -0
  77. data/spec/shared/spec/edge_rider/collect_column_spec.rb +50 -0
  78. data/spec/shared/spec/edge_rider/collect_ids_spec.rb +73 -0
  79. data/spec/shared/spec/edge_rider/to_id_query_spec.rb +29 -0
  80. data/spec/shared/spec/edge_rider/to_sql_spec.rb +14 -0
  81. data/spec/shared/spec/edge_rider/traverse_association_spec.rb +133 -0
  82. data/spec/shared/spec/edge_rider/util_spec.rb +5 -0
  83. metadata +159 -0
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../boot', __FILE__)
4
+
5
+ require 'rails/all'
6
+
7
+ # If you have a Gemfile, require the gems listed there, including any gems
8
+ # you've limited to :test, :development, or :production.
9
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
10
+
11
+ module SpecApp
12
+ class Application < Rails::Application
13
+ config.encoding = "utf-8"
14
+
15
+ config.cache_classes = true
16
+ config.whiny_nils = true
17
+
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ config.action_dispatch.show_exceptions = false
22
+
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ config.action_mailer.delivery_method = :test
26
+
27
+ config.active_support.deprecation = :stderr
28
+
29
+ config.root = File.expand_path('../..', __FILE__)
30
+
31
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ # Set up gems listed in the Gemfile.
6
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
7
+ begin
8
+ ENV['BUNDLE_GEMFILE'] = gemfile
9
+ require 'bundler'
10
+ Bundler.setup
11
+ rescue Bundler::GemNotFound => e
12
+ STDERR.puts e.message
13
+ STDERR.puts "Try running `bundle install`."
14
+ exit!
15
+ end if File.exist?(gemfile)
@@ -0,0 +1,6 @@
1
+ test:
2
+ adapter: mysql2
3
+ host: localhost
4
+ username: root
5
+ password: junior
6
+ database: edge_rider_test
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ # Load the rails application
4
+ require File.expand_path('../application', __FILE__)
5
+
6
+ # Initialize the rails application
7
+ SpecApp::Application.initialize!
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ SpecApp::Application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb
5
+
6
+ # The test environment is used exclusively to run your application's
7
+ # test suite. You never need to work with it otherwise. Remember that
8
+ # your test database is "scratch space" for the test suite and is wiped
9
+ # and recreated between test runs. Don't rely on the data there!
10
+ config.cache_classes = true
11
+
12
+ # Log error messages when you accidentally call methods on nil.
13
+ config.whiny_nils = true
14
+
15
+ # Show full error reports and disable caching
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ # Raise exceptions instead of rendering exception templates
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ # Disable request forgery protection in test environment
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ # Tell Action Mailer not to deliver emails to the real world.
26
+ # The :test delivery method accumulates sent emails in the
27
+ # ActionMailer::Base.deliveries array.
28
+ config.action_mailer.delivery_method = :test
29
+
30
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
31
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
32
+ # like if you have constraints or database-specific column types
33
+ # config.active_record.schema_format = :sql
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
6
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
7
+
8
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
9
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new inflection rules using the following format
6
+ # (all these examples are active by default):
7
+ # ActiveSupport::Inflector.inflections do |inflect|
8
+ # inflect.plural /^(ox)$/i, '\1en'
9
+ # inflect.singular /^(ox)en/i, '\1'
10
+ # inflect.irregular 'person', 'people'
11
+ # inflect.uncountable %w( fish sheep )
12
+ # end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new mime types for use in respond_to blocks:
6
+ # Mime::Type.register "text/richtext", :rtf
7
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Your secret key for verifying the integrity of signed cookies.
6
+ # If you change this key, all old signed cookies will become invalid!
7
+ # Make sure the secret is at least 30 characters and all random,
8
+ # no regular words or you'll be exposed to dictionary attacks.
9
+ SpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ SpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
6
+
7
+ # Use the database for sessions instead of the cookie-based default,
8
+ # which shouldn't be used to store highly confidential information
9
+ # (create the session table with "rails generate session_migration")
10
+ # HasDefaultSpecApp::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ SpecApp::Application.routes.draw do
4
+ match ':controller(/:action(/:id(.:format)))'
5
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
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,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ $: << File.join(File.dirname(__FILE__), "/../../lib" )
4
+
5
+ ENV['RAILS_ENV'] = 'test'
6
+ ENV['RAILS_ROOT'] = 'app_root'
7
+
8
+ # Load the Rails environment and testing framework
9
+ require "#{File.dirname(__FILE__)}/../app_root/config/environment"
10
+ require 'rspec/rails'
11
+ require 'edge_rider/development'
12
+ DatabaseCleaner.strategy = :truncation
13
+
14
+ # Run the migrations
15
+ EdgeRider::Development.migrate_test_database
16
+
17
+ RSpec.configure do |config|
18
+ config.use_transactional_fixtures = false
19
+ config.use_instantiated_fixtures = false
20
+ config.before(:each) do
21
+ DatabaseCleaner.clean
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~>3.2.0'
4
+ gem 'rspec'
5
+ gem 'rspec-rails'
6
+ gem 'mysql2'
7
+ gem 'rspec_candy'
8
+ gem 'ruby-debug', :platforms => :ruby_18
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 '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
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../boot', __FILE__)
4
+
5
+ require 'rails/all'
6
+
7
+ # If you have a Gemfile, require the gems listed there, including any gems
8
+ # you've limited to :test, :development, or :production.
9
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
10
+
11
+ module SpecApp
12
+ class Application < Rails::Application
13
+ config.encoding = "utf-8"
14
+
15
+ config.cache_classes = true
16
+ config.whiny_nils = true
17
+
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ config.action_dispatch.show_exceptions = false
22
+
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ config.action_mailer.delivery_method = :test
26
+
27
+ config.active_support.deprecation = :stderr
28
+
29
+ config.root = File.expand_path('../..', __FILE__)
30
+
31
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ # Set up gems listed in the Gemfile.
6
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
7
+ begin
8
+ ENV['BUNDLE_GEMFILE'] = gemfile
9
+ require 'bundler'
10
+ Bundler.setup
11
+ rescue Bundler::GemNotFound => e
12
+ STDERR.puts e.message
13
+ STDERR.puts "Try running `bundle install`."
14
+ exit!
15
+ end if File.exist?(gemfile)
@@ -0,0 +1,6 @@
1
+ test:
2
+ adapter: mysql2
3
+ host: localhost
4
+ username: root
5
+ password: junior
6
+ database: edge_rider_test
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ # Load the rails application
4
+ require File.expand_path('../application', __FILE__)
5
+
6
+ # Initialize the rails application
7
+ SpecApp::Application.initialize!
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ SpecApp::Application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb
5
+
6
+ # The test environment is used exclusively to run your application's
7
+ # test suite. You never need to work with it otherwise. Remember that
8
+ # your test database is "scratch space" for the test suite and is wiped
9
+ # and recreated between test runs. Don't rely on the data there!
10
+ config.cache_classes = true
11
+
12
+ # Log error messages when you accidentally call methods on nil.
13
+ config.whiny_nils = true
14
+
15
+ # Show full error reports and disable caching
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ # Raise exceptions instead of rendering exception templates
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ # Disable request forgery protection in test environment
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ # Tell Action Mailer not to deliver emails to the real world.
26
+ # The :test delivery method accumulates sent emails in the
27
+ # ActionMailer::Base.deliveries array.
28
+ config.action_mailer.delivery_method = :test
29
+
30
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
31
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
32
+ # like if you have constraints or database-specific column types
33
+ # config.active_record.schema_format = :sql
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
6
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
7
+
8
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
9
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new inflection rules using the following format
6
+ # (all these examples are active by default):
7
+ # ActiveSupport::Inflector.inflections do |inflect|
8
+ # inflect.plural /^(ox)$/i, '\1en'
9
+ # inflect.singular /^(ox)en/i, '\1'
10
+ # inflect.irregular 'person', 'people'
11
+ # inflect.uncountable %w( fish sheep )
12
+ # end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new mime types for use in respond_to blocks:
6
+ # Mime::Type.register "text/richtext", :rtf
7
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Your secret key for verifying the integrity of signed cookies.
6
+ # If you change this key, all old signed cookies will become invalid!
7
+ # Make sure the secret is at least 30 characters and all random,
8
+ # no regular words or you'll be exposed to dictionary attacks.
9
+ SpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ SpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
6
+
7
+ # Use the database for sessions instead of the cookie-based default,
8
+ # which shouldn't be used to store highly confidential information
9
+ # (create the session table with "rails generate session_migration")
10
+ # HasDefaultSpecApp::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ SpecApp::Application.routes.draw do
4
+ match ':controller(/:action(/:id(.:format)))'
5
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ $: << File.join(File.dirname(__FILE__), "/../../lib" )
4
+
5
+ ENV['RAILS_ENV'] = 'test'
6
+ ENV['RAILS_ROOT'] = 'app_root'
7
+
8
+ # Load the Rails environment and testing framework
9
+ require "#{File.dirname(__FILE__)}/../app_root/config/environment"
10
+ require 'rspec/rails'
11
+ require 'edge_rider/development'
12
+ DatabaseCleaner.strategy = :truncation
13
+
14
+ # Dir["#{File.dirname(__FILE__)}/../../shared/spec/shared_examples"].each {|f| require f}
15
+
16
+ # Run the migrations
17
+ EdgeRider::Development.migrate_test_database
18
+
19
+ RSpec.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,5 @@
1
+ # encoding: utf-8
2
+
3
+ class ApplicationController < ActionController::Base
4
+
5
+ end
@@ -0,0 +1,21 @@
1
+ # Since our specs are mostly about working with IDs, this module can be
2
+ # included in an ActiveRecord model class to allow setting the :id attribute
3
+ # on create. This is forbidden by default.
4
+ # http://stackoverflow.com/questions/431617/overriding-id-on-create-in-activerecord
5
+ module AllowSettingIdOnCreate
6
+
7
+ module RemoveIdFromProtectedAttributes
8
+ def attributes_protected_by_default
9
+ super - ['id']
10
+ end
11
+ end
12
+
13
+ def self.included(base)
14
+ if Rails.version < '3' # Rails 2 has this as an instance method
15
+ base.send(:include, RemoveIdFromProtectedAttributes)
16
+ else # Rails 3 has this as a class method
17
+ base.send(:extend, RemoveIdFromProtectedAttributes)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,10 @@
1
+ class Forum < ActiveRecord::Base
2
+ include AllowSettingIdOnCreate
3
+
4
+ has_many :topics
5
+ has_many :active_topics, :conditions => { :trashed => false }, :class_name => 'Topic'
6
+ has_many :posts, :through => :topics
7
+
8
+ has_defaults :trashed => false
9
+
10
+ end
@@ -0,0 +1,9 @@
1
+ class Post < ActiveRecord::Base
2
+ include AllowSettingIdOnCreate
3
+
4
+ belongs_to :topic
5
+ belongs_to :author, :class_name => 'User'
6
+
7
+ has_defaults :trashed => false
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ class Profile < ActiveRecord::Base
2
+ include AllowSettingIdOnCreate
3
+
4
+ belongs_to :user
5
+
6
+ has_defaults :trashed => false
7
+
8
+ end
@@ -0,0 +1,12 @@
1
+ class Topic < ActiveRecord::Base
2
+ include AllowSettingIdOnCreate
3
+
4
+ belongs_to :forum
5
+ belongs_to :active_forum, :conditions => { :trashed => false }, :class_name => 'Forum'
6
+ has_many :posts
7
+ belongs_to :author, :class_name => 'User'
8
+ has_many :post_authors, :through => :posts
9
+
10
+ has_defaults :trashed => false
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ class User < ActiveRecord::Base
2
+ include AllowSettingIdOnCreate
3
+
4
+ has_many :posts
5
+ has_many :topics
6
+
7
+ has_one :profile
8
+ has_one :active_profile, :conditions => { :trashed => false }, :class_name => 'Profile'
9
+
10
+ has_defaults :trashed => false
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ test:
2
+ adapter: mysql2
3
+ host: localhost
4
+ username: root
5
+ password: secret
6
+ database: edge_rider_test
@@ -0,0 +1,6 @@
1
+ test:
2
+ adapter: mysql2
3
+ host: localhost
4
+ username: root
5
+ password:
6
+ database: edge_rider_test
@@ -0,0 +1,45 @@
1
+ class CreateTestTables < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ create_table :forums do |t|
6
+ t.string :name
7
+ t.boolean :trashed
8
+ end
9
+
10
+ create_table :topics do |t|
11
+ t.string :subject
12
+ t.references :forum
13
+ t.references :author
14
+ t.boolean :trashed
15
+ end
16
+
17
+ create_table :posts do |t|
18
+ t.text :body
19
+ t.references :topic
20
+ t.references :author
21
+ t.boolean :trashed
22
+ t.timestamps
23
+ end
24
+
25
+ create_table :users do |t|
26
+ t.string :email
27
+ t.boolean :trashed
28
+ end
29
+
30
+ create_table :profiles do |t|
31
+ t.references :user
32
+ t.text :hobbies
33
+ t.boolean :trashed
34
+ end
35
+
36
+ end
37
+
38
+ def self.down
39
+ drop_table :forums
40
+ drop_table :topics
41
+ drop_table :posts
42
+ drop_table :users
43
+ end
44
+
45
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe EdgeRider::CollectColumn do
4
+
5
+ describe '#collect_column' do
6
+
7
+ it 'should collect the given value from a scope' do
8
+ Forum.create!(:id => 1, :name => 'Name 1')
9
+ Forum.create!(:id => 2, :name => 'Name 2')
10
+ Forum.create!(:id => 3, :name => 'Name 3')
11
+ scope = Forum.scoped(:conditions => { :id => [2, 3] })
12
+ scope.collect_column(:name).should =~ ['Name 2', 'Name 3']
13
+ end
14
+
15
+ it 'should collect the given value from an ActiveRecord class' do
16
+ Forum.create!(:id => 1, :name => 'Name 1')
17
+ Forum.create!(:id => 2, :name => 'Name 2')
18
+ Forum.collect_column(:name).should =~ ['Name 1', 'Name 2']
19
+ end
20
+
21
+ it 'should cast the collected value to their equivalent Ruby type' do
22
+ Post.create!
23
+ Post.collect_column(:created_at).first.should be_a(Time)
24
+ end
25
+
26
+ it 'should not instantiate ActiveRecord objects when collecting values' do
27
+ Forum.create!(:name => 'Name')
28
+ Forum.should_not_receive(:new)
29
+ Forum.collect_column(:name).should == ['Name']
30
+ end
31
+
32
+ it 'should qualify the column name to resolve any ambiguities' do
33
+ expect { Topic.scoped(:joins => :forum).collect_column(:id) }.to_not raise_error
34
+ end
35
+
36
+ context 'with :distinct option' do
37
+
38
+ it 'should return unique values' do
39
+ Forum.create!(:id => 1, :name => 'Name 1')
40
+ Forum.create!(:id => 2, :name => 'Name 2')
41
+ Forum.create!(:id => 3, :name => 'Name 2')
42
+ scope = Forum.scoped(:conditions => { :id => [2, 3] })
43
+ scope.collect_column(:name, :distinct => true).should =~ ['Name 2']
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end