sortables 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Sortables
2
2
 
3
- TODO: Write a gem description
3
+ Easily add sorting by an integer field on your ActiveRecord models
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'sortables'
9
+ ```ruby
10
+ gem 'sortables'
11
+ ```
10
12
 
11
13
  And then execute:
12
14
 
@@ -18,7 +20,14 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ ```ruby
24
+ # you need an integer field on your model called position
25
+ rails g migration AddPositionToMyModels position:integer
26
+
27
+ class MyModel < ActiveRecord::Base
28
+ sortable
29
+ end
30
+ ```
22
31
 
23
32
  ## Contributing
24
33
 
@@ -2,7 +2,7 @@ module Sortables
2
2
  module Sortable
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
- base.send(:default_scope, :order => :position)
5
+ base.send(:default_scope, :order => "#{base.table_name}.position")
6
6
  base.send(:before_create, :set_minimum_position)
7
7
  base.attr_accessible :position
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Sortables
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,9 +5,15 @@ class SomeSuchClass < ActiveRecord::Base
5
5
  sortable
6
6
  end
7
7
 
8
- class MigrateDatabase < ActiveRecord::Migration
9
- unless table_exists?('some_such_classes')
10
- create_table :some_such_classes do |t|
8
+ class SomeOtherClass < ActiveRecord::Base
9
+ sortable
10
+ end
11
+
12
+ migrator = ActiveRecord::Migration
13
+
14
+ %w(some_such_classes some_other_classes).each do |table_name|
15
+ unless migrator.table_exists?(table_name)
16
+ migrator.create_table table_name.to_sym do |t|
11
17
  t.integer :position
12
18
  end
13
19
  end
@@ -30,4 +36,8 @@ describe Sortables do
30
36
 
31
37
  @class.all.should == [obj2, obj]
32
38
  end
39
+
40
+ it "doesn't use ambiguous column references" do
41
+ SomeOtherClass.where('position IS NOT NULL').to_sql.should include("some_other_classes.position")
42
+ end
33
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-11-14 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 1.8.23
121
+ rubygems_version: 1.8.24
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: (hopefully) painless positional sorting