Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 12 commits
  • 54 files changed
  • 0 commit comments
  • 2 contributors
Showing with 657 additions and 43 deletions.
  1. +1 −0  .ruby-version
  2. +1 −0  .travis.yml
  3. +10 −4 README.md
  4. +19 −7 Rakefile
  5. +15 −8 lib/assignable_values/active_record/restriction/base.rb
  6. +4 −1 lib/assignable_values/active_record/restriction/scalar_attribute.rb
  7. +1 −1  lib/assignable_values/version.rb
  8. +4 −1 spec/rails-2.3/Gemfile
  9. +2 −2 spec/rails-2.3/Gemfile.lock
  10. +0 −4 spec/rails-2.3/app_root/config/database.yml
  11. +1 −0  spec/rails-2.3/app_root/config/database.yml
  12. +1 −1  spec/rails-3.0/Gemfile
  13. +2 −2 spec/rails-3.0/Gemfile.lock
  14. +1 −0  spec/rails-3.0/app_root/config/database.yml
  15. +0 −4 spec/rails-3.0/app_root/config/database.yml
  16. +1 −1  spec/rails-3.2/Gemfile
  17. +2 −2 spec/rails-3.2/Gemfile.lock
  18. +0 −4 spec/rails-3.2/app_root/config/database.yml
  19. +1 −0  spec/rails-3.2/app_root/config/database.yml
  20. +2 −0  spec/rails-4.1/.rspec
  21. +1 −0  spec/rails-4.1/.ruby-version
  22. +16 −0 spec/rails-4.1/Gemfile
  23. +143 −0 spec/rails-4.1/Gemfile.lock
  24. +12 −0 spec/rails-4.1/Rakefile
  25. +16 −0 spec/rails-4.1/app_root/.gitignore
  26. +1 −0  spec/rails-4.1/app_root/app
  27. +3 −0  spec/rails-4.1/app_root/bin/bundle
  28. +8 −0 spec/rails-4.1/app_root/bin/rails
  29. +8 −0 spec/rails-4.1/app_root/bin/rake
  30. +18 −0 spec/rails-4.1/app_root/bin/spring
  31. +28 −0 spec/rails-4.1/app_root/config/application.rb
  32. +4 −0 spec/rails-4.1/app_root/config/boot.rb
  33. +1 −0  spec/rails-4.1/app_root/config/database.yml
  34. +5 −0 spec/rails-4.1/app_root/config/environment.rb
  35. +37 −0 spec/rails-4.1/app_root/config/environments/development.rb
  36. +83 −0 spec/rails-4.1/app_root/config/environments/production.rb
  37. +39 −0 spec/rails-4.1/app_root/config/environments/test.rb
  38. +7 −0 spec/rails-4.1/app_root/config/initializers/backtrace_silencers.rb
  39. +3 −0  spec/rails-4.1/app_root/config/initializers/cookies_serializer.rb
  40. +4 −0 spec/rails-4.1/app_root/config/initializers/filter_parameter_logging.rb
  41. +16 −0 spec/rails-4.1/app_root/config/initializers/inflections.rb
  42. +4 −0 spec/rails-4.1/app_root/config/initializers/mime_types.rb
  43. +3 −0  spec/rails-4.1/app_root/config/initializers/session_store.rb
  44. +14 −0 spec/rails-4.1/app_root/config/initializers/wrap_parameters.rb
  45. +1 −0  spec/rails-4.1/app_root/config/locales
  46. +3 −0  spec/rails-4.1/app_root/config/routes.rb
  47. +22 −0 spec/rails-4.1/app_root/config/secrets.yml
  48. +1 −0  spec/rails-4.1/app_root/db
  49. +2 −0  spec/rails-4.1/rcov.opts
  50. +25 −0 spec/rails-4.1/spec/spec_helper.rb
  51. +2 −0  spec/shared/app_root/app/models/song.rb
  52. +4 −0 spec/shared/app_root/config/database.yml
  53. +3 −0  spec/shared/app_root/config/locales/en.yml
  54. +52 −1 spec/shared/assignable_values/active_record_spec.rb
View
1  .ruby-version
@@ -0,0 +1 @@
+1.9.3
View
1  .travis.yml
@@ -2,6 +2,7 @@ language: ruby
rvm:
- "1.8.7"
- "1.9.3"
+ - "2.1.0"
- ree
services:
- mysql
View
14 README.md
@@ -5,6 +5,8 @@ assignable_values - Enums on vitamins [![Build Status](https://secure.travis-ci.
We carefully enhanced the core enum functionality with small tweaks that are useful for web forms, internationalized applications and common authorization patterns.
+`assignable_values` is tested with Rails 2.3, 3.0, 3.2 and 4.1 on Ruby 1.8.7, 1.9.3 and 2.1.0.
+
Restricting scalar attributes
-----------------------------
@@ -156,11 +158,15 @@ If a value has been saved before, it will remain valid, even if it is no longer
It will also be returned when obtaining the list of assignable values:
- song.assignable_genres # => [2010, 2011, 2012, 1985]
+ song.assignable_years # => [2010, 2011, 2012, 1985]
+
+However, if you want only those values that are actually intended to be assignable, e.g. when updating a `<select>` via AJAX, pass an option:
+
+ song.assignable_years(include_old_value: false) # => [2010, 2011, 2012]
Once a changed value has been saved, the previous value disappears from the list of assignable values:
- song.genre = 'pop'
+ song.year = '2010'
song.save!
song.assignable_years # => [2010, 2011, 2012]
song.year = 1985
@@ -174,7 +180,7 @@ Restricting belongs_to associations
You can restrict `belongs_to` associations in the same manner as scalar attributes:
- class Song
+ class Song < ActiveRecord::Base
belongs_to :artist
@@ -200,7 +206,7 @@ Listing and validating als works the same:
song.valid? # => false
Similiar to scalar attributes, associations are only validated when the foreign key (`artist_id` in the example above) changes.
-Previously saved values will remain assignable until another association has been saved.
+Values stored in the database will remain assignable until they are changed, and you can query actually assignable values with `song.assignable_artists(include_old_value: false)`.
Validation errors will be attached to the association's foreign key (`artist_id` in the example above).
View
26 Rakefile
@@ -8,11 +8,13 @@ task :default => 'all:spec'
namespace :travis do
desc 'Run tests on Travis CI'
- task :run => ['slimgems', 'all:bundle:install', 'all:spec']
+ task :run => [:compatible_rubygems, 'all:bundle:install', 'all:spec']
- desc 'Install slimgems'
- task :slimgems do
- system('gem install slimgems')
+ desc 'Ensure compatible Rubygems version for Ruby 1.8'
+ task :compatible_rubygems do
+ if RUBY_VERSION == '1.8.7'
+ system "rvm rubygems latest-1.8 --force"
+ end
end
end
@@ -29,13 +31,16 @@ namespace :all do
fail "Tests failed" unless success
end
+
+ task :bundle => 'bundle:install'
+
namespace :bundle do
desc "Bundle all spec apps"
task :install do
for_each_directory_of('spec/**/Gemfile') do |directory|
Bundler.with_clean_env do
- system("cd #{directory} && bundle install")
+ system("cd #{directory} && bundle install --without development")
end
end
end
@@ -56,7 +61,14 @@ end
def for_each_directory_of(path, &block)
Dir[path].sort.each do |rakefile|
directory = File.dirname(rakefile)
- puts '', "\033[44m#{directory}\033[0m", ''
- block.call(directory)
+ puts '', "\033[4;34m# #{directory}\033[0m" # blue underline
+
+ if directory.include?('rails-2.3') and RUBY_VERSION != '1.8.7'
+ puts 'Skipping - Rails 2.3 requires Ruby 1.8.7'
+ elsif directory.include?('rails-4.1') and RUBY_VERSION == '1.8.7'
+ puts 'Skipping - Rails 4.1 does not support Ruby 1.8'
+ else
+ block.call(directory)
+ end
end
end
View
23 lib/assignable_values/active_record/restriction/base.rb
@@ -45,19 +45,23 @@ def assignable_value?(record, value)
assignable_values(record).include?(value)
end
- def assignable_values(record, decorate = false)
+ def assignable_values(record, options = {})
assignable_values = []
parsed_values = parsed_assignable_values(record)
current_values = parsed_values.delete(:values)
- old_value = previously_saved_value(record)
- if old_value.present? && !current_values.include?(old_value)
- assignable_values << old_value
+
+ if options.fetch(:include_old_value, true)
+ old_value = previously_saved_value(record)
+ if old_value.present? && !current_values.include?(old_value)
+ assignable_values << old_value
+ end
end
+
assignable_values += current_values
parsed_values.each do |meta_name, meta_content|
assignable_values.singleton_class.send(:define_method, meta_name) { meta_content }
end
- if decorate
+ if options[:decorate]
assignable_values = decorate_values(assignable_values)
end
assignable_values
@@ -92,7 +96,7 @@ def evaluate_default(record, value_or_proc)
end
def parse_values(values)
- { :values => values.to_a }
+ { :values => Array(values) }
end
def current_value(record)
@@ -179,8 +183,11 @@ def define_assignable_values_method
restriction = self
enhance_model do
assignable_values_method = "assignable_#{restriction.property.to_s.pluralize}"
- define_method assignable_values_method do
- restriction.assignable_values(self, true)
+ define_method assignable_values_method do |*args|
+ # Ruby 1.8.7 does not support optional block arguments :(
+ options = args.first || {}
+ options.merge!({:decorate => true})
+ restriction.assignable_values(self, options)
end
end
end
View
5 lib/assignable_values/active_record/restriction/scalar_attribute.rb
@@ -89,7 +89,10 @@ def decorate_values(values)
end
def previously_saved_value(record)
- record.send("#{property}_was")
+ was_method_name = "#{property}_was"
+ if record.respond_to?(was_method_name)
+ record.send(was_method_name)
+ end
end
end
View
2  lib/assignable_values/version.rb
@@ -1,3 +1,3 @@
module AssignableValues
- VERSION = '0.8.1'
+ VERSION = '0.11.1'
end
View
5 spec/rails-2.3/Gemfile
@@ -1,4 +1,7 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
+
+Deprecate.skip = true if defined?(Deprecate.skip)
+Gem::Deprecate.skip = true if defined?(Gem::Deprecate.skip)
gem 'sqlite3'
gem 'test-unit', '=1.2.3', :platforms => :ruby_19
View
4 spec/rails-2.3/Gemfile.lock
@@ -1,11 +1,11 @@
PATH
remote: ../..
specs:
- assignable_values (0.8.1)
+ assignable_values (0.10.0)
activerecord
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
actionmailer (2.3.17)
actionpack (= 2.3.17)
View
4 spec/rails-2.3/app_root/config/database.yml
@@ -1,4 +0,0 @@
-test:
- adapter: sqlite3
- database: ":memory:"
- verbosity: quiet
View
1  spec/rails-2.3/app_root/config/database.yml
View
2  spec/rails-3.0/Gemfile
@@ -1,4 +1,4 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
gem 'sqlite3'
gem 'rails', '~>3.0.3'
View
4 spec/rails-3.0/Gemfile.lock
@@ -1,11 +1,11 @@
PATH
remote: ../..
specs:
- assignable_values (0.8.1)
+ assignable_values (0.11.0)
activerecord
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.20)
View
1  spec/rails-3.0/app_root/config/database.yml
View
4 spec/rails-3.0/app_root/config/database.yml
@@ -1,4 +0,0 @@
-test:
- adapter: sqlite3
- database: ":memory:"
- verbosity: quiet
View
2  spec/rails-3.2/Gemfile
@@ -1,4 +1,4 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
gem 'sqlite3'
gem 'rails', '~>3.2'
View
4 spec/rails-3.2/Gemfile.lock
@@ -1,11 +1,11 @@
PATH
remote: ../..
specs:
- assignable_values (0.8.1)
+ assignable_values (0.11.0)
activerecord
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
actionmailer (3.2.12)
actionpack (= 3.2.12)
View
4 spec/rails-3.2/app_root/config/database.yml
@@ -1,4 +0,0 @@
-test:
- adapter: sqlite3
- database: ":memory:"
- verbosity: quiet
View
1  spec/rails-3.2/app_root/config/database.yml
View
2  spec/rails-4.1/.rspec
@@ -0,0 +1,2 @@
+--colour
+--format progress
View
1  spec/rails-4.1/.ruby-version
@@ -0,0 +1 @@
+2.1.0
View
16 spec/rails-4.1/Gemfile
@@ -0,0 +1,16 @@
+source 'https://rubygems.org'
+
+gem 'sqlite3'
+gem 'rails', '4.1.0'
+gem 'minitest' # fix MiniTest deprecation warnings
+gem 'rspec'
+gem 'rspec-rails'
+gem 'rspec_candy'
+gem 'rspec-collection_matchers' # support for ...should have(n).errors_on ...
+
+gem 'assignable_values', :path => '../..'
+
+group :development do
+ gem 'debugger', platform: 'ruby_19'
+ gem 'ruby-debug', :platforms => :ruby_18
+end
View
143 spec/rails-4.1/Gemfile.lock
@@ -0,0 +1,143 @@
+PATH
+ remote: ../..
+ specs:
+ assignable_values (0.11.0)
+ activerecord
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (4.1.0)
+ actionpack (= 4.1.0)
+ actionview (= 4.1.0)
+ mail (~> 2.5.4)
+ actionpack (4.1.0)
+ actionview (= 4.1.0)
+ activesupport (= 4.1.0)
+ rack (~> 1.5.2)
+ rack-test (~> 0.6.2)
+ actionview (4.1.0)
+ activesupport (= 4.1.0)
+ builder (~> 3.1)
+ erubis (~> 2.7.0)
+ activemodel (4.1.0)
+ activesupport (= 4.1.0)
+ builder (~> 3.1)
+ activerecord (4.1.0)
+ activemodel (= 4.1.0)
+ activesupport (= 4.1.0)
+ arel (~> 5.0.0)
+ activesupport (4.1.0)
+ i18n (~> 0.6, >= 0.6.9)
+ json (~> 1.7, >= 1.7.7)
+ minitest (~> 5.1)
+ thread_safe (~> 0.1)
+ tzinfo (~> 1.1)
+ arel (5.0.1.20140414130214)
+ builder (3.2.2)
+ columnize (0.3.6)
+ debugger (1.6.3)
+ columnize (>= 0.3.1)
+ debugger-linecache (~> 1.2.0)
+ debugger-ruby_core_source (~> 1.2.4)
+ debugger-linecache (1.2.0)
+ debugger-ruby_core_source (1.2.4)
+ diff-lcs (1.2.5)
+ erubis (2.7.0)
+ hike (1.2.3)
+ i18n (0.6.9)
+ json (1.8.1)
+ linecache (0.46)
+ rbx-require-relative (> 0.0.4)
+ mail (2.5.4)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.25.1)
+ minitest (5.3.4)
+ multi_json (1.10.1)
+ polyglot (0.3.5)
+ rack (1.5.2)
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rails (4.1.0)
+ actionmailer (= 4.1.0)
+ actionpack (= 4.1.0)
+ actionview (= 4.1.0)
+ activemodel (= 4.1.0)
+ activerecord (= 4.1.0)
+ activesupport (= 4.1.0)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 4.1.0)
+ sprockets-rails (~> 2.0)
+ railties (4.1.0)
+ actionpack (= 4.1.0)
+ activesupport (= 4.1.0)
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (10.3.2)
+ rbx-require-relative (0.0.9)
+ rspec (3.0.0)
+ rspec-core (~> 3.0.0)
+ rspec-expectations (~> 3.0.0)
+ rspec-mocks (~> 3.0.0)
+ rspec-collection_matchers (1.0.0)
+ rspec-expectations (>= 2.99.0.beta1)
+ rspec-core (3.0.0)
+ rspec-support (~> 3.0.0)
+ rspec-expectations (3.0.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.0.0)
+ rspec-mocks (3.0.0)
+ rspec-support (~> 3.0.0)
+ rspec-rails (3.0.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 3.0.0)
+ rspec-expectations (~> 3.0.0)
+ rspec-mocks (~> 3.0.0)
+ rspec-support (~> 3.0.0)
+ rspec-support (3.0.0)
+ rspec_candy (0.3.1)
+ rspec
+ sneaky-save
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ sneaky-save (0.0.5)
+ activerecord (>= 3.2.0)
+ sprockets (2.11.0)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sprockets-rails (2.1.3)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ sprockets (~> 2.8)
+ sqlite3 (1.3.9)
+ thor (0.19.1)
+ thread_safe (0.3.4)
+ tilt (1.4.1)
+ treetop (1.4.15)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (1.2.1)
+ thread_safe (~> 0.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ assignable_values!
+ debugger
+ minitest
+ rails (= 4.1.0)
+ rspec
+ rspec-collection_matchers
+ rspec-rails
+ rspec_candy
+ ruby-debug
+ sqlite3
View
12 spec/rails-4.1/Rakefile
@@ -0,0 +1,12 @@
+require 'rake'
+require 'rspec/core/rake_task'
+
+desc 'Default: Run all specs for a specific rails version.'
+task :default => :spec
+
+desc "Run all specs for a specific rails version"
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = defined?(SPEC) ? SPEC : ['**/*_spec.rb', '../shared/**/*_spec.rb']
+ t.verbose = false
+ # t.rspec_opts = '--backtrace'
+end
View
16 spec/rails-4.1/app_root/.gitignore
@@ -0,0 +1,16 @@
+# See https://help.github.com/articles/ignoring-files for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile '~/.gitignore_global'
+
+# Ignore bundler config.
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+/db/*.sqlite3-journal
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
View
1  spec/rails-4.1/app_root/app
View
3  spec/rails-4.1/app_root/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
View
8 spec/rails-4.1/app_root/bin/rails
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path("../spring", __FILE__)
+rescue LoadError
+end
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require_relative '../config/boot'
+require 'rails/commands'
View
8 spec/rails-4.1/app_root/bin/rake
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path("../spring", __FILE__)
+rescue LoadError
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
View
18 spec/rails-4.1/app_root/bin/spring
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast
+# It gets overwritten when you run the `spring binstub` command
+
+unless defined?(Spring)
+ require "rubygems"
+ require "bundler"
+
+ if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
+ ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
+ ENV["GEM_HOME"] = ""
+ Gem.paths = ENV
+
+ gem "spring", match[1]
+ require "spring/binstub"
+ end
+end
View
28 spec/rails-4.1/app_root/config/application.rb
@@ -0,0 +1,28 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module SpecApp
+ class Application < Rails::Application
+ config.encoding = "utf-8"
+
+ config.cache_classes = true
+ config.whiny_nils = true
+
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+ config.action_controller.allow_forgery_protection = false
+
+ config.action_dispatch.show_exceptions = false
+
+ config.action_mailer.delivery_method = :test
+
+ config.active_support.deprecation = :stderr
+
+ config.root = File.expand_path('../..', __FILE__)
+ end
+end
View
4 spec/rails-4.1/app_root/config/boot.rb
@@ -0,0 +1,4 @@
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
View
1  spec/rails-4.1/app_root/config/database.yml
View
5 spec/rails-4.1/app_root/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require File.expand_path('../application', __FILE__)
+
+# Initialize the Rails application.
+Rails.application.initialize!
View
37 spec/rails-4.1/app_root/config/environments/development.rb
@@ -0,0 +1,37 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Adds additional error checking when serving assets at runtime.
+ # Checks for improperly declared sprockets dependencies.
+ # Raises helpful error messages.
+ config.assets.raise_runtime_errors = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
View
83 spec/rails-4.1/app_root/config/environments/production.rb
@@ -0,0 +1,83 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
+ # Add `rack-cache` to your Gemfile before enabling this.
+ # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
+ # config.action_dispatch.rack_cache = true
+
+ # Disable Rails's static asset server (Apache or nginx will already do this).
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # Generate digests for assets URLs.
+ config.assets.digest = true
+
+ # Version of your assets, change this if you want to expire all your assets.
+ config.assets.version = '1.0'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Set to :debug to see everything in the log.
+ config.log_level = :info
+
+ # Prepend all log lines with the following tags.
+ # config.log_tags = [ :subdomain, :uuid ]
+
+ # Use a different logger for distributed setups.
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets.
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
+ # config.assets.precompile += %w( search.js )
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Disable automatic flushing of the log to improve performance.
+ # config.autoflush_log = false
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
View
39 spec/rails-4.1/app_root/config/environments/test.rb
@@ -0,0 +1,39 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure static asset server for tests with Cache-Control for performance.
+ config.serve_static_assets = true
+ config.static_cache_control = 'public, max-age=3600'
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
View
7 spec/rails-4.1/app_root/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
3  spec/rails-4.1/app_root/config/initializers/cookies_serializer.rb
@@ -0,0 +1,3 @@
+# Be sure to restart your server when you modify this file.
+
+Rails.application.config.action_dispatch.cookies_serializer = :json
View
4 spec/rails-4.1/app_root/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
View
16 spec/rails-4.1/app_root/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
View
4 spec/rails-4.1/app_root/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
View
3  spec/rails-4.1/app_root/config/initializers/session_store.rb
@@ -0,0 +1,3 @@
+# Be sure to restart your server when you modify this file.
+
+Rails.application.config.session_store :cookie_store, key: '_spec_app_session'
View
14 spec/rails-4.1/app_root/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
View
1  spec/rails-4.1/app_root/config/locales
View
3  spec/rails-4.1/app_root/config/routes.rb
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ get ':controller(/:action(/:id(.:format)))'
+end
View
22 spec/rails-4.1/app_root/config/secrets.yml
@@ -0,0 +1,22 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key is used for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+# You can use `rake secret` to generate a secure secret key.
+
+# Make sure the secrets in this file are kept private
+# if you're sharing your code publicly.
+
+development:
+ secret_key_base: 7aa3418aec81500e8e336d984b9d438f602911ae48df0725543b9c72699a9fa84ce099b327d7db2b10f2655963f19139c9c4c86304b9342ccb9c7e389fc65b6e
+
+test:
+ secret_key_base: 9eb558edf0b5fda539c566df1e3a5b699e7e16267167c797ce838d120a0d52c7c5672bada24457f0ed7b59786e360e2c27e9b9e021cbe98358dc72382cfcd50f
+
+# Do not keep production secrets in the repository,
+# instead read values from the environment.
+production:
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
View
1  spec/rails-4.1/app_root/db
View
2  spec/rails-4.1/rcov.opts
@@ -0,0 +1,2 @@
+--exclude "spec/*,gems/*"
+--rails
View
25 spec/rails-4.1/spec/spec_helper.rb
@@ -0,0 +1,25 @@
+$: << File.join(File.dirname(__FILE__), "/../../lib" )
+
+ENV['RAILS_ENV'] ||= 'test'
+ENV['RAILS_ROOT'] = 'app_root'
+
+# Load the Rails environment and testing framework
+require "#{File.dirname(__FILE__)}/../app_root/config/environment"
+require 'rspec/rails'
+require 'rspec_candy/all'
+
+# Run the migrations
+print "\033[30m" # dark gray text
+ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
+print "\033[0m"
+
+RSpec.configure do |config|
+ config.use_transactional_fixtures = false
+ config.use_instantiated_fixtures = false
+ config.mock_with :rspec do |c|
+ c.syntax = [:should, :expect]
+ end
+ config.expect_with :rspec do |c|
+ c.syntax = [:should, :expect]
+ end
+end
View
2  spec/shared/app_root/app/models/song.rb
@@ -2,4 +2,6 @@ class Song < ActiveRecord::Base
belongs_to :artist
+ attr_accessor :sub_genre
+
end
View
4 spec/shared/app_root/config/database.yml
@@ -0,0 +1,4 @@
+test:
+ adapter: sqlite3
+ database: ":memory:"
+ verbosity: quiet
View
3  spec/shared/app_root/config/locales/en.yml
@@ -12,6 +12,9 @@ en:
genre:
pop: 'Pop music'
rock: 'Rock music'
+ sub_genre:
+ pop: 'Pop music'
+ rock: 'Rock music'
year:
'1977': 'The year a new hope was born'
'1980': 'The year the Empire stroke back'
View
53 spec/shared/assignable_values/active_record_spec.rb
@@ -13,6 +13,32 @@
end.to raise_error(AssignableValues::NoValuesGiven)
end
+ context 'when validating virtual attributes' do
+
+ before :each do
+ @klass = Song.disposable_copy do
+ assignable_values_for :sub_genre do
+ %w[pop rock]
+ end
+ end
+ end
+
+ it 'should validate that the attribute is allowed' do
+ @klass.new(:sub_genre => 'pop').should be_valid
+ @klass.new(:sub_genre => 'disallowed value').should_not be_valid
+ end
+
+ it 'should not allow nil for the attribute value' do
+ @klass.new(:sub_genre => nil).should_not be_valid
+ end
+
+ it 'should generate a method returning the humanized value' do
+ song = @klass.new(:sub_genre => 'pop')
+ song.humanized_sub_genre.should == 'Pop music'
+ end
+
+ end
+
context 'when validating scalar attributes' do
context 'without options' do
@@ -45,7 +71,7 @@
it 'should allow a previously saved value even if that value is no longer allowed' do
record = @klass.create!(:genre => 'pop')
- @klass.update_all(:genre => 'disallowed value') # update without validations for the sake of this test
+ @klass.update_all(:genre => 'pretend previously valid value') # update without validations for the sake of this test
record.reload.should be_valid
end
@@ -490,6 +516,31 @@ def genres
record.assignable_genres.should == %w[pop rock]
end
+ it 'should allow omitting a previously saved value' do
+ klass = Song.disposable_copy do
+ assignable_values_for :genre do
+ %w[pop rock]
+ end
+ end
+ record = klass.create!(:genre => 'pop')
+ klass.update_all(:genre => 'ballad') # update without validation for the sake of this test
+ record.reload.assignable_genres(:include_old_value => false).should == %w[pop rock]
+ end
+
+ it 'should allow omitting a previously saved association' do
+ allowed_association = Artist.create!
+ disallowed_association = Artist.create!
+ klass = Song.disposable_copy
+
+ record = klass.create!(:artist => disallowed_association)
+ klass.class_eval do
+ assignable_values_for :artist do
+ [allowed_association]
+ end
+ end
+ record.assignable_artists(:include_old_value => false).should =~ [allowed_association]
+ end
+
context 'humanization' do
it 'should define a method that return pairs of values and their humanization' do

No commit comments for this range

Something went wrong with that request. Please try again.