assignable_values 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +1 -2
  2. data/Rakefile +26 -5
  3. data/lib/assignable_values/active_record.rb +0 -5
  4. data/lib/assignable_values/active_record/restriction/base.rb +17 -1
  5. data/lib/assignable_values/version.rb +1 -1
  6. data/spec/rails-2.3/Gemfile +8 -0
  7. data/spec/rails-2.3/Rakefile +11 -0
  8. data/spec/rails-2.3/app_root/config/boot.rb +129 -0
  9. data/spec/{app_root → rails-2.3/app_root}/config/database.yml +1 -1
  10. data/spec/rails-2.3/app_root/config/environment.rb +14 -0
  11. data/spec/rails-2.3/app_root/config/environments/test.rb +28 -0
  12. data/spec/rails-2.3/app_root/config/preinitializer.rb +20 -0
  13. data/spec/rails-2.3/app_root/config/routes.rb +4 -0
  14. data/spec/rails-2.3/app_root/lib/console_with_fixtures.rb +4 -0
  15. data/spec/rails-2.3/app_root/log/.gitignore +1 -0
  16. data/spec/rails-2.3/app_root/script/console +7 -0
  17. data/spec/{rcov.opts → rails-2.3/rcov.opts} +0 -0
  18. data/spec/rails-2.3/spec.opts +4 -0
  19. data/spec/rails-2.3/spec_helper.rb +24 -0
  20. data/spec/rails-3.0/.rspec +2 -0
  21. data/spec/rails-3.0/Gemfile +9 -0
  22. data/spec/rails-3.0/Rakefile +10 -0
  23. data/spec/{app_root → rails-3.0/app_root}/.gitignore +0 -0
  24. data/spec/{app_root → rails-3.0/app_root}/config/application.rb +2 -1
  25. data/spec/{app_root → rails-3.0/app_root}/config/boot.rb +0 -0
  26. data/spec/rails-3.0/app_root/config/database.yml +4 -0
  27. data/spec/{app_root → rails-3.0/app_root}/config/environment.rb +1 -1
  28. data/spec/{app_root → rails-3.0/app_root}/config/environments/test.rb +2 -2
  29. data/spec/{app_root → rails-3.0/app_root}/config/initializers/backtrace_silencers.rb +0 -0
  30. data/spec/{app_root → rails-3.0/app_root}/config/initializers/inflections.rb +0 -0
  31. data/spec/{app_root → rails-3.0/app_root}/config/initializers/mime_types.rb +0 -0
  32. data/spec/{app_root → rails-3.0/app_root}/config/initializers/secret_token.rb +1 -1
  33. data/spec/{app_root → rails-3.0/app_root}/config/initializers/session_store.rb +2 -2
  34. data/spec/{app_root → rails-3.0/app_root}/config/routes.rb +1 -1
  35. data/spec/{app_root → rails-3.0/app_root}/lib/tasks/.gitkeep +0 -0
  36. data/spec/{app_root/config/environments/in_memory.rb → rails-3.0/app_root/log/.gitkeep} +0 -0
  37. data/spec/{app_root → rails-3.0/app_root}/script/rails +0 -0
  38. data/spec/rails-3.0/rcov.opts +2 -0
  39. data/spec/{spec_helper.rb → rails-3.0/spec_helper.rb} +8 -4
  40. data/spec/rails-3.2/.rspec +2 -0
  41. data/spec/rails-3.2/Gemfile +9 -0
  42. data/spec/rails-3.2/Rakefile +10 -0
  43. data/spec/rails-3.2/app_root/.gitignore +4 -0
  44. data/spec/rails-3.2/app_root/config/application.rb +32 -0
  45. data/spec/rails-3.2/app_root/config/boot.rb +13 -0
  46. data/spec/rails-3.2/app_root/config/database.yml +4 -0
  47. data/spec/rails-3.2/app_root/config/environment.rb +5 -0
  48. data/spec/rails-3.2/app_root/config/environments/test.rb +35 -0
  49. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +10 -0
  51. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +5 -0
  52. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +7 -0
  53. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +8 -0
  54. data/spec/rails-3.2/app_root/config/routes.rb +58 -0
  55. data/spec/{app_root/config/environments/mysql.rb → rails-3.2/app_root/lib/tasks/.gitkeep} +0 -0
  56. data/spec/{app_root/config/environments/postgresql.rb → rails-3.2/app_root/log/.gitkeep} +0 -0
  57. data/spec/rails-3.2/app_root/script/rails +6 -0
  58. data/spec/rails-3.2/rcov.opts +2 -0
  59. data/spec/rails-3.2/spec_helper.rb +25 -0
  60. data/spec/{app_root → shared/app_root}/app/controllers/application_controller.rb +0 -0
  61. data/spec/{app_root → shared/app_root}/app/models/artist.rb +0 -0
  62. data/spec/{app_root → shared/app_root}/app/models/song.rb +0 -0
  63. data/spec/{app_root → shared/app_root}/config/locales/en.yml +5 -1
  64. data/spec/{app_root → shared/app_root}/db/migrate/001_create_artists.rb +0 -0
  65. data/spec/{app_root → shared/app_root}/db/migrate/002_create_songs.rb +0 -0
  66. data/spec/{assignable_values → shared/assignable_values}/active_record_spec.rb +12 -9
  67. metadata +75 -43
  68. data/Gemfile +0 -3
  69. data/spec/app_root/config/environments/sqlite.rb +0 -0
  70. data/spec/app_root/config/environments/sqlite3.rb +0 -0
