datagrid 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -6
  3. data/VERSION +1 -1
  4. data/app/views/datagrid/_form.html.erb +3 -1
  5. data/datagrid.gemspec +6 -6
  6. data/lib/datagrid.rb +1 -0
  7. data/lib/datagrid/columns.rb +14 -7
  8. data/lib/datagrid/columns/column.rb +7 -4
  9. data/lib/datagrid/renderer.rb +1 -1
  10. data/spec/datagrid/active_model_spec.rb +4 -4
  11. data/spec/datagrid/column_names_attribute_spec.rb +15 -11
  12. data/spec/datagrid/columns_spec.rb +80 -62
  13. data/spec/datagrid/core_spec.rb +6 -6
  14. data/spec/datagrid/drivers/active_record_spec.rb +4 -4
  15. data/spec/datagrid/drivers/array_spec.rb +41 -8
  16. data/spec/datagrid/drivers/mongo_mapper_spec.rb +42 -10
  17. data/spec/datagrid/drivers/mongoid_spec.rb +43 -11
  18. data/spec/datagrid/filters/composite_filters_spec.rb +12 -12
  19. data/spec/datagrid/filters/date_filter_spec.rb +25 -25
  20. data/spec/datagrid/filters/date_time_filter_spec.rb +20 -20
  21. data/spec/datagrid/filters/dynamic_filter_spec.rb +43 -43
  22. data/spec/datagrid/filters/enum_filter_spec.rb +6 -6
  23. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +10 -10
  24. data/spec/datagrid/filters/float_filter_spec.rb +2 -2
  25. data/spec/datagrid/filters/integer_filter_spec.rb +34 -34
  26. data/spec/datagrid/filters/string_filter_spec.rb +7 -7
  27. data/spec/datagrid/filters_spec.rb +20 -20
  28. data/spec/datagrid/form_builder_spec.rb +5 -5
  29. data/spec/datagrid/helper_spec.rb +41 -40
  30. data/spec/datagrid/ordering_spec.rb +22 -22
  31. data/spec/datagrid/scaffold_spec.rb +2 -2
  32. data/spec/datagrid/utils_spec.rb +3 -3
  33. data/spec/datagrid_spec.rb +10 -7
  34. data/spec/support/matchers.rb +6 -3
  35. metadata +30 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87a528983e7fd2ef73cf521c573fec464b5461cb
4
- data.tar.gz: f74b44092e5cb1b1c5c076514c655c6874729f45
3
+ metadata.gz: 8352c27cddb180b596755bfed2473efec0f3623b
4
+ data.tar.gz: 8f92c23740b35d281c71928e447a1d42d67b8270
5
5
  SHA512:
6
- metadata.gz: 5a60e18d5454ad9dabc58d4c367b5b93b1d589d6c4a5dc6aa8d2a7836b4046c587a21fdd694c1553f5746fb4c6b76851fb95a38d8062a6a1cb993e6f06081ff0
7
- data.tar.gz: 09c2cc3b93a3387d1b36eb09bf42c226eeab2bb363ae0ea7db00280d38136b330f1c39bca03441b3969519f4526f413e86dfa8382f9c1b358e28138002b414a5
6
+ metadata.gz: 57916c7c0bfc053923738af1b61db8b617a1088c193d58e5908286da2a190f5f1b0d7e926c068cb157cc16f791c7e33ccb8333fe8c938028cada3634efa6b993
7
+ data.tar.gz: 00327aa061682b9f47178ca95650e36506a7e51d67bb37966f81c40ba885136d3fbc83f02656e9020701129f6323cde72d120e1756cb42d560b89f9ecafd4356
data/Gemfile CHANGED
@@ -15,12 +15,14 @@ group :development do
15
15
  gem "rspec"
16
16
  gem "nokogiri" # used to test html output
17
17
 
18
- gem "sqlite3-ruby"
19
-
20
- gem "mongoid", "2.2.2"
21
- gem "mongo_mapper", ">=0.11.0"
22
- gem "bson", "1.4.0"
23
- gem "bson_ext", "1.4.0"
18
+ gem "sqlite3"
19
+
20
+ group :mongo do
21
+ gem "mongoid", "2.2.2"
22
+ gem "mongo_mapper", ">=0.11.0"
23
+ gem "bson", "1.4.0"
24
+ gem "bson_ext", "1.4.0"
25
+ end
24
26
 
