From e62397c2bb3dff0981591fbd50177e4e142bb502 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Wed, 31 Dec 2014 13:04:42 -0200 Subject: [PATCH] Fix broken specs Fix specs on all gemfiles. Removed some specs related to version before of ActiveRecord 3.2. --- spec/active_record_helper.rb | 8 - spec/ext/active_record_spec.rb | 839 ++++++++++++++++++++----- spec/spec_helper.rb | 4 + spec/support/active_record_versions.rb | 26 + 4 files changed, 718 insertions(+), 159 deletions(-) create mode 100644 spec/support/active_record_versions.rb diff --git a/spec/active_record_helper.rb b/spec/active_record_helper.rb index 7a170f5..2a5207b 100644 --- a/spec/active_record_helper.rb +++ b/spec/active_record_helper.rb @@ -27,14 +27,6 @@ class SubUser < User; end # Helper methods # ############## -def activerecord_version - # ActiveRecord 4+ - return ActiveRecord.version.to_s if ActiveRecord.method_defined? :version - - # everything else - ActiveRecord::VERSION::STRING -end - # we only work with ActiveRecord 2+ def is_usable_activerecord? defined?(ActiveRecord::VERSION::MAJOR) && ActiveRecord::VERSION::MAJOR >= 2 diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index ccb682b..a9630f9 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -82,7 +82,133 @@ EOS it "display single record" do out = @ap.send(:awesome, @diana) - if activerecord_version >= "4.1" + if activerecord_4_2? + str = <<-EOS.strip +# false, + "created_at" => 1992-10-10 12:30:00 UTC, + "name" => "Diana", + "rank" => 1 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = false, + attr_reader :value_before_type_cast = false + >, + "created_at" => #, + attr_reader :value = 1992-10-10 12:30:00 UTC, + attr_reader :value_before_type_cast = "1992-10-10 12:30:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Diana", + attr_reader :value_before_type_cast = "Diana" + >, + "rank" => #, + attr_reader :value = 1, + attr_reader :value_before_type_cast = 1 + > + }, + @materialized = false, + @types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } +> +EOS + elsif activerecord_4_1? str = <<-EOS.strip # EOS - - # ActiveRecord 3.1 and on. - #-------------------------------------------------------------------------- - elsif activerecord_version >= "3.1" + elsif activerecord_4_0? + str = <<-EOS.strip + # #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @column_types_override = nil, + @destroyed = false, + @marked_for_destruction = false, + @new_record = true, + @previously_changed = {}, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = { + "admin" => false, + "created_at" => "1992-10-10 12:30:00", + "id" => nil, + "name" => "Diana", + "rank" => 1 + }, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } +> +EOS + elsif activerecord_3_2? str = <<-EOS.strip # false, "created_at" => "1992-10-10 12:30:00", @@ -209,53 +433,6 @@ EOS "created_at" => nil, "name" => nil, "rank" => nil - }, - attr_reader :mass_assignment_options = nil -> -EOS - # ActiveRecord 3.0.x - #-------------------------------------------------------------------------- - elsif activerecord_version.start_with?('3.0') - str = <<-EOS.strip -# false, - "created_at" => "?", - "name" => "Diana", - "rank" => 1 - }, - attr_reader :changed_attributes = { - "admin" => nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - } -> -EOS - # ActiveRecord 2.x - #-------------------------------------------------------------------------- - elsif activerecord_version.start_with?('2.') - str = <<-EOS.strip -# nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => false, - "created_at" => "1992-10-10 12:30:00", - "name" => "Diana", - "rank" => 1 } > EOS @@ -267,7 +444,258 @@ EOS it "display multiple records" do out = @ap.send(:awesome, [ @diana, @laura ]) - if activerecord_version >= "4.1" + if activerecord_4_2? + str = <<-EOS.strip +[ + [0] # false, + "created_at" => 1992-10-10 12:30:00 UTC, + "name" => "Diana", + "rank" => 1 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = false, + attr_reader :value_before_type_cast = false + >, + "created_at" => #, + attr_reader :value = 1992-10-10 12:30:00 UTC, + attr_reader :value_before_type_cast = "1992-10-10 12:30:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Diana", + attr_reader :value_before_type_cast = "Diana" + >, + "rank" => #, + attr_reader :value = 1, + attr_reader :value_before_type_cast = 1 + > + }, + @materialized = false, + @types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + >, + [1] # true, + "created_at" => 2003-05-26 14:15:00 UTC, + "name" => "Laura", + "rank" => 2 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = true, + attr_reader :value_before_type_cast = true + >, + "created_at" => #, + attr_reader :value = 2003-05-26 14:15:00 UTC, + attr_reader :value_before_type_cast = "2003-05-26 14:15:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Laura", + attr_reader :value_before_type_cast = "Laura" + >, + "rank" => #, + attr_reader :value = 2, + attr_reader :value_before_type_cast = 2 + > + }, + @materialized = false, + @types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + > +] +EOS + elsif activerecord_4_1? str = <<-EOS.strip [ [0] # ] EOS - elsif ActiveRecord::VERSION::STRING >= "3.1" + elsif activerecord_4_0? + str = <<-EOS.strip +[ + [0] # #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @column_types_override = nil, + @destroyed = false, + @marked_for_destruction = false, + @new_record = true, + @previously_changed = {}, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = { + "admin" => false, + "created_at" => "1992-10-10 12:30:00", + "id" => nil, + "name" => "Diana", + "rank" => 1 + }, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + >, + [1] # #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + @column_types_override = nil, + @destroyed = false, + @marked_for_destruction = false, + @new_record = true, + @previously_changed = {}, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = { + "admin" => true, + "created_at" => "2003-05-26 14:15:00", + "id" => nil, + "name" => "Laura", + "rank" => 2 + }, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + > +] +EOS + elsif activerecord_3_2? str = <<-EOS.strip [ [0] # false, "created_at" => "1992-10-10 12:30:00", @@ -491,18 +1120,17 @@ EOS "created_at" => nil, "name" => nil, "rank" => nil - }, - attr_reader :mass_assignment_options = nil + } >, [1] # true, "created_at" => "2003-05-26 14:15:00", @@ -516,93 +1144,6 @@ EOS "created_at" => nil, "name" => nil, "rank" => nil - }, - attr_reader :mass_assignment_options = nil - > -] -EOS - # ActiveRecord 3.0.x - #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('3.0') - str = <<-EOS.strip -[ - [0] # false, - "created_at" => "?", - "name" => "Diana", - "rank" => 1 - }, - attr_reader :changed_attributes = { - "admin" => nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - } - >, - [1] # true, - "created_at" => "?", - "name" => "Laura", - "rank" => 2 - }, - attr_reader :changed_attributes = { - "admin" => nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - } - > -] -EOS - # ActiveRecord 2.0.x - #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('2.') - str = <<-EOS.strip -[ - [0] # nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => false, - "created_at" => "1992-10-10 12:30:00", - "name" => "Diana", - "rank" => 1 - } - >, - [1] # nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => true, - "created_at" => "2003-05-26 14:15:00", - "name" => "Laura", - "rank" => 2 } > ] @@ -672,11 +1213,7 @@ EOS # spec 2 out = @ap.send(:awesome, User.methods.grep(/primary_key/)) - if activerecord_version >= "4.1" - expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/) - else - expect(out).to match(/\sprimary_key\(.*?\)\s+User/) - end + expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/) # spec 3 out = @ap.send(:awesome, User.methods.grep(/validate/)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3fb04c..1d4c779 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'awesome_print' +Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file| + require file +end + def stub_dotfile! dotfile = File.join(ENV["HOME"], ".aprc") expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false) diff --git a/spec/support/active_record_versions.rb b/spec/support/active_record_versions.rb new file mode 100644 index 0000000..4381361 --- /dev/null +++ b/spec/support/active_record_versions.rb @@ -0,0 +1,26 @@ +module ActiveRecordVersions + def activerecord_version + Gem::Version.new(ActiveRecord::VERSION::STRING) + end + + def activerecord_4_2? + Gem::Requirement.new('~> 4.2.0').satisfied_by?(activerecord_version) + end + + def activerecord_4_1? + Gem::Requirement.new('~> 4.1.0').satisfied_by?(activerecord_version) + end + + def activerecord_4_0? + Gem::Requirement.new('~> 4.0.0').satisfied_by?(activerecord_version) + end + + def activerecord_3_2? + Gem::Requirement.new('~> 3.2.0').satisfied_by?(activerecord_version) + end +end + +RSpec.configure do |config| + config.include(ActiveRecordVersions) + config.extend(ActiveRecordVersions) +end