data/.gitignore CHANGED
@@ -2,7 +2,6 @@ doc
2
2
  pkg
3
3
  *.gem
4
4
  .idea
5
- spec/app_root/log/*
5
+ spec/*/log/*
6
6
  Gemfile.lock
7
7
 
8
-
data/Rakefile CHANGED
@@ -1,11 +1,32 @@
1
1
  require 'rake'
2
- require 'rspec/core/rake_task'
3
2
  require 'bundler/gem_tasks'
4
3
 
5
4
  desc 'Default: Run all specs.'
6
- task :default => :spec
5
+ task :default => 'all:spec'
7
6
 
8
- desc "Run all specs"
9
- RSpec::Core::RakeTask.new do |t|
10
- # t.spec_files = FileList['spec/**/*_spec.rb']
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
11
32
  end
@@ -8,11 +8,6 @@ module AssignableValues
8
8
  restriction_type.new(self, property, options, &values)
9
9
  end
10
10
 
11
- #def authorize_values_for(property, options = {})
12
- # method_defined?(:power) or attr_accessor :power
13
- # assignable_values_for property, options.merge(:through => :power)
14
- #end
15
-
16
11
  def belongs_to_association?(property)
17
12
  reflection = reflect_on_association(property)
18
13
  reflection && reflection.macro == :belongs_to
@@ -21,13 +21,17 @@ module AssignableValues
21
21
  unless allow_blank? && value.blank?
22
22
  begin
23
23
  assignable_values = assignable_values(record)
24
- assignable_values.include?(value) or record.errors.add(property, I18n.t('errors.messages.inclusion'))
24
+ assignable_values.include?(value) or record.errors.add(property, not_included_error_message)
25
25
  rescue DelegateUnavailable
26
26
  # if the delegate is unavailable, the validation is skipped
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ def not_included_error_message
32
+ I18n.t('errors.messages.inclusion', :default => 'is not included in the list')
33
+ end
34
+
31
35
  def assignable_values(record)
32
36
  assignable_values = []
33
37
  old_value = previously_saved_value(record)
@@ -85,6 +89,7 @@ module AssignableValues
85
89
  end
86
90
 
87
91
  def setup_default
92
+ ensure_after_initialize_callback_enabled
88
93
  @default = options[:default]
89
94
  restriction = self
90
95
  enhance_model do
@@ -96,6 +101,17 @@ module AssignableValues
96
101
  end
97
102
  end
98
103
 
104
+ def ensure_after_initialize_callback_enabled
105
+ if Rails.version < '3'
106
+ enhance_model do
107
+ # Old ActiveRecord version only call after_initialize callbacks only if this method is defined in a class.
108
+ unless method_defined?(:after_initialize)
109
+ define_method(:after_initialize) {}
110
+ end
111
+ end
112
+ end
113
+ end
114
+
99
115
  def setup_validation
100
116
  restriction = self
101
117
  enhance_model do
@@ -1,3 +1,3 @@
1
1
  module AssignableValues
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '=2.3.10'
5
+ gem 'rspec', '<2'
6
+ gem 'rspec-rails', '<2'
7
+ gem 'ruby-debug'
8
+ gem 'assignable_values', :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,129 @@
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
+
114
+ class Rails::Boot
115
+ def run
116
+ load_initializer
117
+
118
+ Rails::Initializer.class_eval do
119
+ def load_gems
120
+ @bundler_loaded ||= Bundler.require :default, Rails.env
121
+ end
122
+ end
123
+
124
+ Rails::Initializer.run(:set_load_path)
125
+ end
126
+ end
127
+
128
+ # All that for this:
129
+ Rails.boot!
@@ -1,4 +1,4 @@
1
- in_memory:
1
+ test:
2
2
  adapter: sqlite3
3
3
  database: ":memory:"
4
4
  verbosity: quiet
@@ -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,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -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,4 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.connect ':controller/:action/:id'
3
+ map.connect ':controller/:action/:id.:format'
4
+ end
@@ -0,0 +1,4 @@
1
+ # Loads fixtures into the database when running the test app via the console
2
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, '../fixtures/*.{yml,csv}'))).each do |fixture_file|
3
+ Fixtures.create_fixtures(File.join(Rails.root, '../fixtures'), File.basename(fixture_file, '.*'))
4
+ end
@@ -0,0 +1,7 @@
1
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
+ libs = " -r irb/completion"
3
+ libs << " -r test/test_helper"
4
+ libs << " -r console_app"
5
+ libs << " -r console_with_helpers"
6
+ libs << " -r console_with_fixtures"
7
+ exec "#{irb} #{libs} --simple-prompt"
File without changes
@@ -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'] ||= 'test'
5
+
6
+ # Load the Rails environment and testing framework
7
+ require "#{File.dirname(__FILE__)}/app_root/config/environment"
8
+ require 'spec/rails'
9
+
10
+ # Load dependencies
11
+ # require 'has_defaults'
12
+
13
+ # Require support code
14
+ # Dir["../shared/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 'http://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '=3.0.3'
5
+ gem 'rspec'
6
+ gem 'rspec-rails'
7
+ gem 'ruby-debug'
8
+ gem 'assignable_values', :path => '../..'
9
+
@@ -0,0 +1,10 @@
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
+ end
@@ -6,7 +6,8 @@ require 'rails/all'
6
6
  # you've limited to :test, :development, or :production.
7
7
  Bundler.require(:default, Rails.env) if defined?(Bundler)
8
8
 
9
- module AssignableValuesSpecApp
9
+
10
+ module HasDefaultSpecApp
10
11
  class Application < Rails::Application
11
12
  config.encoding = "utf-8"
12
13
 
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ verbosity: quiet
@@ -2,4 +2,4 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the rails application
5
- AssignableValuesSpecApp::Application.initialize!
5
+ HasDefaultSpecApp::Application.initialize!
@@ -1,11 +1,11 @@
1
- AssignableValuesSpecApp::Application.configure do
1
+ HasDefaultSpecApp::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
5
  # test suite. You never need to work with it otherwise. Remember that
6
6
  # your test database is "scratch space" for the test suite and is wiped
7
7
  # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = false
8
+ config.cache_classes = true
9
9
 
10
10
  # Log error messages when you accidentally call methods on nil.
11
11
  config.whiny_nils = true
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- AssignableValuesSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
7
+ HasDefaultSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
@@ -1,8 +1,8 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- AssignableValuesSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
3
+ HasDefaultSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
7
7
  # (create the session table with "rails generate session_migration")
8
- # AssignableValuesSpecApp::Application.config.session_store :active_record_store
8
+ # HasDefaultSpecApp::Application.config.session_store :active_record_store
@@ -1,4 +1,4 @@
1
- AssignableValuesSpecApp::Application.routes.draw do
1
+ HasDefaultSpecApp::Application.routes.draw do
2
2
  # The priority is based upon order of creation:
3
3
  # first created -> highest priority.
4
4
 
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -1,19 +1,23 @@
1
1
  $: << File.join(File.dirname(__FILE__), "/../lib" )
2
2
 
3
3
  # Set the default environment to sqlite3's in_memory database
4
- ENV['RAILS_ENV'] ||= 'in_memory'
4
+ ENV['RAILS_ENV'] ||= 'test'
5
5
  ENV['RAILS_ROOT'] = 'app_root'
6
6
 
7
7
  # Load the Rails environment and testing framework
8
8
  require "#{File.dirname(__FILE__)}/app_root/config/environment"
9
- require "#{File.dirname(__FILE__)}/../lib/assignable_values"
10
9
  require 'rspec/rails'
