mighty_grid 0.2.1 → 0.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -4
- data/Rakefile +0 -4
- data/lib/mighty_grid/base.rb +12 -3
- data/lib/mighty_grid/version.rb +1 -1
- data/spec/fake_app/models/active_record.rb +4 -2
- data/spec/lib/base_spec.rb +64 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7f9c3fe294d2ca3e018c9423d017080db7f0672
|
4
|
+
data.tar.gz: b4ee536a54684468aecaaa5637f6d95e026f2ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b8a28c2bef8f954d51dde1fc7f926ddd7952bb39aea2e7e14016d033cfb2a3d1a9f9e21995b59191904139221f34e6bd75fcd88814099ccd59563c5338e4c5
|
7
|
+
data.tar.gz: 1ca07348c0c9bca8cd89f9e0aa142717554ad9f5c7ba1b7bf94a0ef42a343dcb8b625ffab72d4e89a5a506de10f6000f8ff303989dfb4119d4754e7116dab04b
|
data/.travis.yml
CHANGED
@@ -6,10 +6,11 @@ rvm:
|
|
6
6
|
|
7
7
|
script: bundle exec rake spec
|
8
8
|
|
9
|
-
env:
|
10
|
-
CODECLIMATE_REPO_TOKEN: 47bc411a11ccfed015bf25395d8204600c899e530c1c4beed1b7197aa61c6fb6
|
11
|
-
|
12
9
|
gemfile:
|
13
10
|
- gemfiles/rails_32.gemfile
|
14
11
|
- gemfiles/rails_40.gemfile
|
15
|
-
- gemfiles/rails_41.gemfile
|
12
|
+
- gemfiles/rails_41.gemfile
|
13
|
+
|
14
|
+
addons:
|
15
|
+
code_climate:
|
16
|
+
repo_token: 47bc411a11ccfed015bf25395d8204600c899e530c1c4beed1b7197aa61c6fb6
|
data/Rakefile
CHANGED
data/lib/mighty_grid/base.rb
CHANGED
@@ -31,7 +31,7 @@ module MightyGrid
|
|
31
31
|
|
32
32
|
def read
|
33
33
|
apply_filters
|
34
|
-
@relation = @relation.order(@mg_params[:order] =>
|
34
|
+
@relation = @relation.order(@mg_params[:order] => current_order_direction.to_sym) if @mg_params[:order].present? && current_order_direction.present?
|
35
35
|
@relation = @relation.page(@mg_params[:page]).per(@mg_params[:per_page])
|
36
36
|
end
|
37
37
|
|
@@ -78,10 +78,19 @@ module MightyGrid
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def order_params(attribute)
|
81
|
-
|
81
|
+
direction = attribute.to_s == @mg_params[:order] ? another_order_direction : 'asc'
|
82
|
+
{@name => {order: attribute, order_direction: direction}}
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
85
|
+
def current_order_direction
|
86
|
+
direction = nil
|
87
|
+
if current_grid_params.has_key?('order_direction') && ['asc', 'desc'].include?(current_grid_params['order_direction'].downcase)
|
88
|
+
direction = current_grid_params['order_direction'].downcase
|
89
|
+
end
|
90
|
+
direction
|
91
|
+
end
|
92
|
+
|
93
|
+
def another_order_direction
|
85
94
|
(current_grid_params.has_key?('order_direction')) ? (['asc', 'desc'] - [current_grid_params['order_direction'].to_s]).first : MightyGrid.config.order_direction
|
86
95
|
end
|
87
96
|
|
data/lib/mighty_grid/version.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# MODELS
|
1
2
|
class Product < ActiveRecord::Base
|
2
3
|
end
|
3
4
|
|
4
|
-
#
|
5
|
+
# MIGRATIONS
|
5
6
|
class CreateAllTables < ActiveRecord::Migration
|
6
7
|
def self.up
|
7
|
-
create_table(:products) { |t| t.string :name }
|
8
|
+
create_table(:products) { |t| t.string :name; t.text :description }
|
8
9
|
end
|
9
10
|
end
|
11
|
+
|
10
12
|
ActiveRecord::Migration.verbose = false
|
11
13
|
CreateAllTables.up
|
data/spec/lib/base_spec.rb
CHANGED
@@ -19,23 +19,24 @@ describe MightyGrid::Base do
|
|
19
19
|
its(:relation) { should == Product }
|
20
20
|
its(:klass) { should == Product }
|
21
21
|
its(:current_grid_params) { should == {} }
|
22
|
-
its(:
|
22
|
+
its(:current_order_direction) { should == nil }
|
23
|
+
its(:another_order_direction) { should == 'asc' }
|
23
24
|
its(:filter_param_name) { should == 'f' }
|
24
25
|
context 'controller' do
|
25
|
-
it { instance_variable_get(:@controller).should
|
26
|
+
it { instance_variable_get(:@controller).should be_an_instance_of ActionView::TestCase::TestController }
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
context 'with custom' do
|
30
31
|
subject { MightyGrid::Base.new(Product, @controller, page: 2, per_page: 10, name: 'grid1') }
|
31
|
-
its(:options) { should ==
|
32
|
+
its(:options) { should == @default_options.merge(page: 2, per_page: 10, name: 'grid1') }
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'with custom' do
|
35
36
|
before(:all){ @controller.params = {'grid' => {page: 5, per_page: 30, name: 'grid2'}} }
|
36
37
|
subject { MightyGrid::Base.new(Product, @controller) }
|
37
38
|
its(:params) { should == @controller.params }
|
38
|
-
its(:mg_params) { should ==
|
39
|
+
its(:mg_params) { should == @default_options.merge(page: 5, per_page: 30, name: 'grid2') }
|
39
40
|
after(:all){ @controller.params = {} }
|
40
41
|
end
|
41
42
|
|
@@ -48,6 +49,65 @@ describe MightyGrid::Base do
|
|
48
49
|
before(:all){ @controller.params = {'grid'=>{per_page: 30}} }
|
49
50
|
subject { MightyGrid::Base.new(Product, @controller).get_current_grid_param(:per_page) }
|
50
51
|
it { should == 30 }
|
52
|
+
after(:all){ @controller.params = {} }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#current_order_direction' do
|
56
|
+
context 'with ASC controller param' do
|
57
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'asc'}} }
|
58
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
59
|
+
its(:current_order_direction) { should == 'asc' }
|
60
|
+
after(:all){ @controller.params = {} }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with DESC controller param' do
|
64
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'desc'}} }
|
65
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
66
|
+
its(:current_order_direction) { should == 'desc' }
|
67
|
+
after(:all){ @controller.params = {} }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with BAD controller param' do
|
71
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'bad'}} }
|
72
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
73
|
+
its(:current_order_direction) { should == nil }
|
74
|
+
after(:all){ @controller.params = {} }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#another_order_direction' do
|
79
|
+
context 'with ASC controller param' do
|
80
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'asc'}} }
|
81
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
82
|
+
its(:another_order_direction) { should == 'desc' }
|
83
|
+
after(:all){ @controller.params = {} }
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with DESC controller param' do
|
87
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'desc'}} }
|
88
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
89
|
+
its(:another_order_direction) { should == 'asc' }
|
90
|
+
after(:all){ @controller.params = {} }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with BAD controller param' do
|
94
|
+
before(:all){ @controller.params = {'grid'=>{'order_direction' => 'bad'}} }
|
95
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
96
|
+
its(:another_order_direction) { should == 'asc' }
|
97
|
+
after(:all){ @controller.params = {} }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#order_params' do
|
102
|
+
before(:all){ @controller.params = {'grid'=>{'order' => 'name', 'order_direction' => 'asc'}} }
|
103
|
+
subject { MightyGrid::Base.new(Product, @controller) }
|
104
|
+
context 'with current order attribute' do
|
105
|
+
it { subject.order_params(:name).should == {'grid'=>{order: :name, order_direction: 'desc'}} }
|
106
|
+
end
|
107
|
+
context 'with other order attribute' do
|
108
|
+
it { subject.order_params(:description).should == {'grid'=>{order: :description, order_direction: 'asc'}} }
|
109
|
+
end
|
110
|
+
after(:all){ @controller.params = {} }
|
51
111
|
end
|
52
112
|
|
53
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mighty_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jurrick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|