datagrid 1.3.7 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/assets/stylesheets/{datagrid.css.sass → datagrid.sass} +0 -0
  4. data/app/views/datagrid/_form.html.erb +1 -1
  5. data/datagrid.gemspec +9 -6
  6. data/lib/datagrid/columns/column.rb +1 -2
  7. data/lib/datagrid/filters.rb +10 -0
  8. data/lib/datagrid/filters/base_filter.rb +5 -2
  9. data/lib/datagrid/filters/date_filter.rb +1 -1
  10. data/lib/datagrid/filters/date_time_filter.rb +1 -1
  11. data/lib/datagrid/filters/float_filter.rb +1 -1
  12. data/lib/datagrid/filters/integer_filter.rb +1 -1
  13. data/lib/datagrid/filters/ranged_filter.rb +1 -1
  14. data/lib/datagrid/form_builder.rb +25 -9
  15. data/lib/datagrid/rspec.rb +1 -1
  16. data/lib/datagrid/utils.rb +14 -0
  17. data/spec/datagrid/columns_spec.rb +61 -4
  18. data/spec/datagrid/drivers/active_record_spec.rb +2 -2
  19. data/spec/datagrid/drivers/mongo_mapper_spec.rb +1 -1
  20. data/spec/datagrid/drivers/mongoid_spec.rb +1 -1
  21. data/spec/datagrid/filters/date_time_filter_spec.rb +7 -2
  22. data/spec/datagrid/filters_spec.rb +48 -0
  23. data/spec/datagrid/form_builder_spec.rb +37 -13
  24. data/spec/datagrid/helper_spec.rb +23 -0
  25. data/spec/datagrid/stylesheet_spec.rb +8 -0
  26. data/spec/datagrid_spec.rb +4 -2
  27. data/spec/spec_helper.rb +2 -0
  28. data/spec/support/i18n_helpers.rb +7 -0
  29. data/spec/support/matchers.rb +5 -0
  30. data/spec/support/simple_report.rb +2 -1
  31. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +1 -0
  32. data/spec/support/test_partials/custom_form/_form.html.erb +7 -0
  33. data/spec/support/test_partials/custom_range/_range_filter.html.erb +1 -0
  34. metadata +8 -5
  35. data/spec/support/locale/deprecated_range_format.yml +0 -7
  36. data/spec/support/locale/deprecated_range_separator.yml +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a5c31c4749036fb87065560c115eedfd90a4c26
4
- data.tar.gz: afe23674ce0a6092e9a38aef5755327a934d942b
3
+ metadata.gz: 6d1827360a3a33795e420d9c086607e2934ff3a8
4
+ data.tar.gz: 34e08edcc7adcb354dfd7d6b24b19c8a34134c19
5
5
  SHA512:
6
- metadata.gz: 3fc66b0df7f1c502250b47dad4d1f92b56b155d2d4a89e5a04d8fb706565c2438d35b0a84a0776cf7ef93b7221e93b79e69591576d931bfe3bde8cab111db8af
7
- data.tar.gz: f174e306b193df406d8bd519f7de01f91da7d37431ec7b898ef1bbab6150265054a82de1d256015efd3281d19940f42d689927d41a081ff72226e992f8185d19
6
+ metadata.gz: d1d458c0938739371e2cf3dd5d16e5c9601dea0f9a6c62b439c542aa8a14d6a84e90c76e7447b03306a51eec91eddb05d97fe454c1020dd25748c89b093cc8fa
7
+ data.tar.gz: bd86f70ec51fcf427b33c1b3380b4c4eaf9d7c8e3070ce74606354dace36e973ca5befe383f3cc7c397ebe4e8418d8e568e2cea1621d9372195321295ed5b7f5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.7
1
+ 1.3.9
@@ -2,7 +2,7 @@
2
2
  <% grid.filters.each do |filter| %>
3
3
  <div class="datagrid-filter filter">
4
4
  <%= f.datagrid_label filter %>
5
- <%= f.datagrid_filter filter %>
5
+ <%= f.datagrid_filter filter, partials: options[:partials] %>
6
6
  </div>