25
27
  gem "fastercsv", :platform => "mri_18"
26
28
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -7,6 +7,8 @@
7
7
  <% end %>
8
8
  <div class="datagrid-actions">
9
9
  <%= f.submit I18n.t("datagrid.form.search").html_safe, :class => "datagrid-submit" %>
10
- <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), :class => "datagrid-reset" %>
10
+ <%# https://github.com/rails/rails/pull/14949 -%>
11
+ <% empty_parameter = Rails.version >= "4.1.0" && Rails.version <= '4.1.2' ? nil : {}-%>
12
+ <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => empty_parameter), :class => "datagrid-reset" %>
11
13
  </div>
12
14
  <% end -%>
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.2.0 ruby lib
5
+ # stub: datagrid 1.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid"
9
- s.version = "1.2.0"
9
+ s.version = "1.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Bogdan Gusiev"]
14
- s.date = "2014-05-10"
14
+ s.date = "2014-05-19"
15
15
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
16
16
  s.email = "agresso@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -132,7 +132,7 @@ Gem::Specification.new do |s|
132
132
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
133
133
  s.add_development_dependency(%q<rspec>, [">= 0"])
134
134
  s.add_development_dependency(%q<nokogiri>, [">= 0"])
135
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
135
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
136
136
  s.add_development_dependency(%q<mongoid>, ["= 2.2.2"])
137
137
  s.add_development_dependency(%q<mongo_mapper>, [">= 0.11.0"])
138
138
  s.add_development_dependency(%q<bson>, ["= 1.4.0"])
@@ -147,7 +147,7 @@ Gem::Specification.new do |s|
147
147
  s.add_dependency(%q<ruby-debug>, [">= 0"])
148
148
  s.add_dependency(%q<rspec>, [">= 0"])
149
149
  s.add_dependency(%q<nokogiri>, [">= 0"])
150
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
150
+ s.add_dependency(%q<sqlite3>, [">= 0"])
151
151
  s.add_dependency(%q<mongoid>, ["= 2.2.2"])
152
152
  s.add_dependency(%q<mongo_mapper>, [">= 0.11.0"])
153
153
  s.add_dependency(%q<bson>, ["= 1.4.0"])
@@ -163,7 +163,7 @@ Gem::Specification.new do |s|
163
163
  s.add_dependency(%q<ruby-debug>, [">= 0"])
164
164
  s.add_dependency(%q<rspec>, [">= 0"])
165
165
  s.add_dependency(%q<nokogiri>, [">= 0"])
166
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
166
+ s.add_dependency(%q<sqlite3>, [">= 0"])
167
167
  s.add_dependency(%q<mongoid>, ["= 2.2.2"])
168
168
  s.add_dependency(%q<mongo_mapper>, [">= 0.11.0"])
169
169
  s.add_dependency(%q<bson>, ["= 1.4.0"])
@@ -38,6 +38,7 @@ module Datagrid
38
38
 
39
39
  class ConfigurationError < StandardError; end
40
40
  class ArgumentError < ::ArgumentError; end
41
+ class ColumnUnavailableError < StandardError; end
41
42
 
42
43
  end
43
44
 
@@ -217,6 +217,7 @@ module Datagrid
217
217
  end
218
218
 
219
219
  def find_column_by_name(columns,name) #:nodoc:
220
+ return name if name.is_a?(Datagrid::Columns::Column)
220
221
  columns.find do |col|
221
222
  col.name.to_sym == name.to_sym
222
223
  end
@@ -246,7 +247,7 @@ module Datagrid
246
247
  # * <tt>column_names</tt> - list of column names if you want to limit data only to specified columns
247
248
  def row_for(asset, *column_names)
248
249
  data_columns(*column_names).map do |column|
249
- column.data_value(asset, self)
250
+ data_value(column, asset)
250
251
  end
251
252
  end
252
253
 
@@ -254,7 +255,7 @@ module Datagrid
254
255
  def hash_for(asset)
255
256
  result = {}
256
257
  self.data_columns.each do |column|
257
- result[column.name] = column.data_value(asset, self)
258
+ result[column.name] = data_value(column, asset)
258
259
  end
259
260
  result
260
261
  end
@@ -436,6 +437,16 @@ module Datagrid
436
437
  end
437
438
  end
438
439
 
