From e0ff956ef2947fc00e76802e9819a18cf3221990 Mon Sep 17 00:00:00 2001 From: Justin French Date: Fri, 11 Apr 2014 20:54:53 +1000 Subject: [PATCH] add failing spec and fix rails version check --- lib/formtastic/util.rb | 6 ++++- spec/util_spec.rb | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/util_spec.rb diff --git a/lib/formtastic/util.rb b/lib/formtastic/util.rb index 14e83792b..a0c04256f 100644 --- a/lib/formtastic/util.rb +++ b/lib/formtastic/util.rb @@ -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 diff --git a/spec/util_spec.rb b/spec/util_spec.rb new file mode 100644 index 000000000..6f7ae797c --- /dev/null +++ b/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