11
10
 
12
- # Undo changes to RAILS_ENV
13
- silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
11
+ # Load dependencies
12
+ # require 'has_defaults'
13
+
14
+ # Require support code
15
+ # Dir["../shared/support/**/*.rb"].each {|f| require f}
14
16
 
15
17
  # Run the migrations
18
+ print "\033[30m" # dark gray text
16
19
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
20
+ print "\033[0m"
17
21
 
18
22
  RSpec.configure do |config|
19
23
  config.use_transactional_fixtures = true
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '~>3.2'
5
+ gem 'rspec'
6
+ gem 'rspec-rails'
7
+ gem 'ruby-debug'
8
+ gem 'assignable_values', :path => '../..'
9
+
@@ -0,0 +1,10 @@
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
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,32 @@
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
+
10
+ module HasDefaultSpecApp
11
+ class Application < Rails::Application
12
+ config.encoding = "utf-8"
13
+
14
+ config.cache_classes = true
15
+ config.whiny_nils = true
16
+
17
+ config.consider_all_requests_local = true
18
+ config.action_controller.perform_caching = false
19
+
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ config.action_controller.allow_forgery_protection = false
23
+
24
+ config.action_mailer.delivery_method = :test
25
+
26
+ config.active_support.deprecation = :stderr
27
+
28
+ config.root = File.expand_path('../..', __FILE__)
29
+
30
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
31
+ end
32
+ 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: ":memory:"
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
+ HasDefaultSpecApp::Application.initialize!
@@ -0,0 +1,35 @@
1
+ HasDefaultSpecApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ HasDefaultSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ HasDefaultSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # HasDefaultSpecApp::Application.config.session_store :active_record_store
@@ -0,0 +1,58 @@
1
+ HasDefaultSpecApp::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -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,25 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../lib" )
2
+
3
+ # Set the default environment to sqlite3's in_memory database
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+ ENV['RAILS_ROOT'] = 'app_root'
6
+
7
+ # Load the Rails environment and testing framework
8
+ require "#{File.dirname(__FILE__)}/app_root/config/environment"
9
+ require 'rspec/rails'
10
+
11
+ # Load dependencies
12
+ # require 'has_defaults'
13
+
14
+ # Require support code
15
+ # Dir["../shared/support/**/*.rb"].each {|f| require f}
16
+
17
+ # Run the migrations
18
+ print "\033[30m" # dark gray text
19
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
20
+ print "\033[0m"
21
+
22
+ RSpec.configure do |config|
23
+ config.use_transactional_fixtures = true
24
+ config.use_instantiated_fixtures = false
25
+ end
@@ -2,9 +2,13 @@
2
2
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
+
6
+ errors:
7
+ messages:
8
+ inclusion: "is not included in the list"
9
+
5
10
  assignable_values:
6
11
  song:
7
12
  genre:
8
13
  pop: 'Pop music'
9
14
  rock: 'Rock music'
10
-
@@ -4,10 +4,11 @@ require 'ostruct'
4
4
  describe AssignableValues::ActiveRecord do
5
5
 
6
6
  def disposable_song_class(&block)
7
- klass = Class.new(Song, &block)
7
+ klass = Class.new(Song) #, &block)
8
8
  def klass.name
9
9
  'Song'
10
10
  end
11
+ klass.class_eval(&block) if block
11
12
  klass
12
13
  end
13
14
 
@@ -41,8 +42,10 @@ describe AssignableValues::ActiveRecord do
41
42
  it 'should use the same error message as validates_inclusion_of' do
42
43
  record = @klass.new(:genre => 'disallowed value')
43
44
  record.valid?
44
- record.errors[:genre].first.should == I18n.t('errors.messages.inclusion')
45
- record.errors[:genre].first.should == 'is not included in the list'
45
+ errors = record.errors[:genre]
46
+ error = errors.is_a?(Array) ? errors.first : errors # the return value sometimes was a string, sometimes an Array in Rails
47
+ error.should == I18n.t('errors.messages.inclusion')
48
+ error.should == 'is not included in the list'
46
49
  end
47
50
 
48
51
  it 'should not allow nil for the attribute value' do
@@ -50,9 +53,9 @@ describe AssignableValues::ActiveRecord do
50
53
  end
51
54
 
52
55
  it 'should allow a previously saved value even if that value is no longer allowed' do