440
+ # Return a cell data value for given column name and asset
441
+ def data_value(column_name, asset)
442
+ column_by_name(column_name).data_value(asset, self)
443
+ end
444
+
445
+ # Return a cell HTML value for given column name and asset and view context
446
+ def html_value(column_name, context, asset)
447
+ column_by_name(column_name).html_value(context, asset, self)
448
+ end
449
+
439
450
  protected
440
451
 
441
452
  def map_with_batches(&block)
@@ -474,11 +485,7 @@ module Datagrid
474
485
  end
475
486
 
476
487
  def method_missing(meth, *args, &blk)
477
- if column = @grid.column_by_name(meth)
478
- column.data_value(@model, @grid)
479
- else
480
- super
481
- end
488
+ @grid.data_value(meth, @model)
482
489
  end
483
490
  end
484
491
  end
@@ -16,11 +16,11 @@ class Datagrid::Columns::Column
16
16
  self.html_block = block
17
17
  end
18
18
 
19
- def data_value
19
+ def call_data
20
20
  data_block.call
21
21
  end
22
22
 
23
- def html_value(context)
23
+ def call_html(context)
24
24
  context.instance_eval(&html_block)
25
25
  end
26
26
  end
@@ -48,7 +48,7 @@ class Datagrid::Columns::Column
48
48
  def data_value(model, grid)
49
49
  raise "no data value for #{name} column" unless data?
50
50
  result = generic_value(model,grid)
51
- result.is_a?(ResponseFormat) ? result.data_value : result
51
+ result.is_a?(ResponseFormat) ? result.call_data : result
52
52
  end
53
53
 
54
54
 
@@ -119,7 +119,7 @@ class Datagrid::Columns::Column
119
119
  value_from_html_block(context, asset, grid)
120
120
  else
121
121
  result = generic_value(asset,grid)
122
- result.is_a?(ResponseFormat) ? result.html_value(context) : result
122
+ result.is_a?(ResponseFormat) ? result.call_html(context) : result
123
123
  end
124
124
  end
125
125
 
@@ -144,6 +144,9 @@ class Datagrid::Columns::Column
144
144
  end
145
145
 
146
146
  def generic_value(model, grid)
147
+ unless enabled?(grid)
148
+ raise Datagrid::ColumnUnavailableError, "Column #{name} disabled for #{grid.inspect}"
149
+ end
147
150
  if self.data_block.arity >= 1
148
151
  Datagrid::Utils.apply_args(model, grid, grid.data_row(model), &data_block)
149
152
  else
@@ -16,7 +16,7 @@ module Datagrid
16
16
  column = grid.column_by_name(column)
17
17
  end
18
18
 
19
- value = column.html_value(@template, asset, grid)
19
+ value = grid.html_value(column, @template, asset)
20
20
 
21
21
  url = column.options[:url] && column.options[:url].call(asset)
22
22
  if url
@@ -14,19 +14,19 @@ describe Datagrid::ActiveModel do
14
14
 
15
15
  describe ".model_name" do
16
16
  it "should be generate from class name " do
17
- ActiveReport.model_name.should == "ActiveReport"
17
+ expect(ActiveReport.model_name).to eq("ActiveReport")
18
18
  end
19
19
  it "should have ActiveModel naming conventions" do
20
- ActiveReport.model_name.i18n_key.should == :active_report
20
+ expect(ActiveReport.model_name.i18n_key).to eq(:active_report)
21
21
  end
22
22
  end
23
23
 
24
24
  describe ".param_name" do
25
25
  it "should make right param key from simple class name" do
26
- ActiveReport.param_name.should == 'active_report'
26
+ expect(ActiveReport.param_name).to eq('active_report')
27
27
  end
28
28
  it "should make right param key from class of module" do
29
- Grid::ActiveReport.param_name.should == 'grid_active_report'
29
+ expect(Grid::ActiveReport.param_name).to eq('grid_active_report')
30
30
  end
31
31
  end
32
32
 
@@ -25,24 +25,24 @@ describe Datagrid::ColumnNamesAttribute do
25
25
 
26
26
  it "should work" do
27
27
  subject.column_names = [:id]
28
- subject.mandatory_columns.map(&:name).should == [:name]
29
- subject.optional_columns.map(&:name).should == [:id, :category]
30
- subject.data.should == [["Id", "Name"], [entry.id, "hello"]]
28
+ expect(subject.mandatory_columns.map(&:name)).to eq([:name])
29
+ expect(subject.optional_columns.map(&:name)).to eq([:id, :category])
30
+ expect(subject.data).to eq([["Id", "Name"], [entry.id, "hello"]])
31
31
  columns_filter = subject.filter_by_name(:column_names)
