Skip to content

Commit

Permalink
Added changes to make the gem Rails 4 compatible
Browse files Browse the repository at this point in the history
1) Updated gemspec to allow Rails 4.x
2) Made changes to specs and Rakefile to allow them to run under Rails 4
3) Modified specs to eliminate a number of deprecation warnings
4) Updated the Gemfile and database.yml so that the specs run against multiple Rails versions, JRuby
5) Added a .travis.yml
6) Added another AR class in specs to allow the specs to run against Rails 3.1.x
  • Loading branch information
petergoldstein committed Jul 18, 2013
1 parent 3180e78 commit 826b9b7
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .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
33 changes: 27 additions & 6 deletions Gemfile
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion 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"
Expand Down
2 changes: 1 addition & 1 deletion active_enum.gemspec
Expand Up @@ -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<activesupport>, ["~> 3.0"])
s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
end
11 changes: 8 additions & 3 deletions spec/active_enum/acts_as_enum_spec.rb
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/active_enum/extensions_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/active_enum/form_helpers/formtastic2_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/active_enum/form_helpers/formtastic_spec.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/active_enum/form_helpers/simple_form_spec.rb
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/active_enum/storage/i18n_store_spec.rb
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/active_enum/storage/memory_store_spec.rb
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -8,6 +8,7 @@

require 'active_enum'
require 'active_enum/acts_as_enum'
require 'securerandom'

module ActiveEnum
class Application < Rails::Application
Expand All @@ -16,20 +17,22 @@ 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!

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
Expand Down
8 changes: 8 additions & 0 deletions spec/support/schema.rb
Expand Up @@ -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
Expand Down

0 comments on commit 826b9b7

Please sign in to comment.