mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix almost all Ruby warnings during spec suite
This commit is contained in:
parent
6690e3c007
commit
927d8b8cde
10 changed files with 36 additions and 19 deletions
|
@ -2,7 +2,7 @@ module Arel
|
|||
module ClassExtensions
|
||||
def attributes(*attrs)
|
||||
@attributes = attrs
|
||||
attr_reader *attrs
|
||||
attr_reader(*attrs)
|
||||
end
|
||||
|
||||
def deriving(*methods)
|
||||
|
|
|
@ -5,16 +5,22 @@ module Arel
|
|||
alias_method :manufacture, :new
|
||||
|
||||
def start
|
||||
if @started
|
||||
if defined?(@started) && @started
|
||||
yield
|
||||
else
|
||||
begin
|
||||
@started = true
|
||||
@instance = manufacture
|
||||
metaclass.send :alias_method, :new, :instance
|
||||
metaclass.class_eval do
|
||||
undef :new
|
||||
alias_method :new, :instance
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
metaclass.send :alias_method, :new, :manufacture
|
||||
metaclass.class_eval do
|
||||
undef :new
|
||||
alias_method :new, :manufacture
|
||||
end
|
||||
@started = false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Arel
|
|||
|
||||
describe '==' do
|
||||
it "obtains if attribute1 and attribute2 are identical" do
|
||||
Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2)
|
||||
check Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2)
|
||||
Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1)
|
||||
end
|
||||
|
||||
|
|
|
@ -73,10 +73,8 @@ module Arel
|
|||
|
||||
describe 'when dividing two matching attributes' do
|
||||
it 'returns a the highest score for the most similar attributes' do
|
||||
(@aliased_relation[:id] / @relation[:id]) \
|
||||
.should == (@aliased_relation[:id] / @relation[:id])
|
||||
(@aliased_relation[:id] / @relation[:id]) \
|
||||
.should < (@aliased_relation[:id] / @aliased_relation[:id])
|
||||
check((@aliased_relation[:id] / @relation[:id]).should == (@aliased_relation[:id] / @relation[:id]))
|
||||
(@aliased_relation[:id] / @relation[:id]).should < (@aliased_relation[:id] / @aliased_relation[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Arel
|
|||
|
||||
describe '==' do
|
||||
it "obtains if the objects are the same" do
|
||||
Alias.new(@relation).should_not == Alias.new(@relation)
|
||||
check Alias.new(@relation).should_not == Alias.new(@relation)
|
||||
(aliaz = Alias.new(@relation)).should == aliaz
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,8 +17,8 @@ module Arel
|
|||
|
||||
describe 'when given a', Symbol, String do
|
||||
it "returns the attribute with the same name, if it exists" do
|
||||
@relation[:id].should == @attribute1
|
||||
@relation['id'].should == @attribute1
|
||||
check @relation[:id].should == @attribute1
|
||||
check @relation['id'].should == @attribute1
|
||||
@relation[:does_not_exist].should be_nil
|
||||
end
|
||||
end
|
||||
|
@ -180,7 +180,7 @@ module Arel
|
|||
|
||||
describe Relation::Enumerable do
|
||||
it "implements enumerable" do
|
||||
@relation.collect.should == @relation.session.read(@relation).collect
|
||||
check @relation.collect.should == @relation.session.read(@relation).collect
|
||||
@relation.first.should == @relation.session.read(@relation).first
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Arel
|
|||
describe '[]' do
|
||||
describe 'when given a', Symbol do
|
||||
it "manufactures an attribute if the symbol names an attribute within the relation" do
|
||||
@relation[:id].should == Attribute.new(@relation, :id)
|
||||
check @relation[:id].should == Attribute.new(@relation, :id)
|
||||
@relation[:does_not_exist].should be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,15 +2,16 @@ require 'spec_helper'
|
|||
|
||||
module Arel
|
||||
describe Binary do
|
||||
class ConcreteBinary < Binary
|
||||
def predicate_sql
|
||||
"<=>"
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
@relation = Table.new(:users)
|
||||
@attribute1 = @relation[:id]
|
||||
@attribute2 = @relation[:name]
|
||||
class ConcreteBinary < Binary
|
||||
def predicate_sql
|
||||
"<=>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with compound predicates" do
|
||||
|
|
|
@ -3,18 +3,22 @@ class Hash
|
|||
to_a.sort { |(key1, value1), (key2, value2)| key1.hash <=> key2.hash }
|
||||
end
|
||||
|
||||
undef :keys
|
||||
def keys
|
||||
ordered_array.collect(&:first)
|
||||
end
|
||||
|
||||
undef :values
|
||||
def values
|
||||
ordered_array.collect { |_, v| v }
|
||||
end
|
||||
|
||||
undef :each
|
||||
def each(&block)
|
||||
ordered_array.each(&block)
|
||||
end
|
||||
|
||||
undef :shift
|
||||
def shift
|
||||
returning to_a.first do |k, v|
|
||||
delete(k)
|
||||
|
|
|
@ -37,9 +37,17 @@ module AdapterGuards
|
|||
end
|
||||
end
|
||||
|
||||
module Check
|
||||
# This is used to eliminate Ruby warnings on some RSpec assertion lines
|
||||
# See: https://rspec.lighthouseapp.com/projects/5645/tickets/504
|
||||
def check(*args)
|
||||
end
|
||||
end
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
config.include BeLikeMatcher, HashTheSameAsMatcher, DisambiguateAttributesMatcher
|
||||
config.include AdapterGuards
|
||||
config.include Check
|
||||
config.mock_with :rr
|
||||
config.before do
|
||||
Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)
|
||||
|
|
Loading…
Reference in a new issue