7
7
  <% end %>
8
8
  <div class="datagrid-actions">
@@ -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.3.7 ruby lib
5
+ # stub: datagrid 1.3.9 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid"
9
- s.version = "1.3.7"
9
+ s.version = "1.3.9"
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 = "2015-03-25"
14
+ s.date = "2015-05-11"
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 = [
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "Readme.markdown",
29
29
  "VERSION",
30
- "app/assets/stylesheets/datagrid.css.sass",
30
+ "app/assets/stylesheets/datagrid.sass",
31
31
  "app/views/datagrid/_enum_checkboxes.html.erb",
32
32
  "app/views/datagrid/_form.html.erb",
33
33
  "app/views/datagrid/_head.html.erb",
@@ -98,13 +98,13 @@ Gem::Specification.new do |s|
98
98
  "spec/datagrid/helper_spec.rb",
99
99
  "spec/datagrid/ordering_spec.rb",
100
100
  "spec/datagrid/scaffold_spec.rb",
101
+ "spec/datagrid/stylesheet_spec.rb",
101
102
  "spec/datagrid/utils_spec.rb",
102
103
  "spec/datagrid_spec.rb",
103
104
  "spec/spec_helper.rb",
104
105
  "spec/support/active_record.rb",
105
106
  "spec/support/configuration.rb",
106
- "spec/support/locale/deprecated_range_format.yml",
107
- "spec/support/locale/deprecated_range_separator.yml",
107
+ "spec/support/i18n_helpers.rb",
108
108
  "spec/support/matchers.rb",
109
109
  "spec/support/mongo_mapper.rb",
110
110
  "spec/support/mongoid.rb",
@@ -115,6 +115,9 @@ Gem::Specification.new do |s|
115
115
  "spec/support/test_partials/client/datagrid/_order_for.html.erb",
116
116
  "spec/support/test_partials/client/datagrid/_row.html.erb",
117
117
  "spec/support/test_partials/client/datagrid/_table.html.erb",
118
+ "spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb",
119
+ "spec/support/test_partials/custom_form/_form.html.erb",
120
+ "spec/support/test_partials/custom_range/_range_filter.html.erb",
118
121
  "templates/controller.rb.erb",
119
122
  "templates/grid.rb.erb",
120
123
  "templates/index.html.erb"
@@ -56,8 +56,7 @@ class Datagrid::Columns::Column
56
56
  end
57
57
 
58
58
  def header
59
- self.options[:header] ||
60
- I18n.translate(self.name, :scope => "datagrid.#{self.grid_class.param_name}.columns", :default => self.name.to_s.humanize )
59
+ self.options[:header] || Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
61
60
  end
62
61
 
63
62
  def order
@@ -151,6 +151,16 @@ module Datagrid
151
151
  apply_filters(scope, filters.map{|f| filter_by_name(f)})
152
152
  end
153
153
 
154
+ # Returns select options for specific filter or filter name
155
+ # If given filter doesn't support select options raises `ArgumentError`
156
+ def select_options(filter)
157
+ filter = filter_by_name(filter)
158
+ unless filter.class.included_modules.include?(::Datagrid::Filters::SelectOptions)
159
+ raise ::Datagrid::ArgumentError, "#{filter.name} with type #{FILTER_TYPES.invert[filter.class].inspect} can not have select options"
160
+ end
161
+ filter.select(self)
162
+ end
163
+
154
164
  protected
155
165
 
156
166
  def apply_filters(current_scope, filters)
@@ -49,8 +49,7 @@ class Datagrid::Filters::BaseFilter #:nodoc:
49
49
  end
50
50
 
51
51
  def header
52
- options[:header] ||
53
- I18n.translate(self.name, :scope => "datagrid.#{grid_class.param_name}.filters", :default => self.name.to_s.humanize)
52
+ options[:header] || Datagrid::Utils.translate_from_namespace(:filters, grid_class, name)
54
53
  end
55
54
 
56
55
  def default
@@ -100,6 +99,10 @@ class Datagrid::Filters::BaseFilter #:nodoc:
100
99
  end
101
100
  end
102
101
 
102
+ def supports_range?
103
+ self.class.ancestors.include?(::Datagrid::Filters::RangedFilter)
104
+ end
105
+
103
106
  def format(value)
104
107
  value.nil? ? nil : value.to_s
105
108
  end
@@ -2,7 +2,7 @@ require "datagrid/filters/ranged_filter"
2
2
 
3
3
  class Datagrid::Filters::DateFilter < Datagrid::Filters::BaseFilter
4
4
 
5
- include RangedFilter
5
+ include Datagrid::Filters::RangedFilter
6
6
 
7
7
  def apply(grid_object, scope, value)
8
8
  if value.is_a?(Range)
@@ -2,7 +2,7 @@ require "datagrid/filters/ranged_filter"
2
2
 
3
3
  class Datagrid::Filters::DateTimeFilter < Datagrid::Filters::BaseFilter
4
4
 
5
- include RangedFilter
5
+ include Datagrid::Filters::RangedFilter
6
6
 
7
7
  def parse(value)
8
8
  Datagrid::Utils.parse_datetime(value)
@@ -1,6 +1,6 @@
1
1
  class Datagrid::Filters::FloatFilter < Datagrid::Filters::BaseFilter
2
2
 
3
- include RangedFilter
3
+ include Datagrid::Filters::RangedFilter
4
4
 
5
5
  def parse(value)
6
6
  return nil if value.blank?
@@ -2,7 +2,7 @@ require "datagrid/filters/ranged_filter"
2
2
 
3
3
  class Datagrid::Filters::IntegerFilter < Datagrid::Filters::BaseFilter
4
4
 
5
- include RangedFilter
5
+ include Datagrid::Filters::RangedFilter
6
6
 
7
7
  def parse(value)
8
8
  return nil if value.blank?
@@ -1,4 +1,4 @@
1
- module RangedFilter
1
+ module Datagrid::Filters::RangedFilter
2
2
 
3
3
 
4
4
  def initialize(grid, name, options, &block)
@@ -7,6 +7,8 @@ module Datagrid
7
7
  def datagrid_filter(filter_or_attribute, options = {}, &block)
8
8
  filter = datagrid_get_filter(filter_or_attribute)
9
9
  options = add_html_classes(options, filter.name, datagrid_filter_html_class(filter))
10
+ # Prevent partials option from appearing in HTML attributes
11
+ options.delete(:partials) unless supports_partial?(filter)
10
12
  self.send(filter.form_builder_helper_name, filter, options, &block)
11
13
  end
12
14
 
@@ -48,18 +50,17 @@ module Datagrid
48
50
  end
49
51
 
50
52
  def datagrid_enum_filter(attribute_or_filter, options = {}, &block)
51
- options = options.clone
52
53
  filter = datagrid_get_filter(attribute_or_filter)
53
54
  if filter.checkboxes?
55
+ partial = partial_path(options, 'enum_checkboxes')
54
56
  options = add_html_classes(options, 'checkboxes')
55
- partials_path = options.delete(:partials) || 'datagrid'
56
- elements = filter.select(object).map do |element|
57
+ elements = object.select_options(filter).map do |element|
57
58
  text, value = @template.send(:option_text_and_value, element)
58
59
  checked = enum_checkbox_checked?(filter, value)
59
60
  [value, text, checked]
60
61
  end
61
62
  @template.render(
62
- :partial => File.join(partials_path, 'enum_checkboxes'),
63
+ :partial => partial,
63
64
  :locals => {
64
65
  :elements => elements,
65
66
  :form => self,
@@ -73,7 +74,7 @@ module Datagrid
73
74
  end
74
75
  select(
75
76
  filter.name,
76
- filter.select(object) || [],
77
+ object.select_options(filter) || [],
77
78
  {:include_blank => filter.include_blank,
78
79
  :prompt => filter.prompt,
79
80
  :include_hidden => false},
@@ -95,7 +96,7 @@ module Datagrid
95
96
 
96
97
  def datagrid_integer_filter(attribute_or_filter, options = {})
97
98
  filter = datagrid_get_filter(attribute_or_filter)
98
- if filter.multiple? && self.object[filter.name].blank?
99
+ if filter.multiple? && object[filter.name].blank?
99
100
  options[:value] = ""
100
101
  end
101
102
  datagrid_range_filter(:integer, filter, options)
@@ -108,7 +109,7 @@ module Datagrid
108
109
  options = options.merge(:name => input_name)
109
110
  field_input = select(
110
111
  filter.name,
111
- filter.select(object) || [],
112
+ object.select_options(filter) || [],
112
113
  {
113
114
  :include_blank => filter.include_blank,
114
115
  :prompt => filter.prompt,
@@ -129,6 +130,7 @@ module Datagrid
129
130
  def datagrid_range_filter(type, attribute_or_filter, options = {})
130
131
  filter = datagrid_get_filter(attribute_or_filter)
131
132
  if filter.range?
133
+ partial = partial_path(options, 'range_filter')
132
134
  options = options.merge(:multiple => true)
133
135
 
134
136
 
@@ -151,7 +153,7 @@ module Datagrid
151
153
  I18n.t(format_key, :from_input => from_input, :to_input => to_input).html_safe
152
154
  else
153
155
  # More flexible way to render via partial
154
- @template.render :partial => 'datagrid/range_filter', :locals => {
156
+ @template.render :partial => partial, :locals => {
155
157
  :from_options => from_options, :to_options => to_options, :filter => filter, :form => self
156
158
  }
157
159
  end
@@ -214,8 +216,22 @@ module Datagrid
214
216
  Datagrid::Utils.add_html_classes(options, *classes)
215
217
  end
216
218
 
217
- class Error < StandardError
219
+ def partial_path(options, name)
220
+ if partials = options.delete(:partials)
221
+ partial_name = File.join(partials, name)
222
+ # Second argument is []: no magical namespaces to lookup added from controller
223
+ if @template.lookup_context.template_exists?(partial_name, [], true)
224
+ return partial_name
225
+ end
226
+ end
227
+ File.join('datagrid', name)
218
228
  end
219
229
 
230
+ def supports_partial?(filter)
231
+ (filter.supports_range? && filter.range?) || (filter.type == :enum && filter.checkboxes?)
232
+ end
233
+
234
+ class Error < StandardError
235
+ end
220
236
  end
221
237
  end
@@ -45,7 +45,7 @@ shared_examples_for "Datagrid" do
45
45
  when :integer
46
46
  1
47
47
  when :enum
48
- select = filter.select(subject)
48
+ select = subject.select_options(filter)
49
49
  select.first.try(:last)
50
50
  else
51
51
  raise "unknown filter type: #{filter.class}"
@@ -12,6 +12,20 @@ module Datagrid
12
12
  TRUTH.include?(value)
13
13
  end
14
14
 
15
+ def translate_from_namespace(namespace, grid_class, key)
16
+ deprecated_key = :"datagrid.#{grid_class.param_name}.#{namespace}.#{key}"
17
+ live_key = :"datagrid.#{grid_class.model_name.i18n_key}.#{namespace}.#{key}"
18
+ i18n_key = grid_class.model_name.i18n_key.to_s
19
+
20
+ if grid_class.param_name != i18n_key && I18n.exists?(deprecated_key)
21
+ Datagrid::Utils.warn_once(
22
+ "Deprecated translation namespace 'datagrid.#{grid_class.param_name}' for #{grid_class}. Use 'datagrid.#{i18n_key}' instead."
23
+ )
24
+ return I18n.t(deprecated_key)
25
+ end
26
+ I18n.t(live_key, default: key.to_s.humanize).presence
27
+ end
28
+
15
29
  def warn_once(message, delay = 5)
16
30
  @warnings ||= {}
17
31
  timestamp = @warnings[message]
@@ -23,13 +23,70 @@ 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
- expect(subject.data_columns.size).to eq(subject.columns.size - 1)
26
+ grid = test_report do
27
+ scope {Entry}
28
+ column(:name)
29
+ column(:action, :html => true) do
30
+ 'dummy'
31
+ end
32
+ end
33
+ expect(grid.data_columns.map(&:name)).to eq([:name])
34
+ expect(grid.html_columns.map(&:name)).to eq([:name, :action])
27
35
  end
28
36
  it "should build rows of data" do
29
- expect(subject.rows).to eq([[date, "Pop", "Star", "admin", "ROTTWEILER"]])
37
+ grid = test_report do
38
+ scope {Entry}
39
+ column(:name)
40
+ column(:action, :html => true) do
41
+ 'dummy'
42
+ end
43
+ end
44
+ expect(grid.rows).to eq([["Star"]])
45
+ end
46
+ it "should generate header without html columns" do
47
+ grid = test_report do
48
+ scope {Entry}
49
+ column(:name)
50
+ column(:action, :html => true) do
51
+ 'dummy'
52
+ end
53
+ end
54
+ expect(grid.header).to eq(["Name"])
30
55
  end
31
- it "should generate header" do
32
- expect(subject.header).to eq(["Shipping date", "Group", "Name", "Access level", "Pet"])
56
+
57
+ describe "translations" do
58
+
59
+ module ::Ns45
60
+ class TranslatedReport
61
+ include Datagrid
62
+ scope { Entry }
63
+ column(:name)
64
+ end
65
+ end
66
+ it "translates column with deprecated namespace" do
67
+ silence_warnings do
68
+ store_translations(:en, datagrid: {ns45_translated_report: {columns: {name: "Navn"}}}) do
69
+ expect(Ns45::TranslatedReport.new.header.first).to eq("Navn")
70
+ end
71
+ end
72
+ end
73
+
74
+ it "translates column with namespace" do
75
+ store_translations(:en, datagrid: {:"ns45/translated_report" => {columns: {name: "Navn"}}}) do
76
+ expect(Ns45::TranslatedReport.new.header.first).to eq("Navn")
77
+ end
78
+ end
79
+
80
+ it "translates column without namespace" do
81
+ class Report27
82
+ include Datagrid
83
+ scope {Entry}
84
+ column(:name)
85
+ end
86
+ store_translations(:en, datagrid: {:"report27" => {columns: {name: "Nombre"}}}) do
87
+ expect(Report27.new.header.first).to eq("Nombre")
88
+ end
89
+ end
33
90
  end
34
91
 
35
92
  it "should return html_columns" do
@@ -6,7 +6,7 @@ describe Datagrid::Drivers::ActiveRecord do
6
6
  subject { described_class }
7
7
 
8
8
  it {should be_match(Entry)}
9
- it {should be_match(Entry.scoped)}
9
+ it {should be_match(Entry.where(:id => 1))}
10
10
  it {should_not be_match(MongoidEntry)}
11
11
  end
12
12
 
@@ -17,7 +17,7 @@ describe Datagrid::Drivers::ActiveRecord do
17
17
  end
18
18
 
19
19
  it "should support append_column_queries" do
20
- scope = subject.append_column_queries(Entry.scoped, [Datagrid::Columns::Column.new(SimpleReport, :sum_group_id, 'sum(entries.group_id)')])
20
+ scope = subject.append_column_queries(Entry.where({}), [Datagrid::Columns::Column.new(test_report_class, :sum_group_id, 'sum(entries.group_id)')])
21
21
  expect(scope.to_sql.strip).to eq('SELECT "entries".*, sum(entries.group_id) AS sum_group_id FROM "entries"')
22
22
  end
23
23
  end
@@ -9,7 +9,7 @@ describe Datagrid::Drivers::MongoMapper, :mongomapper do
9
9
  it {should be_match(MongoMapperEntry)}
10
10
  # MongoMapper doesn't have a scoped method, instead it has a query method which returns a Plucky::Query object
11
11
  it {should be_match(MongoMapperEntry.query)}
12
- it {should_not be_match(Entry.scoped)}
12
+ it {should_not be_match(Entry.where(:id => 1))}
13
13
 
14
14
  end
15
15
  describe "api" do
@@ -8,7 +8,7 @@ describe Datagrid::Drivers::Mongoid, :mongoid do
8
8
 
9
9
  it {should be_match(MongoidEntry)}
10
10
  it {should be_match(MongoidEntry.scoped)}
11
- it {should_not be_match(Entry.scoped)}
11
+ it {should_not be_match(Entry.where(:id => 1))}
12
12
 
13
13
  end
14
14
  describe "api" do
@@ -5,11 +5,16 @@ describe Datagrid::Filters::DateTimeFilter do
5
5
  describe "with orm #{orm}", orm => true do
6
6
  describe "timestamp to timestamp conversion" do
7
7
  let(:klass) { klass }
8
- subject do
8
+
9
+ let(:grid) do
9
10
  test_report(:created_at => _created_at) do
10
11
  scope { klass }
11
12
  filter(:created_at, :datetime, :range => true)
12
- end.assets.to_a
13
+ end
14
+ end
15
+
16
+ subject do
17
+ grid.assets.to_a
13
18
  end
14
19
 
15
20
  def entry_dated(date)
@@ -204,4 +204,52 @@ describe Datagrid::Filters do
204
204
  expect(object.type).to eq(:integer)
205
205
  end
206
206
  end
207
+
208
+ describe "tranlations" do
209
+
210
+ module ::Ns46
211
+ class TranslatedReport
212
+ include Datagrid
213
+ scope { Entry }
214
+ filter(:name)
215
+ end
216
+ end
217
+ it "translates filter with deprecated namespace" do
218
+ grid = Ns46::TranslatedReport.new
219
+ silence_warnings do
220
+ store_translations(:en, datagrid: {ns46_translated_report: {filters: {name: "Navn"}}}) do
221
+ expect(grid.filters.map(&:header)).to eq(["Navn"])
222
+ end
223
+ end
224
+ end
225
+
226
+ it "translates filter with namespace" do
227
+ grid = Ns46::TranslatedReport.new
228
+ store_translations(:en, datagrid: {:"ns46/translated_report" => {filters: {name: "Navn"}}}) do
229
+ expect(grid.filters.map(&:header)).to eq(["Navn"])
230
+ end
231
+ end
232
+
233
+ end
234
+
235
+
236
+ describe "#select_options" do
237
+ it "should return select options" do
238
+ grid = test_report do
239
+ scope {Entry}
240
+ filter(:id, :enum, select: [1,2,3])
241
+ end
242
+ expect(grid.select_options(:id)).to eq([1,2,3])
243
+ end
244
+
245
+ it "should raise ArgumentError for filter without options" do
246
+ grid = test_report do
247
+ scope {Entry}
248
+ filter(:id, :integer)
249
+ end
250
+ expect {
251
+ grid.select_options(:id)
252
+ }.to raise_error(Datagrid::ArgumentError)
253
+ end
254
+ end
207
255
  end
@@ -58,6 +58,13 @@ describe Datagrid::FormBuilder do
58
58
  it { should equal_to_dom(
59
59
  '<input class="group_id integer_filter" id="report_group_id" name="report[group_id]" size="30" type="text"/>'
60
60
  )}
61
+
62
+ context "when partials option is passed for filter that don't support range" do
63
+ let(:_filter_options) { {partials: 'anything' } }
64
+ it { should equal_to_dom(
65
+ '<input class="group_id integer_filter" id="report_group_id" name="report[group_id]" size="30" type="text"/>'
66
+ )}
67
+ end
61
68
  end
62
69
 
63
70
  context "with date filter type" do
@@ -130,16 +137,31 @@ describe Datagrid::FormBuilder do
130
137
  )}
131
138
  end
132
139
 
140
+ context "with custom partials option and template exists" do
141
+ let(:_filter_options) { { :partials => 'custom_range' } }
142
+ let(:_range) { nil }
143
+ it { should equal_to_dom(
144
+ "custom_range_partial"
145
+ ) }
146
+ end
147
+
148
+ context "when custom partial doesn't exist" do
149
+ let(:_filter_options) { { :partials => 'not_existed' } }
150
+ let(:_range) { nil }
151
+ it { should equal_to_dom(
152
+ '<input class="group_id integer_filter from" multiple name="report[group_id][]" size="30" type="text"><span class="separator integer"> - </span><input class="group_id integer_filter to" multiple name="report[group_id][]" size="30" type="text">'
153
+ ) }
154
+
155
+ end
156
+
133
157
  context "when deprecated format translation specified" do
134
158
  let(:_range) { nil }
135
159
  around(:each) do |example|
136
- I18n.load_path << File.expand_path('../../support/locale/deprecated_range_format.yml', __FILE__)
137
- I18n.reload!
138
- silence_warnings do
139
- example.run
160
+ store_translations(:en, datagrid: {filters: {integer: {range_format: "from %{from_input} to %{to_input}"}}}) do
161
+ silence_warnings do
162
+ example.run
163
+ end
140
164
  end
141
- I18n.load_path.pop
142
- I18n.reload!
143
165
  end
144
166
  it { should equal_to_dom(
145
167
  'from <input class="group_id integer_filter from" multiple name="report[group_id][]" size="30" type="text"> to <input class="group_id integer_filter to" multiple name="report[group_id][]" size="30" type="text">'
@@ -148,14 +170,11 @@ describe Datagrid::FormBuilder do
148
170
  context "when deprecated separator is specified" do
149
171
  let(:_range) { nil }
150
172
  around(:each) do |example|
151
- I18n.load_path << File.expand_path('../../support/locale/deprecated_range_separator.yml', __FILE__)
152
- I18n.reload!
153
- silence_warnings do
154
- example.run
173
+ store_translations(:en, datagrid: {filters: {integer: {range_separator: " | "}}}) do
174
+ silence_warnings do
175
+ example.run
176
+ end
155
177
  end
156
- I18n.load_path.pop
157
- I18n.reload!
158
-
159
178
  end
160
179
  it { should equal_to_dom(
161
180
  '<input class="group_id integer_filter from" multiple name="report[group_id][]" size="30" type="text"> | <input class="group_id integer_filter to" multiple name="report[group_id][]" size="30" type="text">'
@@ -319,6 +338,11 @@ describe Datagrid::FormBuilder do
319
338
 
320
339
 
321
340
  end
341
+
342
+ context "when partials option passed and partial exists" do
343
+ let(:_filter_options) { {partials: 'custom_checkboxes'} }
344
+ it { should equal_to_dom('custom_enum_checkboxes') }
345
+ end
322
346
  end
323
347
  end
324
348
 
@@ -455,6 +455,29 @@ describe Datagrid::Helper do
455
455
  "form.datagrid-form input[name='g[id]']" => 1,
456
456
  )
457
457
  end
458
+
459
+ it "takes default partials if custom doesn't exist" do
460
+ class PartialDefaultGrid
461
+ include Datagrid
462
+ scope {Entry}
463
+ filter(:id, :integer, :range => true)
464
+ filter(:group_id, :enum, :multiple => true, :checkboxes => true, :select => [1,2])
465
+ def param_name
466
+ 'g'
467
+ end
468
+ end
469
+ rendered_form = subject.datagrid_form_for(PartialDefaultGrid.new, {
470
+ :url => '',
471
+ :partials => 'custom_form'
472
+ })
473
+ expect(rendered_form).to include 'form_partial_test'
474
+ expect(rendered_form).to match_css_pattern([
475
+ 'input.integer_filter.from',
476
+ 'input.integer_filter.to',
477
+ ".enum_filter input[value='1']",
478
+ ".enum_filter input[value='2']",
479
+ ])
480
+ end
458
481
  end
459
482
 
460
483
 
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Datagrid stylesheet" do
4
+
5
+ pending "should work correctly" do
6
+ Rails.application.assets.find_asset("datagrid")
7
+ end
8
+ end
@@ -2,9 +2,11 @@ require 'spec_helper'
2
2
  require "datagrid/rspec"
3
3
 
4
4
 
5
- describe SimpleReport do
5
+ describe Datagrid do
6
6
 
7
- it_should_behave_like 'Datagrid'
7
+ describe SimpleReport do
8
+ it_should_behave_like 'Datagrid'
9
+ end
8
10
 
9
11
  let(:group) { Group.create!(:name => "Pop") }
10
12
 
@@ -31,6 +31,8 @@ require "logger"
31
31
 
32
32
  class DatagridTest < Rails::Application
33
33
 
34
+ config.eager_load = false
35
+
34
36
  end
35
37
 
36
38
  if I18n.respond_to?(:enforce_available_locales)
@@ -0,0 +1,7 @@
1
+ def store_translations(locale, translations, &block)
2
+ I18n.backend.store_translations locale, translations
3
+ yield
4
+ ensure
5
+ I18n.reload!
6
+ I18n.backend.send :init_translations
7
+ end
@@ -42,6 +42,11 @@ end
42
42
  class CssPattern
43
43
  def initialize(pattern)
44
44
  @css_pattern = pattern
45
+ unless @css_pattern.is_a?(Hash)
46
+ @css_pattern = Array(@css_pattern).map do |key|
47
+ [key, 1]
48
+ end
49
+ end
45
50
  end
46
51
 
47
52
  def error!(message)
@@ -33,7 +33,7 @@ class SimpleReport
33
33
  filter(:confirmed, :boolean)
34
34
 
35
35
  filter(:name) do |value|
36
- self.scoped(:conditions => {:name => value})
36
+ self.where(:name => value)
37
37
  end
38
38
 
39
39
  column(:group, :order => "groups.name") do
@@ -61,3 +61,4 @@ class SimpleReport
61
61
  end
62
62
 
63
63
  end
64
+
@@ -0,0 +1,7 @@
1
+ <%= form_for grid, options do |f| -%>
2
+ <p>form_partial_test</p>
3
+ <% grid.filters.each do |filter| %>
4
+ <%= f.datagrid_label filter %>
5
+ <%= f.datagrid_filter filter, partials: options[:partials] %>
6
+ <% end %>
7
+ <% end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -195,7 +195,7 @@ files:
195
195
  - Rakefile
196
196
  - Readme.markdown
197
197
  - VERSION
198
- - app/assets/stylesheets/datagrid.css.sass
198
+ - app/assets/stylesheets/datagrid.sass
199
199
  - app/views/datagrid/_enum_checkboxes.html.erb
200
200
  - app/views/datagrid/_form.html.erb
201
201
  - app/views/datagrid/_head.html.erb
@@ -266,13 +266,13 @@ files:
266
266
  - spec/datagrid/helper_spec.rb
267
267
  - spec/datagrid/ordering_spec.rb
268
268
  - spec/datagrid/scaffold_spec.rb
269
+ - spec/datagrid/stylesheet_spec.rb
269
270
  - spec/datagrid/utils_spec.rb
270
271
  - spec/datagrid_spec.rb
271
272
  - spec/spec_helper.rb
272
273
  - spec/support/active_record.rb
273
274
  - spec/support/configuration.rb
274
- - spec/support/locale/deprecated_range_format.yml
275
- - spec/support/locale/deprecated_range_separator.yml
275
+ - spec/support/i18n_helpers.rb
276
276
  - spec/support/matchers.rb
277
277
  - spec/support/mongo_mapper.rb
278
278
  - spec/support/mongoid.rb
@@ -283,6 +283,9 @@ files:
283
283
  - spec/support/test_partials/client/datagrid/_order_for.html.erb
284
284
  - spec/support/test_partials/client/datagrid/_row.html.erb
285
285
  - spec/support/test_partials/client/datagrid/_table.html.erb
286
+ - spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb
287
+ - spec/support/test_partials/custom_form/_form.html.erb
288
+ - spec/support/test_partials/custom_range/_range_filter.html.erb
286
289
  - templates/controller.rb.erb
287
290
  - templates/grid.rb.erb
288
291
  - templates/index.html.erb
@@ -1,7 +0,0 @@
1
- en:
2
- datagrid:
3
- filters:
4
- integer:
5
- range_format:
6
- "from %{from_input} to %{to_input}"
7
-
@@ -1,5 +0,0 @@
1
- en:
2
- datagrid:
3
- filters:
4
- integer:
5
- range_separator: " | "