32
- columns_filter.should_not be_nil
33
- columns_filter.select(subject).should == [["Id", :id], ["Category", :category]]
32
+ expect(columns_filter).not_to be_nil
33
+ expect(columns_filter.select(subject)).to eq([["Id", :id], ["Category", :category]])
34
34
  end
35
35
 
36
36
  it "should show only mandatory columns by default" do
37
- subject.row_for(entry).should == [ "hello" ]
37
+ expect(subject.row_for(entry)).to eq([ "hello" ])
38
38
  subject.column_names = ["name", "category"]
39
- subject.row_for(entry).should == ["hello", "greeting"]
39
+ expect(subject.row_for(entry)).to eq(["hello", "greeting"])
40
40
  end
41
41
 
42
42
  it "should find any column by name" do
43
- subject.column_by_name(:id).should_not be_nil
44
- subject.column_by_name(:name).should_not be_nil
45
- subject.column_by_name(:category).should_not be_nil
43
+ expect(subject.column_by_name(:id)).not_to be_nil
44
+ expect(subject.column_by_name(:name)).not_to be_nil
45
+ expect(subject.column_by_name(:category)).not_to be_nil
46
46
  end
47
47
 
48
48
 
@@ -50,7 +50,11 @@ describe Datagrid::ColumnNamesAttribute do
50
50
  let(:column_names_filter_options) do
51
51
  { :default => [:id] }
52
52
  end
53
- its(:data) { should == [["Id", "Name"], [entry.id, 'hello']] }
53
+
54
+ describe '#data' do
55
+ subject { super().data }
56
+ it { should == [["Id", "Name"], [entry.id, 'hello']] }
57
+ end
54
58
 
55
59
  end
56
60
  end
@@ -23,13 +23,13 @@ describe Datagrid::Columns do
23
23
  let(:date) { Date.new(2013, 8, 1) }
24
24
 
25
25
  it "should have data columns without html columns" do
26
- subject.data_columns.size.should == subject.columns.size - 1
26
+ expect(subject.data_columns.size).to eq(subject.columns.size - 1)
27
27
  end
28
28
  it "should build rows of data" do
29
- subject.rows.should == [[date, "Pop", "Star", "admin", "ROTTWEILER"]]
29
+ expect(subject.rows).to eq([[date, "Pop", "Star", "admin", "ROTTWEILER"]])
30
30
  end
31
31
  it "should generate header" do
32
- subject.header.should == ["Shipping date", "Group", "Name", "Access level", "Pet"]
32
+ expect(subject.header).to eq(["Shipping date", "Group", "Name", "Access level", "Pet"])
33
33
  end
34
34
 
35
35
  it "should return html_columns" do
@@ -38,7 +38,7 @@ describe Datagrid::Columns do
38
38
  column(:id)
39
39
  column(:name, :html => false)
40
40
  end
41
- report.html_columns.map(&:name).should == [:id]
41
+ expect(report.html_columns.map(&:name)).to eq([:id])
42
42
  end
43
43
 
44
44
  it "should return html_columns when column definition has 2 arguments" do
@@ -51,36 +51,36 @@ describe Datagrid::Columns do
51
51
  end
52
52
  end
53
53
  entry = Entry.create!(:name => "Hello World")
54
- report.row_for(entry).should == [entry.id, "'Hello World' filtered by 'Hello'"]
54
+ expect(report.row_for(entry)).to eq([entry.id, "'Hello World' filtered by 'Hello'"])
55
55
  end
56
56
 
57
57
  it "should generate table data" do
58
- subject.data.should == [
58
+ expect(subject.data).to eq([
59
59
  subject.header,
60
60
  subject.row_for(entry)
61
- ]
61
+ ])
62
62
  end
63
63
 
64
64
  it "should generate hash for given asset" do
65
- subject.hash_for(entry).should == {
65
+ expect(subject.hash_for(entry)).to eq({
66
66
  :group => "Pop",
67
67
  :name => "Star",
68
68
  :access_level => 'admin',
69
69
  :pet => 'ROTTWEILER',
70
70
  :shipping_date => date
71
- }
71
+ })
72
72
  end