53
- song = @klass.new(:genre => 'disallowed value')
54
- song.save!(:validate => false)
55
- song.should be_valid
56
+ record = @klass.create!(:genre => 'pop')
57
+ @klass.update_all(:genre => 'disallowed value') # update without validations for the sake of this test
58
+ record.reload.should be_valid
56
59
  end
57
60
 
58
61
  it 'should generate a method returning the humanized value' do
@@ -291,9 +294,9 @@ describe AssignableValues::ActiveRecord do
291
294
  %w[pop rock]
292
295
  end
293
296
  end
294
- record = klass.new(:genre => 'ballad')
295
- record.save!(:validate => false)
296
- record.assignable_genres.should =~ %w[pop rock ballad]
297
+ record = klass.create!(:genre => 'pop')
298
+ klass.update_all(:genre => 'ballad') # update without validation for the sake of this test
299
+ record.reload.assignable_genres.should =~ %w[pop rock ballad]
297
300
  end
298
301
 
299
302
  context 'humanization' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assignable_values
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henning Koch
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-15 00:00:00 +02:00
18
+ date: 2012-07-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :runtime
22
+ name: activerecord
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -30,10 +30,10 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
33
- name: activerecord
33
+ type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- type: :development
36
+ name: rails
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -45,10 +45,10 @@ dependencies:
45
45
  - 3
46
46
  - 1
47
47
  version: "3.1"
48
- name: rails
48
+ type: :development
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- type: :development
51
+ name: rspec
52
52
  prerelease: false
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -60,10 +60,10 @@ dependencies:
60
60
  - 2
61
61
  - 8
62
62
  version: "2.8"
63
- name: rspec
63
+ type: :development
64
64
  version_requirements: *id003
65
65
  - !ruby/object:Gem::Dependency
66
- type: :development
66
+ name: rspec-rails
67
67
  prerelease: false
68
68
  requirement: &id004 !ruby/object:Gem::Requirement
69
69
  none: false
@@ -75,10 +75,10 @@ dependencies:
75
75
  - 2
76
76
  - 8
77
77
  version: "2.8"
78
- name: rspec-rails
78
+ type: :development
79
79
  version_requirements: *id004
80
80
  - !ruby/object:Gem::Dependency
81
- type: :development
81
+ name: sqlite3
82
82
  prerelease: false
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
@@ -89,7 +89,7 @@ dependencies:
89
89
  segments:
90
90
  - 0
91
91
  version: "0"
92
- name: sqlite3
92
+ type: :development
93
93
  version_requirements: *id005
94
94
  description: Restrict the values assignable to ActiveRecord attributes or associations. Or enums on steroids.
95
95
  email: henning.koch@makandra.de
@@ -102,7 +102,6 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - .gitignore
104
104
  - .rspec
105
- - Gemfile
106
105
  - README.md
107
106
  - Rakefile
108
107
  - assignable_values.gemspec
@@ -113,34 +112,67 @@ files:
113
112
  - lib/assignable_values/active_record/restriction/scalar_attribute.rb
114
113
  - lib/assignable_values/errors.rb
115
114
  - lib/assignable_values/version.rb
