wice_grid_mongoid 6.0.5 → 6.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.5
1
+ 6.0.6
@@ -83,6 +83,13 @@ module Wice
83
83
  Wice.log "invalid parameters for the grid string filter - empty string"
84
84
  return false
85
85
  end
86
+ if string_fragment.starts_with?('/')
87
+ string_fragment = string_fragment[1..-1]
88
+ else
89
+ special_chars = '|()[]{}+\^$*?.'
90
+ string_fragment = string_fragment.gsub( /([\|\(\)\[\]\{\}\+\^\\\$\*\?\.])/ ) { |s| '\\' + s}
91
+ end
92
+
86
93
  @criteria.where(@field.name.to_s => /#{string_fragment}/)
87
94
  return true
88
95
  end
@@ -121,7 +128,7 @@ module Wice
121
128
  when 'g': num * 1024*1024*1024
122
129
  when 'm': num * 1024*1024
123
130
  when 'k': num * 1024
124
- end if match_data.size > 3
131
+ end if match_data[3]
125
132
  num
126
133
  end
127
134
  end
@@ -750,7 +750,7 @@ module Wice
750
750
 
751
751
  def pagination_info(grid, allow_showing_all_records) #:nodoc:
752
752
  found = grid.resultset.count
753
- total = grid.extra_filter.count
753
+ total = grid.extra_filter ? grid.extra_filter.count : grid.klass.count
754
754
  shown = [found, grid.status[:per_page].to_i].min
755
755
  summary = ""
756
756
  summary << "Shown: #{shown}"
data/test/blueprint.rb CHANGED
@@ -10,6 +10,7 @@ User.blueprint do
10
10
  last_login { Time.parse('1980-01-01 11:00')}
11
11
  computers_number { 1 }
12
12
  archived { false }
13
+ storage_limit { 10*1024*1024*1024 }
13
14
  end
14
15
 
15
16
  Computer.blueprint do
@@ -8,8 +8,8 @@ describe UsersController do
8
8
  @aa = User.make(:first_name => 'aabbcc', :year => Time.parse('1980-01-01'), :archived => true)
9
9
  @bb = User.make(:first_name => 'bbccdd', :year => Time.parse('1990-01-01'), :last_login => Time.parse('2010-01-01 4pm'))
10
10
  @cc = User.make(:first_name => 'ccddee', :year => Time.parse('2000-01-01'), :computers_number => 3)
11
- Computer.make(:user_id => @aa.id, :name => "aa_host_1")
12
- Computer.make(:user_id => @aa.id, :name => "aa_host_2")
11
+ @c1 = Computer.make(:user_id => @aa.id, :name => "aa_host_1")
12
+ @c2 = Computer.make(:user_id => @aa.id, :name => "aa_host_2")
13
13
  end
14
14
 
15
15
  it "should render grid as table" do
@@ -77,7 +77,43 @@ describe UsersController do
77
77
  first_name_column = all('tbody td[1]').map(&:text)
78
78
  first_name_column.size.should == 1
79
79
  end
80
+
81
+ it "should be possible to use K,M,G,KB,MB,GB in Integer filters" do
82
+ UsersController.columns do |grid|
83
+ grid.column :column_name => 'Storage Limit', :attribute_name => 'storage_limit'
84
+ end
85
+
86
+ visit '/users?grid[f][storage_limit][fr]=1K&grid[f][storage_limit][to]=5K'
87
+ first_name_column = all('tbody td[1]').map(&:text)
88
+ first_name_column.size.should == 0
89
+
90
+ visit '/users?grid[f][storage_limit][fr]=1Mb&grid[f][storage_limit][to]=200M'
91
+ first_name_column = all('tbody td[1]').map(&:text)
92
+ first_name_column.size.should == 0
93
+
94
+ visit '/users?grid[f][storage_limit][fr]=500mb&grid[f][storage_limit][to]=20G'
95
+ first_name_column = all('tbody td[1]').map(&:text)
96
+ first_name_column.size.should == 3
97
+ end
80
98
 
99
+ it "should be possible to use '/' for String fields to indicate regexp" do
100
+ UsersController.columns do |grid|
101
+ grid.column :column_name => 'First Name', :attribute_name => 'first_name'
102
+ end
103
+ visit '/users'
104
+ filter_string = '/c.*e'
105
+ fill_in "grid[f][first_name]", :with => filter_string
106
+ visit "/users?grid[f][first_name][v]=#{URI.escape(filter_string)}&grid[f][first_name][n]=#{URI.escape(filter_string)}"
107
+ first_name_column = all('tbody td[1]').map(&:text)
108
+ first_name_column.size.should == 1
109
+
110
+ filter_string = 'c.*e'
111
+ fill_in "grid[f][first_name]", :with => filter_string
112
+ visit "/users?grid[f][first_name][v]=#{URI.escape(filter_string)}&grid[f][first_name][n]=#{URI.escape(filter_string)}"
113
+ first_name_column = all('tbody td[1]').map(&:text)
114
+ first_name_column.size.should == 0
115
+ end
116
+
81
117
  it "should be possible to see Boolean filters and use them" do
82
118
  UsersController.columns do |grid|
83
119
  grid.column :column_name => 'Archived', :attribute_name => 'archived'
@@ -24,6 +24,7 @@ class User
24
24
  field :last_login, :type => Time
25
25
  field :computers_number, :type => Integer
26
26
  field :archived, :type => Boolean
27
+ field :storage_limit, :type => Integer
27
28
 
28
29
  def self.merge_conditions(*conditions)
29
30
  ""
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wice_grid_mongoid}
8
- s.version = "6.0.5"
8
+ s.version = "6.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yuri Leikind", "Aleksandr Furmanov"]
12
- s.date = %q{2010-12-10}
12
+ s.date = %q{2010-12-13}
13
13
  s.description = %q{A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters }
14
14
  s.email = %q{aleksandr.furmanov@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wice_grid_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 6
8
8
  - 0
9
- - 5
10
- version: 6.0.5
9
+ - 6
10
+ version: 6.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yuri Leikind
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-10 00:00:00 -08:00
19
+ date: 2010-12-13 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies: []
22
22