73
73
 
74
74
  it "should support csv export" do
75
- subject.to_csv.should == "Shipping date,Group,Name,Access level,Pet\n#{date},Pop,Star,admin,ROTTWEILER\n"
75
+ expect(subject.to_csv).to eq("Shipping date,Group,Name,Access level,Pet\n#{date},Pop,Star,admin,ROTTWEILER\n")
76
76
  end
77
77
 
78
78
  it "should support csv export of particular columns" do
79
- subject.to_csv(:name).should == "Name\nStar\n"
79
+ expect(subject.to_csv(:name)).to eq("Name\nStar\n")
80
80
  end
81
81
 
82
82
  it "should support csv export options" do
83
- subject.to_csv(:col_sep => ";").should == "Shipping date;Group;Name;Access level;Pet\n#{date};Pop;Star;admin;ROTTWEILER\n"
83
+ expect(subject.to_csv(:col_sep => ";")).to eq("Shipping date;Group;Name;Access level;Pet\n#{date};Pop;Star;admin;ROTTWEILER\n")
84
84
  end
85
85
 
86
86
  end
@@ -98,8 +98,8 @@ describe Datagrid::Columns do
98
98
  end
99
99
  Entry.create!(:category => "foo")
100
100
  Entry.create!(:category => "foobar")
101
- report.rows.first.first.should be_true
102
- report.rows.last.first.should be_false
101
+ expect(report.rows.first.first).to be_true
102
+ expect(report.rows.last.first).to be_false
103
103
  end
104
104
 
105
105
  it "should inherit columns correctly" do
@@ -112,10 +112,10 @@ describe Datagrid::Columns do
112
112
  child = Class.new(parent) do
113
113
  column(:group_id)
114
114
  end
115
- parent.column_by_name(:name).should_not be_nil
116
- parent.column_by_name(:group_id).should be_nil
117
- child.column_by_name(:name).should_not be_nil
118
- child.column_by_name(:group_id).should_not be_nil
115
+ expect(parent.column_by_name(:name)).not_to be_nil
116
+ expect(parent.column_by_name(:group_id)).to be_nil
117
+ expect(child.column_by_name(:name)).not_to be_nil
118
+ expect(child.column_by_name(:group_id)).not_to be_nil
119
119
  end
120
120
  it "should support defining a query for a column" do
121
121
  report = test_report do
@@ -125,7 +125,7 @@ describe Datagrid::Columns do
125
125
  column(:sum_group_id, 'sum(group_id)')
126
126
  end
127
127
  Entry.create!(:group => group)
128
- report.assets.first.sum_group_id.should == group.id
128
+ expect(report.assets.first.sum_group_id).to eq(group.id)
129
129
  end
130
130
 
131
131
  it "should support post formatting for column defined with query" do
@@ -139,7 +139,7 @@ describe Datagrid::Columns do
139
139
  end
140
140
  end
141
141
  3.times { Entry.create!(group: group) }
142
- report.rows.should == [["(3)"]]
142
+ expect(report.rows).to eq([["(3)"]])
143
143
  end
144
144
  it "should support hidding columns through if and unless" do
145
145
  report = test_report do
@@ -152,9 +152,9 @@ describe Datagrid::Columns do
152
152
  false
153
153
  end
154
154
  end
155
- report.columns(:id).should == []
156
- report.columns(:name).should == []
157
- report.available_columns.map(&:name).should == [:category]
155
+ expect(report.columns(:id)).to eq([])
156
+ expect(report.columns(:name)).to eq([])
157
+ expect(report.available_columns.map(&:name)).to eq([:category])
158
158
  end
159
159
 
160
160
  describe ".column_names attributes" do
@@ -170,18 +170,18 @@ describe Datagrid::Columns do
170
170
  Entry.create!(:name => 'hello')
171
171
  end
172
172
  it "should be suppored in header" do
173
- grid.header.should == ["Id", "Name"]
173
+ expect(grid.header).to eq(["Id", "Name"])
174
174
  end
175
175
  it "should be suppored in rows" do
176
- grid.rows.should == [[entry.id, "hello"]]
176
+ expect(grid.rows).to eq([[entry.id, "hello"]])
177
177
  end
178
178
 
179
179
  it "should be suppored in csv" do
180
- grid.to_csv.should == "Id,Name\n#{entry.id},hello\n"
180
+ expect(grid.to_csv).to eq("Id,Name\n#{entry.id},hello\n")
181
181
  end
182
182
 
183
183
  it "should support explicit overwrite" do
184
- grid.header(:id, :name, :category).should == %w(Id Name Category)
184
+ expect(grid.header(:id, :name, :category)).to eq(%w(Id Name Category))
185
185
  end
186
186
 
187
187
  end
@@ -198,7 +198,7 @@ describe Datagrid::Columns do
198
198
  end
199
199
  end
200
200
  Entry.create!(:name => "Hello World")
201
- report.rows.should == [["Hello World"]]
201
+ expect(report.rows).to eq([["Hello World"]])
202
202
  end
203
203
  end
204
204
 
@@ -212,9 +212,9 @@ describe Datagrid::Columns do
212
212
  end
213
213
  first = Entry.create(:name => '1st')
214
214
  second = Entry.create(:name => '2nd')
215
- proc { report.attributes = {:order => :id} }.should raise_error(Datagrid::OrderUnsupported)
215
+ expect { report.attributes = {:order => :id} }.to raise_error(Datagrid::OrderUnsupported)
216
216
  report.attributes = {:order => :name, :descending => true}
217
- report.assets.should == [second, first]
217
+ expect(report.assets).to eq([second, first])
218
218
  end
219
219
  end
220
220
 
@@ -227,8 +227,8 @@ describe Datagrid::Columns do
227
227
  end
228
228
 
229
229
  fake_assets = double(:assets)
230
- report.should_receive(:assets) { fake_assets }
231
- fake_assets.should_receive(:find_each).with(batch_size: 25)
230
+ expect(report).to receive(:assets) { fake_assets }
231
+ expect(fake_assets).to receive(:find_each).with(batch_size: 25)
232
232
  report.rows
233
233
  end
234
234
  it "should be able to disable batches" do
@@ -240,9 +240,9 @@ describe Datagrid::Columns do
240
240
 
241
241
  fake_assets = double(:assets)
242
242
 
243
- report.should_receive(:assets) { fake_assets }
244
- fake_assets.should_receive(:each)
245
- fake_assets.should_not_receive(:find_each)
243
+ expect(report).to receive(:assets) { fake_assets }
244
+ expect(fake_assets).to receive(:each)
245
+ expect(fake_assets).not_to receive(:find_each)
246
246
  report.rows
247
247
  end
248
248
 
@@ -255,9 +255,9 @@ describe Datagrid::Columns do
255
255
  grid.batch_size = 0
256
256
  fake_assets = double(:assets)
257
257
 
258
- grid.should_receive(:assets) { fake_assets }
259
- fake_assets.should_receive(:each)
260
- fake_assets.should_not_receive(:find_each)
258
+ expect(grid).to receive(:assets) { fake_assets }
259
+ expect(fake_assets).to receive(:each)
260
+ expect(fake_assets).not_to receive(:find_each)
261
261
  grid.rows
262
262
  end
263
263
  end
@@ -276,11 +276,11 @@ describe Datagrid::Columns do
276
276
  end
277
277
  entry = Entry.create!(name: 'hello')
278
278
  row = grid.data_row(entry)
279
- row.id.should == entry.id
280
- row.name.should == "Hello"
281
- proc {
279
+ expect(row.id).to eq(entry.id)
280
+ expect(row.name).to eq("Hello")
281
+ expect {
282
282
  row.actions
283
- }.should raise_error
283
+ }.to raise_error
284
284
  end
285
285
  end
286
286
 
@@ -299,7 +299,7 @@ describe Datagrid::Columns do
299
299
  end
300
300
  end
301
301
 
302
- grid.row_for(group).should == [2, false]
302
+ expect(grid.row_for(group)).to eq([2, false])
303
303
  end
304
304
  end
305
305
 
@@ -317,55 +317,55 @@ describe Datagrid::Columns do
317
317
  let!(:entry) { Entry.create!(:name => "Hello", :category => 'first') }
318
318
 
319
319
  it "should have correct columns" do
320
- modified_grid.columns.size.should == 2
321
- basic_grid.class.columns.size.should == 1
322
- basic_grid.columns.size.should == 1
320
+ expect(modified_grid.columns.size).to eq(2)
321
+ expect(basic_grid.class.columns.size).to eq(1)
322
+ expect(basic_grid.columns.size).to eq(1)
323
323
  end
324
324
 
325
325
  it "should give correct header" do
326
- modified_grid.header.should == ["Id", "Name"]
327
- basic_grid.header.should == ["Id"]
326
+ expect(modified_grid.header).to eq(["Id", "Name"])
327
+ expect(basic_grid.header).to eq(["Id"])
328
328
  end
329
329
 
330
330
  it "should give correct rows" do
331
- modified_grid.rows.should == [[entry.id, 'Hello']]
332
- basic_grid.rows.should == [[entry.id]]
331
+ expect(modified_grid.rows).to eq([[entry.id, 'Hello']])
332
+ expect(basic_grid.rows).to eq([[entry.id]])
333
333
  end
334
334
 
335
335
  it "should support possitioning" do
336
336
  modified_grid.column(:category, :before => :name)
337
- modified_grid.header.should == ["Id", "Category", "Name"]
337
+ expect(modified_grid.header).to eq(["Id", "Category", "Name"])
338
338
  end
339
339
 
340
340
  it "should support columns block" do
341
341
  modified_grid.column(:category) do
342
342
  category.capitalize
343
343
  end
344
- modified_grid.rows.should == [[entry.id, "Hello", 'First']]
344
+ expect(modified_grid.rows).to eq([[entry.id, "Hello", 'First']])
345
345
  end
346
346
 
347
347
  it "should support column_names accessor" do
348
348
  modified_grid.column_names = [:name]
349
- modified_grid.rows.should == [['Hello']]
349
+ expect(modified_grid.rows).to eq([['Hello']])
350
350
  modified_grid.column_names = [:id]
351
- modified_grid.rows.should == [[entry.id]]
351
+ expect(modified_grid.rows).to eq([[entry.id]])
352
352
  end
353
353
  it "should support column_names accessor with mandatory columns" do
354
354
  modified_grid.column(:category, :mandatory => true)
355
355
  modified_grid.column_names = [:name]
356
- modified_grid.rows.should == [['Hello', 'first']]
356
+ expect(modified_grid.rows).to eq([['Hello', 'first']])
357
357
  basic_grid.column_names = [:id]
358
- basic_grid.rows.should == [[entry.id]]
358
+ expect(basic_grid.rows).to eq([[entry.id]])
359
359
  end
360
360
 
361
361
  it "should support available columns" do
362
362
  modified_grid.column(:category, :mandatory => true)
363
- modified_grid.available_columns.map(&:name).should == [:id, :name, :category]
363
+ expect(modified_grid.available_columns.map(&:name)).to eq([:id, :name, :category])
364
364
  end
365
365
 
366
366
  it "should respect column availability criteria" do
367
367
  modified_grid.column(:category, :if => proc { false })
368
- modified_grid.columns.map(&:name).should == [:id, :name]
368
+ expect(modified_grid.columns.map(&:name)).to eq([:id, :name])
369
369
  end
370
370
  end
371
371
 
@@ -380,12 +380,30 @@ describe Datagrid::Columns do
380
380
  }
381
381
  end
382
382
 
383
- grid.columns.map(&:name).should == [:id, :name, :category]
384
- grid.class.columns.map(&:name).should == [:id]
383
+ expect(grid.columns.map(&:name)).to eq([:id, :name, :category])
384
+ expect(grid.class.columns.map(&:name)).to eq([:id])
385
385
 
386
- grid.column_by_name(:id).should_not be_nil
387
- grid.column_by_name(:name).should_not be_nil
386
+ expect(grid.column_by_name(:id)).not_to be_nil
387
+ expect(grid.column_by_name(:name)).not_to be_nil
388
388
  end
389
389
  end
390
390
 
391
+ describe ".data_value" do
392
+ it "should return value" do
393
+ grid = test_report do
394
+ scope {Entry }
395
+ column(:name)
396
+ end
397
+ expect(grid.data_value(:name, Entry.create!(:name => 'Hello'))).to eq('Hello')
398
+ end
399
+ it "should raise for disabled columns" do
400
+ grid = test_report do
401
+ scope {Entry }
402
+ column(:name, :if => proc { false })
403
+ end
404
+ expect {
405
+ grid.data_value(:name, Entry.create!(:name => 'Hello'))
406
+ }.to raise_error(Datagrid::ColumnUnavailableError)
407
+ end
408
+ end
391
409
  end