116
- - spec/app_root/.gitignore
117
- - spec/app_root/app/controllers/application_controller.rb
118
- - spec/app_root/app/models/artist.rb
119
- - spec/app_root/app/models/song.rb
120
- - spec/app_root/config/application.rb
121
- - spec/app_root/config/boot.rb
122
- - spec/app_root/config/database.yml
123
- - spec/app_root/config/environment.rb
124
- - spec/app_root/config/environments/in_memory.rb
125
- - spec/app_root/config/environments/mysql.rb
126
- - spec/app_root/config/environments/postgresql.rb
127
- - spec/app_root/config/environments/sqlite.rb
128
- - spec/app_root/config/environments/sqlite3.rb
129
- - spec/app_root/config/environments/test.rb
130
- - spec/app_root/config/initializers/backtrace_silencers.rb
131
- - spec/app_root/config/initializers/inflections.rb
132
- - spec/app_root/config/initializers/mime_types.rb
133
- - spec/app_root/config/initializers/secret_token.rb
134
- - spec/app_root/config/initializers/session_store.rb
135
- - spec/app_root/config/locales/en.yml
136
- - spec/app_root/config/routes.rb
137
- - spec/app_root/db/migrate/001_create_artists.rb
138
- - spec/app_root/db/migrate/002_create_songs.rb
139
- - spec/app_root/lib/tasks/.gitkeep
140
- - spec/app_root/script/rails
141
- - spec/assignable_values/active_record_spec.rb
142
- - spec/rcov.opts
143
- - spec/spec_helper.rb
115
+ - spec/rails-2.3/Gemfile
116
+ - spec/rails-2.3/Rakefile
117
+ - spec/rails-2.3/app_root/config/boot.rb
118
+ - spec/rails-2.3/app_root/config/database.yml
119
+ - spec/rails-2.3/app_root/config/environment.rb
120
+ - spec/rails-2.3/app_root/config/environments/test.rb
121
+ - spec/rails-2.3/app_root/config/preinitializer.rb
122
+ - spec/rails-2.3/app_root/config/routes.rb
123
+ - spec/rails-2.3/app_root/lib/console_with_fixtures.rb
124
+ - spec/rails-2.3/app_root/log/.gitignore
125
+ - spec/rails-2.3/app_root/script/console
126
+ - spec/rails-2.3/rcov.opts
127
+ - spec/rails-2.3/spec.opts
128
+ - spec/rails-2.3/spec_helper.rb
129
+ - spec/rails-3.0/.rspec
130
+ - spec/rails-3.0/Gemfile
131
+ - spec/rails-3.0/Rakefile
132
+ - spec/rails-3.0/app_root/.gitignore
133
+ - spec/rails-3.0/app_root/config/application.rb
134
+ - spec/rails-3.0/app_root/config/boot.rb
135
+ - spec/rails-3.0/app_root/config/database.yml
136
+ - spec/rails-3.0/app_root/config/environment.rb
137
+ - spec/rails-3.0/app_root/config/environments/test.rb
138
+ - spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb
139
+ - spec/rails-3.0/app_root/config/initializers/inflections.rb
140
+ - spec/rails-3.0/app_root/config/initializers/mime_types.rb
141
+ - spec/rails-3.0/app_root/config/initializers/secret_token.rb
142
+ - spec/rails-3.0/app_root/config/initializers/session_store.rb
143
+ - spec/rails-3.0/app_root/config/routes.rb
144
+ - spec/rails-3.0/app_root/lib/tasks/.gitkeep
145
+ - spec/rails-3.0/app_root/log/.gitkeep
146
+ - spec/rails-3.0/app_root/script/rails
147
+ - spec/rails-3.0/rcov.opts
148
+ - spec/rails-3.0/spec_helper.rb
149
+ - spec/rails-3.2/.rspec
150
+ - spec/rails-3.2/Gemfile
151
+ - spec/rails-3.2/Rakefile
152
+ - spec/rails-3.2/app_root/.gitignore
153
+ - spec/rails-3.2/app_root/config/application.rb
154
+ - spec/rails-3.2/app_root/config/boot.rb
155
+ - spec/rails-3.2/app_root/config/database.yml
156
+ - spec/rails-3.2/app_root/config/environment.rb
157
+ - spec/rails-3.2/app_root/config/environments/test.rb
158
+ - spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb
159
+ - spec/rails-3.2/app_root/config/initializers/inflections.rb
160
+ - spec/rails-3.2/app_root/config/initializers/mime_types.rb
161
+ - spec/rails-3.2/app_root/config/initializers/secret_token.rb
162
+ - spec/rails-3.2/app_root/config/initializers/session_store.rb
163
+ - spec/rails-3.2/app_root/config/routes.rb
164
+ - spec/rails-3.2/app_root/lib/tasks/.gitkeep
165
+ - spec/rails-3.2/app_root/log/.gitkeep
166
+ - spec/rails-3.2/app_root/script/rails
167
+ - spec/rails-3.2/rcov.opts
168
+ - spec/rails-3.2/spec_helper.rb
169
+ - spec/shared/app_root/app/controllers/application_controller.rb
170
+ - spec/shared/app_root/app/models/artist.rb
171
+ - spec/shared/app_root/app/models/song.rb
172
+ - spec/shared/app_root/config/locales/en.yml
173
+ - spec/shared/app_root/db/migrate/001_create_artists.rb
174
+ - spec/shared/app_root/db/migrate/002_create_songs.rb
175
+ - spec/shared/assignable_values/active_record_spec.rb
144
176
  has_rdoc: true
145
177
  homepage: https://github.com/makandra/assignable_values
146
178
  licenses: []
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec