diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dc70c9e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +env: + - "RAILS_VERSION=3.1.0" + - "RAILS_VERSION=3.2.0" + - "RAILS_VERSION=4.0.0" + - "RAILS_VERSION=master" +rvm: + - 1.9.3 + - 2.0.0 diff --git a/Gemfile b/Gemfile index f8cc587..f7b2bde 100644 --- a/Gemfile +++ b/Gemfile @@ -2,14 +2,35 @@ source 'http://rubygems.org' gemspec -gem 'rake', '0.8.7' +rails_version = ENV["RAILS_VERSION"] || "default" + +rails = case rails_version +when "master" + {github: "rails/rails"} +when "default" + ">= 3.1.0" +else + "~> #{rails_version}" +end + +gem "rails", rails + +platforms :jruby do + gem 'jdbc-sqlite3', :require => false + gem 'activerecord-jdbc-adapter' + gem 'activerecord-jdbcsqlite3-adapter' +end + +platforms :ruby do + gem 'sqlite3' +end + +gem 'rake' gem 'ZenTest' -gem 'rails', "~> #{ENV['RAILS'] || '3.0.0'}" -gem 'sqlite3-ruby', '1.3.3', :require => 'sqlite3' -gem 'simple_form', '~> 1.3.0' +gem 'simple_form' gem 'formtastic', "~> #{ENV['FORMTASTIC'] || '2.0'}" gem 'ruby-debug', :platform => :ruby_18 gem 'debugger', :platform => :ruby_19 -gem 'rspec', '~> 2.4.0' -gem 'rspec-rails', '~> 2.4.0' +gem 'rspec', '~> 2.4' +gem 'rspec-rails', '~> 2.4' gem 'webrat' diff --git a/Rakefile b/Rakefile index 5d31ca4..80865c6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ require 'bundler' Bundler::GemHelper.install_tasks -require 'rake/rdoctask' +require 'rdoc/task' require 'rspec/core/rake_task' desc "Run specs" diff --git a/active_enum.gemspec b/active_enum.gemspec index 4966e10..8267f57 100644 --- a/active_enum.gemspec +++ b/active_enum.gemspec @@ -16,5 +16,5 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"] - s.add_runtime_dependency(%q, ["~> 3.0"]) + s.add_runtime_dependency(%q, [">= 3.0"]) end diff --git a/spec/active_enum/acts_as_enum_spec.rb b/spec/active_enum/acts_as_enum_spec.rb index 6c5c758..cee376b 100644 --- a/spec/active_enum/acts_as_enum_spec.rb +++ b/spec/active_enum/acts_as_enum_spec.rb @@ -13,9 +13,15 @@ class << self end end + class SortedPerson < ActiveRecord::Base + acts_as_enum :name_column => 'first_name', :order => :desc + end + before(:all) do Person.create!(:first_name => 'Dave', :last_name => 'Smith') Person.create!(:first_name => 'John', :last_name => 'Doe') + SortedPerson.create!(:first_name => 'Dave', :last_name => 'Smith') + SortedPerson.create!(:first_name => 'John', :last_name => 'Doe') end it "should mixin enum class methods only when act_as_enum defined" do @@ -41,8 +47,7 @@ class << self Person.to_select.should == [['Dave', 1], ['John', 2]] end - it "should return sorted array from order value for select helpers from to_select" do - Person.acts_as_enum :name_column => 'first_name', :order => :desc - Person.to_select.should == [['John', 2], ['Dave', 1]] + it "should return sorted array from order value for select helpers from to_select when an order is specified" do + SortedPerson.to_select.should == [['John', 2], ['Dave', 1]] end end diff --git a/spec/active_enum/extensions_spec.rb b/spec/active_enum/extensions_spec.rb index 7e5353c..49f0420 100644 --- a/spec/active_enum/extensions_spec.rb +++ b/spec/active_enum/extensions_spec.rb @@ -51,7 +51,7 @@ class Accepted < ActiveEnum::Base it 'should raise error if implicit enumeration class cannot be found' do expect { Person.enumerate :first_name - }.should raise_error(ActiveEnum::EnumNotFound) + }.to raise_error(ActiveEnum::EnumNotFound) end context "attribute" do diff --git a/spec/active_enum/form_helpers/formtastic2_spec.rb b/spec/active_enum/form_helpers/formtastic2_spec.rb index dcb7a34..7ef3b79 100644 --- a/spec/active_enum/form_helpers/formtastic2_spec.rb +++ b/spec/active_enum/form_helpers/formtastic2_spec.rb @@ -48,7 +48,7 @@ semantic_form_for(Person.new, :url => people_path) do |f| f.input(:attending, :as => :enum) end - }.should raise_error "Attribute 'attending' has no enum class" + }.to raise_error "Attribute 'attending' has no enum class" end it "should not use enum input type if class does not support ActiveEnum" do diff --git a/spec/active_enum/form_helpers/formtastic_spec.rb b/spec/active_enum/form_helpers/formtastic_spec.rb index 32f3cf4..354d644 100644 --- a/spec/active_enum/form_helpers/formtastic_spec.rb +++ b/spec/active_enum/form_helpers/formtastic_spec.rb @@ -51,7 +51,7 @@ semantic_form_for(Person.new, :url => people_path) do |f| f.input(:attending, :as => :enum) end - }.should raise_error "Attribute 'attending' has no enum class" + }.to raise_error "Attribute 'attending' has no enum class" end it "should not use enum input type if class does not support ActiveEnum" do diff --git a/spec/active_enum/form_helpers/simple_form_spec.rb b/spec/active_enum/form_helpers/simple_form_spec.rb index e7afad4..fd19fb4 100644 --- a/spec/active_enum/form_helpers/simple_form_spec.rb +++ b/spec/active_enum/form_helpers/simple_form_spec.rb @@ -7,7 +7,7 @@ include SimpleForm::ActionViewExtensions::FormHelper before do - controller.stub!(:action_name).and_return('new') + controller.stub(:action_name).and_return('new') reset_class Person do enumerate :sex do value :id => 1, :name => 'Male' @@ -46,7 +46,7 @@ simple_form_for(Person.new, :url => people_path) do |f| f.input(:attending, :as => :enum) end - }.should raise_error "Attribute 'attending' has no enum class" + }.to raise_error "Attribute 'attending' has no enum class" end it "should not use enum input type if class does not support ActiveEnum" do diff --git a/spec/active_enum/storage/i18n_store_spec.rb b/spec/active_enum/storage/i18n_store_spec.rb index 9912a56..d4f7033 100644 --- a/spec/active_enum/storage/i18n_store_spec.rb +++ b/spec/active_enum/storage/i18n_store_spec.rb @@ -39,21 +39,21 @@ class TestI18nStoreEnum < ActiveEnum::Base; end expect { store.set 1, 'Name 1' store.set 1, 'Other Name' - }.should raise_error(ActiveEnum::DuplicateValue) + }.to raise_error(ActiveEnum::DuplicateValue) end it 'should raise error if duplicate name' do expect { store.set 1, 'Name 1' store.set 2, 'Name 1' - }.should raise_error(ActiveEnum::DuplicateValue) + }.to raise_error(ActiveEnum::DuplicateValue) end it 'should not raise error if duplicate name with alternate case matches' do expect { store.set 1, 'Name 1' store.set 2, 'name 1' - }.should_not raise_error(ActiveEnum::DuplicateValue) + }.not_to raise_error() end end diff --git a/spec/active_enum/storage/memory_store_spec.rb b/spec/active_enum/storage/memory_store_spec.rb index e309a99..638f962 100644 --- a/spec/active_enum/storage/memory_store_spec.rb +++ b/spec/active_enum/storage/memory_store_spec.rb @@ -21,21 +21,21 @@ class TestOtherAREnum < ActiveEnum::Base; end expect { store.set 1, 'Name 1' store.set 1, 'Other Name' - }.should raise_error(ActiveEnum::DuplicateValue) + }.to raise_error(ActiveEnum::DuplicateValue) end it 'should raise error if duplicate name' do expect { store.set 1, 'Name 1' store.set 2, 'Name 1' - }.should raise_error(ActiveEnum::DuplicateValue) + }.to raise_error(ActiveEnum::DuplicateValue) end it 'should raise error if duplicate name matches title-case name' do expect { store.set 1, 'Name 1' store.set 2, 'name 1' - }.should raise_error(ActiveEnum::DuplicateValue) + }.to raise_error(ActiveEnum::DuplicateValue) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 49a4348..4c92897 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,7 @@ require 'active_enum' require 'active_enum/acts_as_enum' +require 'securerandom' module ActiveEnum class Application < Rails::Application @@ -16,6 +17,8 @@ class Application < Rails::Application g.test_framework :rspec, :fixture => false end config.active_support.deprecation = :notify + config.eager_load = false if Rails.version >= "4.0" + config.secret_key_base = SecureRandom.hex(10) if Rails.version >= "4.0" end end ActiveEnum::Application.initialize! @@ -23,13 +26,13 @@ class Application < Rails::Application require 'rspec/rails' ActiveRecord::Migration.verbose = false -ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'}) +ActiveRecord::Base.establish_connection({:adapter => "#{'jdbc' if defined? JRUBY_VERSION}sqlite3", :database => ':memory:'}) require 'support/schema' class Person < ActiveRecord::Base; end class NoEnumPerson < ActiveRecord::Base - set_table_name 'people' + self.table_name = 'people' end class NotActiveRecord diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 9eb1aaf..68c73d3 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -7,6 +7,14 @@ t.integer :staying end + create_table :sorted_people, :force => true do |t| + t.string :first_name + t.string :last_name + t.integer :sex + t.integer :attending + t.integer :staying + end + create_table :sexes, :force => true do |t| t.string :name end