Skip to content

Commit

Permalink
add failing spec and fix rails version check
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Apr 11, 2014
1 parent f630fb0 commit e0ff956
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/formtastic/util.rb
Expand Up @@ -38,7 +38,11 @@ def rails4_1?
end

def deprecated_version_of_rails?
const_defined?(:Rails) && ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR < 2 && ::Rails::VERSION::PATCH < 13
const_defined?(:Rails) && rails_version < Gem::Version.new("3.2.13")
end

def rails_version
Gem::Version.new(::Rails::VERSION::STRING)
end

end
Expand Down
59 changes: 59 additions & 0 deletions spec/util_spec.rb
@@ -0,0 +1,59 @@
# encoding: utf-8
require 'spec_helper'

describe 'Formtastic::Util' do

describe '.deprecated_version_of_rails?' do

subject { Formtastic::Util.deprecated_version_of_rails? }

context '3.0.0' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.0.0") } }
it 'should be true' do
expect(subject).to be_true
end
end

context '3.1.0' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.1.0") } }
it 'should be true' do
expect(subject).to be_true
end
end

context '3.2.12' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.2.12") } }
it 'should be true' do
expect(subject).to be_true
end
end

context '3.2.13' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.2.13") } }
it 'should be true' do
expect(subject).to be_false
end
end

context '3.2.14' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.2.14") } }
it 'should be true' do
expect(subject).to be_false
end
end

context '3.3.0' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("3.3.0") } }
it 'should be true' do
expect(subject).to be_false
end
end

context '4.0.0' do
before { allow(Formtastic::Util).to receive(:rails_version) { Gem::Version.new("4.0.0") } }
it 'should be true' do
expect(subject).to be_false
end
end
end
end

0 comments on commit e0ff956

Please sign in to comment.