positionable 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/positionable.rb CHANGED
@@ -66,7 +66,7 @@ module Positionable
66
66
  start = options[:start] || 0
67
67
  order = options[:order] || :asc
68
68
 
69
- default_scope order("\"#{self.table_name}\".\"position\" #{order}")
69
+ default_scope order("`#{self.table_name}`.`position` #{order}")
70
70
 
71
71
  before_create :add_to_bottom
72
72
  before_update :update_position
@@ -1,3 +1,3 @@
1
1
  module Positionable
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -28,7 +28,7 @@ describe Positionable do
28
28
  it "prepends the table name in SQL 'order by' clause" do
29
29
  sql = DefaultItem.where("1 = 1").to_sql
30
30
  table = DefaultItem.table_name
31
- sql.should include("ORDER BY \"#{table}\".\"position\"")
31
+ sql.should include("ORDER BY `#{table}`.`position`")
32
32
  end
33
33
 
34
34
  context "inheritance" do
@@ -49,7 +49,7 @@ describe Positionable do
49
49
  it "orders records by their position by default" do
50
50
  shuffle_positions = (0..9).to_a.shuffle
51
51
  shuffle_positions.each do |position|
52
- item = Factory.create(:default_item)
52
+ item = FactoryGirl.create(:default_item)
53
53
  item.update_column(:position, position)
54
54
  end
55
55
  DefaultItem.all.should be_contiguous.starting_at(0)
@@ -67,7 +67,7 @@ describe Positionable do
67
67
  end
68
68
 
69
69
  it "increments position by one after creation" do
70
- item = Factory.create(:default_item)
70
+ item = FactoryGirl.create(:default_item)
71
71
  item.position.should == items.last.position + 1
72
72
  end
73
73
 
@@ -167,9 +167,9 @@ describe Positionable do
167
167
  context "inheritance" do
168
168
 
169
169
  it "inserts contiguously records of all subclasses" do
170
- Factory.create(:sub_item_1).position.should == items.count
171
- Factory.create(:sub_item_2).position.should == items.count + 1
172
- Factory.create(:sub_item_1).position.should == items.count + 2
170
+ FactoryGirl.create(:sub_item_1).position.should == items.count
171
+ FactoryGirl.create(:sub_item_2).position.should == items.count + 1
172
+ FactoryGirl.create(:sub_item_1).position.should == items.count + 2
173
173
  end
174
174
 
175
175
  end
@@ -259,7 +259,7 @@ describe Positionable do
259
259
  let!(:items) { FactoryGirl.create_list(:default_item, 10) }
260
260
 
261
261
  it "gives the range position of a new record" do
262
- item = Factory.build(:default_item)
262
+ item = FactoryGirl.build(:default_item)
263
263
  item.range.should == (0..items.count)
264
264
  end
265
265
 
@@ -294,7 +294,7 @@ describe Positionable do
294
294
  it "increments position by one after creation inside a folder" do
295
295
  folders.each do |folder|
296
296
  last_position = folder.documents.last.position
297
- document = Factory.create(:document, :folder => folder)
297
+ document = FactoryGirl.create(:document, :folder => folder)
298
298
  document.position.should == last_position + 1
299
299
  end
300
300
  end
@@ -438,7 +438,7 @@ describe Positionable do
438
438
  # Last document is a special case when changing scope, so it is avoided
439
439
  let!(:document) { old_folder.documents.but_last.sample }
440
440
  # A new folder containing a different count of documents than the old folder
441
- let!(:new_folder) { Factory.create(:folder) }
441
+ let!(:new_folder) { FactoryGirl.create(:folder) }
442
442
  let!(:new_documents) { FactoryGirl.create_list(:document, old_folder.documents.count + 1, :folder => new_folder) }
443
443
 
444
444
  it "moves to bottom position when scope has changed but position is out of range" do
@@ -472,27 +472,27 @@ describe Positionable do
472
472
  end
473
473
 
474
474
  it "gives the range within a scope" do
475
- folder = Factory.create(:folder_with_documents)
475
+ folder = FactoryGirl.create(:folder_with_documents)
476
476
  document = Document.new
477
477
  document.range(folder).should == (0..folder.documents.count)
478
478
  end
479
479
 
480
480
  it "gives the range within its own scope by default" do
481
- folder = Factory.create(:folder_with_documents)
481
+ folder = FactoryGirl.create(:folder_with_documents)
482
482
  document = folder.documents.sample
483
483
  document.range.should == (0..(folder.documents.count - 1))
484
484
  end
485
485
 
486
486
  it "gives the range within another scope" do
487
- document = Factory.build(:document)
488
- folder = Factory.create(:folder_with_documents)
487
+ document = FactoryGirl.build(:document)
488
+ folder = FactoryGirl.create(:folder_with_documents)
489
489
  document.folder.should_not == folder # Meta!
490
490
  document.range(folder).should == (0..folder.documents.count)
491
491
  end
492
492
 
493
493
  it "gives the range within another empty scope" do
494
- document = Factory.build(:document)
495
- folder = Factory.create(:folder)
494
+ document = FactoryGirl.build(:document)
495
+ folder = FactoryGirl.create(:folder)
496
496
  document.folder.should_not == folder # Meta!
497
497
  folder.documents.should be_empty # Meta!
498
498
  document.range(folder).should == (0..0)
@@ -503,14 +503,14 @@ describe Positionable do
503
503
  context "existing record" do
504
504
 
505
505
  it "gives the range within its own scope" do
506
- folder = Factory.create(:folder_with_documents)
506
+ folder = FactoryGirl.create(:folder_with_documents)
507
507
  document = folder.documents.sample
508
508
  document.range(folder).should == (0..(folder.documents.count - 1))
509
509
  end
510
510
 
511
511
  it "gives the range within another scope" do
512
- document = Factory.create(:document)
513
- folder = Factory.create(:folder_with_documents)
512
+ document = FactoryGirl.create(:document)
513
+ folder = FactoryGirl.create(:folder_with_documents)
514
514
  document.folder.should_not == folder # Meta!
515
515
  document.range(folder).should == (0..folder.documents.count)
516
516
  end
@@ -526,13 +526,13 @@ describe Positionable do
526
526
  let(:start) { 1 }
527
527
 
528
528
  it "starts at the given position" do
529
- item = Factory.create(:starting_at_one_item)
529
+ item = FactoryGirl.create(:starting_at_one_item)
530
530
  item.position.should == start
531
531
  end
532
532
 
533
533
  it "increments by one the given start position" do
534
534
  items = FactoryGirl.create_list(:starting_at_one_item, 5)
535
- item = Factory.create(:starting_at_one_item)
535
+ item = FactoryGirl.create(:starting_at_one_item)
536
536
  item.position.should == items.size + start
537
537
  end
538
538
 
@@ -581,7 +581,7 @@ describe Positionable do
581
581
 
582
582
  it "appends at the last position" do
583
583
  items = FactoryGirl.create_list(:asc_item, 5)
584
- item = Factory.create(:asc_item)
584
+ item = FactoryGirl.create(:asc_item)
585
585
  item.position.should == items.size
586
586
  end
587
587
 
@@ -598,7 +598,7 @@ describe Positionable do
598
598
 
599
599
  it "appends at the last position" do
600
600
  items = FactoryGirl.create_list(:desc_item, 5)
601
- item = Factory.create(:desc_item)
601
+ item = FactoryGirl.create(:desc_item)
602
602
  item.position.should == items.size
603
603
  end
604
604
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: positionable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-14 00:00:00.000000000 Z
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler