Permalink
Browse files

table_name is safe

  • Loading branch information...
1 parent 5a3a269 commit 507a46387df8ff2d906dae72b74d61c45bc3827a Aaron Lasseigne committed Feb 9, 2012
Showing with 11 additions and 11 deletions.
  1. +1 −1 lib/with_order/active_record_model_extension.rb
  2. +10 −10 spec/active_record_model_extension_spec.rb
@@ -49,7 +49,7 @@ def to_a
if field !~ /\./
if relation.column_names.include?(field)
- field = [self.table_name, field].map{|i| relation.connection.quote_column_name(i)}.join('.')
+ field = "#{self.table_name}.#{relation.connection.quote_column_name(field)}"
else
field = relation.connection.quote_column_name(field)
end
@@ -5,27 +5,27 @@
context 'orders using a field' do
it 'where the order is a hash containing :order' do
npw = NobelPrizeWinner.with_order({order: 'first_name-asc'})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
it 'where the order is a symbol' do
npw = NobelPrizeWinner.with_order(:first_name)
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
it 'where the order is a string' do
npw = NobelPrizeWinner.with_order('first_name-asc')
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
end
context 'limit the need for specifying table names to resolve ambiguity' do
it 'prepends the table name to the field if the field is in the primary table' do
npw = NobelPrizeWinner.joins(:nobel_prizes).with_order(:id)
- npw.order_values.should == ['"nobel_prize_winners"."id" ASC']
+ npw.order_values.should == ['nobel_prize_winners."id" ASC']
end
it 'skips fields where a table is already provided' do
@@ -41,13 +41,13 @@
it 'reverses order using a field' do
npw = NobelPrizeWinner.with_order({order: 'first_name-desc'})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should be true
end
it 'does not break the chain' do
npw = NobelPrizeWinner.with_order({order: 'first_name-asc'}).limit(1)
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
@@ -61,7 +61,7 @@
context 'order does not include a direction' do
it 'defaults to "ASC"' do
npw = NobelPrizeWinner.with_order({order: 'first_name'})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
end
@@ -91,21 +91,21 @@
context 'options include :default to select a default field to order by' do
it 'defaults to the field when no order is passed' do
npw = NobelPrizeWinner.with_order({}, {default: 'first_name-desc'})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should be true
end
it 'does not default to the field when a order is passed' do
npw = NobelPrizeWinner.with_order({order: 'first_name'}, {default: 'last_name'})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end
end
context 'the :param_namespace option is passed' do
it 'finds the :order param from the hash using the namespace' do
npw = NobelPrizeWinner.with_order({foo: {order: 'first_name'}}, {param_namespace: :foo})
- npw.order_values.should == ['"nobel_prize_winners"."first_name" ASC']
+ npw.order_values.should == ['nobel_prize_winners."first_name" ASC']
npw.reverse_order_value.should == nil
end

0 comments on commit 507a463

Please sign in to comment.