datagrid 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/datagrid.gemspec +26 -164
  4. data/lib/datagrid/columns.rb +5 -10
  5. data/lib/datagrid/filters.rb +3 -6
  6. data/lib/datagrid/filters/base_filter.rb +8 -0
  7. data/lib/datagrid/form_builder.rb +14 -13
  8. data/lib/datagrid/version.rb +3 -0
  9. metadata +10 -196
  10. data/.document +0 -5
  11. data/.rspec +0 -1
  12. data/.travis.yml +0 -23
  13. data/Gemfile +0 -33
  14. data/Rakefile +0 -43
  15. data/VERSION +0 -1
  16. data/spec/datagrid/active_model_spec.rb +0 -33
  17. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  18. data/spec/datagrid/columns/column_spec.rb +0 -19
  19. data/spec/datagrid/columns_spec.rb +0 -592
  20. data/spec/datagrid/core_spec.rb +0 -210
  21. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  22. data/spec/datagrid/drivers/array_spec.rb +0 -106
  23. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  24. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  25. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  26. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  27. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  28. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  29. data/spec/datagrid/filters/date_filter_spec.rb +0 -198
  30. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  31. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  32. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  33. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  34. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  35. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  36. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  37. data/spec/datagrid/filters_spec.rb +0 -332
  38. data/spec/datagrid/form_builder_spec.rb +0 -611
  39. data/spec/datagrid/helper_spec.rb +0 -683
  40. data/spec/datagrid/ordering_spec.rb +0 -150
  41. data/spec/datagrid/scaffold_spec.rb +0 -45
  42. data/spec/datagrid/stylesheet_spec.rb +0 -12
  43. data/spec/datagrid/utils_spec.rb +0 -19
  44. data/spec/datagrid_spec.rb +0 -94
  45. data/spec/spec_helper.rb +0 -123
  46. data/spec/support/active_record.rb +0 -38
  47. data/spec/support/configuration.rb +0 -28
  48. data/spec/support/i18n_helpers.rb +0 -6
  49. data/spec/support/matchers.rb +0 -101
  50. data/spec/support/mongo_mapper.rb +0 -32
  51. data/spec/support/mongoid.rb +0 -36
  52. data/spec/support/sequel.rb +0 -39
  53. data/spec/support/simple_report.rb +0 -64
  54. data/spec/support/test_partials/_actions.html.erb +0 -1
  55. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  56. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  57. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  58. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  59. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  60. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  61. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  62. data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,38 +0,0 @@
1
- require "sqlite3"
2
-
3
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
4
- #ActiveRecord::Base.configurations = true
5
-
6
- ActiveRecord::Base.logger = TEST_LOGGER
7
-
8
-
9
-
10
-
11
- ActiveRecord::Schema.verbose = false
12
- ActiveRecord::Schema.define(:version => 1) do
13
-
14
- create_table :entries do |t|
15
- t.integer :group_id
16
- t.string :name
17
- t.string :category
18
- t.string :access_level
19
- t.string :pet
20
- t.boolean :disabled, :null => false, :default => false
21
- t.boolean :confirmed, :null => false, :default => false
22
- t.date :shipping_date
23
- t.timestamps
24
- end
25
-
26
- create_table :groups do |t|
27
- t.string :name
28
- t.float :rating
29
- t.timestamps
30
- end
31
-
32
- class ::Entry < ActiveRecord::Base
33
- belongs_to :group
34
- end
35
- class ::Group < ActiveRecord::Base
36
- has_many :entries
37
- end
38
- end
@@ -1,28 +0,0 @@
1
- def with_date_format(format = "%m/%d/%Y")
2
- begin
3
- old_format = Datagrid.configuration.date_formats
4
- Datagrid.configure do |config|
5
- config.date_formats = format
6
- end
7
- yield
8
- ensure
9
- Datagrid.configure do |config|
10
- config.date_formats = old_format
11
- end
12
- end
13
- end
14
-
15
- def with_datetime_format(format = "%m/%d/%Y")
16
- begin
17
- old_format = Datagrid.configuration.datetime_formats
18
- Datagrid.configure do |config|
19
- config.datetime_formats = format
20
- end
21
- yield
22
- ensure
23
- Datagrid.configure do |config|
24
- config.datetime_formats = old_format
25
- end
26
- end
27
- end
28
-
@@ -1,6 +0,0 @@
1
- def store_translations(locale, translations, &block)
2
- I18n.backend.store_translations locale, translations
3
- yield
4
- ensure
5
- I18n.reload!
6
- end
@@ -1,101 +0,0 @@
1
- require "nokogiri"
2
-
3
- def equal_to_dom(text)
4
- EqualToDom.new(text)
5
- end
6
-
7
- def match_css_pattern(pattern)
8
- CssPattern.new(pattern)
9
- end
10
-
11
- class EqualToDom
12
-
13
- def initialize(expectation)
14
- @expectation = normalize(expectation)
15
- end
16
-
17
- def matches?(text)
18
- @matcher = normalize(text)
19
- @matcher == @expectation
20
- end
21
-
22
- def normalize(text)
23
- Nokogiri::HTML::DocumentFragment.parse(force_encoding(text.split("\n").map(&:strip).join(""))).to_s
24
- end
25
-
26
- def failure_message
27
- "Expected dom \n#{@matcher}\n to match \n#{@expectation}\n, but it wasn't"
28
- end
29
-
30
- def description
31
- "equal to dom #{@expectation[0..20]}"
32
- end
33
-
34
- private
35
-
36
- def force_encoding(text)
37
- "1.9.3".respond_to?(:force_encoding) ? text.clone.force_encoding("UTF-8") : text
38
- end
39
- end
40
-
41
-
42
- class CssPattern
43
- def initialize(pattern)
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
50
- end
51
-
52
- def error!(message)
53
- @error_message = message
54
- false
55
- end
56
-
57
- def failure_message
58
- @error_message || ""
59
- end
60
-
61
- def matches?(text)
62
- text = text.clone.force_encoding("UTF-8") if "1.9.3".respond_to? :force_encoding
63
-
64
- @matcher = Nokogiri::HTML::DocumentFragment.parse(text)
65
- @css_pattern.each do |css, amount_or_pattern_or_string_or_proc|
66
- path = @matcher.css(css)
67
- if amount_or_pattern_or_string_or_proc.is_a?(String) or amount_or_pattern_or_string_or_proc.is_a?(Regexp)
68
- pattern_or_string = amount_or_pattern_or_string_or_proc
69
- html = path.inner_html
70
- if !html.match(pattern_or_string)
71
- return error!("#{css.inspect} did not match #{pattern_or_string.inspect}. It was \n:#{html.inspect}")
72
- end
73
- elsif amount_or_pattern_or_string_or_proc.is_a? Numeric
74
- expected_amount = amount_or_pattern_or_string_or_proc
75
- amount = path.size
76
- if amount != expected_amount
77
- return error!("did not find #{css.inspect} #{expected_amount.inspect} times. It was #{amount.inspect}")
78
- end
79
- elsif amount_or_pattern_or_string_or_proc.is_a? Proc
80
- if !amount_or_pattern_or_string_or_proc.call(path)
81
- return error!("#{css.inspect} did not validate (proc must not return a falsy value)")
82
- end
83
- else
84
- raise "Instance of String, Rexexp, Proc or Fixnum required"
85
- end
86
- true
87
- end
88
- end
89
-
90
- def failure_message
91
- "Expected to match dom pattern. But it wasn't."
92
- end
93
-
94
- def failure_message_when_negated
95
- "Expected to not match dom pattern. But it was."
96
- end
97
-
98
- def description
99
- "match dom pattern"
100
- end
101
- end
@@ -1,32 +0,0 @@
1
- if defined?(MongoMapper)
2
-
3
- class MongoMapperEntry
4
- include MongoMapper::Document
5
-
6
- key :group_id, Integer
7
- key :name, String
8
- key :category, String
9
- key :disabled, Boolean, :default => false
10
- key :confirmed, Boolean, :default => false
11
- key :shipping_date, Time
12
- timestamps!
13
-
14
- end
15
-
16
- class MongoMapperGrid
17
- include ::Datagrid
18
-
19
- scope do
20
- MongoMapperEntry
21
- end
22
-
23
- filter :name
24
- integer_range_filters(:group_id, {:default => 0}, {:default => 100})
25
- filter :disabled, :xboolean
26
-
27
- column :name
28
- column :group_id
29
- column :disabled
30
-
31
- end
32
- end
@@ -1,36 +0,0 @@
1
- require "rubygems"
2
-
3
- #Mongoid.logger = TEST_LOGGER #TODO: understand why still output to STDOUT
4
-
5
-
6
- class MongoidEntry
7
-
8
- include Mongoid::Document
9
- include Mongoid::Timestamps
10
-
11
- field :group_id, :type => Integer
12
- field :name, :type => String
13
- field :category, :type => String
14
- field :disabled, :default => false, :type => Boolean
15
- field :confirmed, :default => false, :type => Boolean
16
- field :shipping_date, :type => Time
17
-
18
- end
19
-
20
- class MongoidGrid
21
- include ::Datagrid
22
-
23
- scope do
24
- MongoidEntry
25
- end
26
-
27
- filter :name
28
- integer_range_filters(:group_id, {:default => 0}, {:default => 100})
29
- filter :disabled, :xboolean
30
-
31
- column :name
32
- column :group_id
33
- column :disabled
34
-
35
- end
36
-
@@ -1,39 +0,0 @@
1
- require "sequel"
2
-
3
-
4
- DB = Sequel.sqlite # memory database
5
-
6
- DB.create_table :sequel_entries do
7
- primary_key :id
8
-
9
- Integer :group_id
10
- String :name
11
- String :category
12
- Boolean :disabled
13
- Boolean :confirmed
14
- Time :shipping_date
15
- Time :created_at
16
- end
17
-
18
- class SequelEntry < Sequel::Model
19
-
20
- end
21
-
22
-
23
- class SequelGrid
24
- include ::Datagrid
25
-
26
- scope do
27
- SequelEntry
28
- end
29
-
30
- filter :name
31
- integer_range_filters(:group_id, {:default => 0}, {:default => 100})
32
- filter :disabled, :xboolean
33
-
34
- column :name
35
- column :group_id
36
- column :disabled
37
-
38
- end
39
-
@@ -1,64 +0,0 @@
1
-
2
-
3
- def test_report(attributes = {}, &block)
4
- klass = test_report_class(&block)
5
- klass.new(attributes)
6
- end
7
-
8
- def test_report_class(&block)
9
- Class.new.tap do |klass|
10
- klass.class_eval do
11
- include Datagrid
12
- def self.name
13
- "TestGrid"
14
- end
15
- end
16
- if block
17
- klass.class_eval(&block)
18
- end
19
- end
20
- end
21
-
22
- class SimpleReport
23
-
24
- include Datagrid
25
-
26
- scope do
27
- ::Entry.includes(:group).order("entries.created_at")
28
- end
29
-
30
- filter(:group_id, :integer, :multiple => true)
31
- filter(:category, :enum, :select => ["first", "second"])
32
- filter(:disabled, :xboolean)
33
- filter(:confirmed, :boolean)
34
-
35
- filter(:name) do |value|
36
- self.where(:name => value)
37
- end
38
-
39
- column(:group, :order => "groups.name") do
40
- self.group.name
41
- end
42
-
43
- column(:name) do |user|
44
- user.name
45
- end
46
-
47
- column(:actions, :html => true) do |model|
48
- render :partial => "/actions", :locals => {:model => model}
49
- end
50
-
51
- column(:pet, :html => lambda {|data| content_tag :em, data}) do
52
- self.pet.try(:upcase)
53
- end
54
-
55
- column(:shipping_date, :before => :group)
56
-
57
- column(:access_level, :html => lambda {|data| content_tag :h1, data}, :after => :actions)
58
-
59
- def param_name
60
- :report
61
- end
62
-
63
- end
64
-
@@ -1 +0,0 @@
1
- <%= "No action for #{model.name}" -%>
@@ -1,13 +0,0 @@
1
- <%= form_for grid, options do |f| -%>
2
- <p>Namespaced form partial.</p>
3
- <% grid.filters.each do |filter| %>
4
- <div class="datagrid-filter filter">
5
- <%= f.datagrid_label filter %>
6
- <%= f.datagrid_filter filter %>
7
- </div>
8
- <% end %>
9
- <div class="datagrid-actions">
10
- <%= f.submit I18n.t("datagrid.form.search").html_safe, :class => "datagrid-submit" %>
11
- <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), :class => "datagrid-reset" %>
12
- </div>
13
- <% end -%>
@@ -1,9 +0,0 @@
1
- <tr>
2
- <p>Namespaced head partial.</p>
3
- <% grid.html_columns(*options[:columns]).each do |column| %>
4
- <th class="<%= datagrid_column_classes(grid, column) %>">
5
- <%= column.header %>
6
- <%= datagrid_order_for(grid, column, options) if column.order && options[:order]%>
7
- </th>
8
- <% end %>
9
- </tr>
@@ -1,11 +0,0 @@
1
- <div class="order">
2
- <p>Namespaced order_for partial.</p>
3
- <%= link_to(
4
- I18n.t("datagrid.table.order.asc").html_safe,
5
- url_for(grid.query_params(order: column.name, descending: false)),
6
- :class => "asc") %>
7
- <%= link_to(
8
- I18n.t("datagrid.table.order.desc").html_safe,
9
- url_for(grid.query_params(order: column.name, descending: true)),
10
- :class => "desc") %>
11
- </div>
@@ -1,6 +0,0 @@
1
- <tr>
2
- <p>Namespaced row partial.</p>
3
- <% grid.html_columns(*options[:columns]).each do |column| %>
4
- <td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
5
- <% end %>
6
- </tr>
@@ -1,19 +0,0 @@
1
- <%#
2
- Local variables:
3
- * grid - instance of Datagrid
4
- * assets - Array of database Entities
5
- * options - passed options Hash
6
- %>
7
- <p>Namespaced table partial.</p>
8
- <%= content_tag :table, options[:html] do %>
9
- <thead>
10
- <%= datagrid_header(grid, options) %>
11
- </thead>
12
- <tbody>
13
- <% if assets.empty? %>
14
- <tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
15
- <% else %>
16
- <%= datagrid_rows(grid, assets, **options) %>
17
- <% end %>
18
- </tbody>
19
- <% end %>
@@ -1 +0,0 @@
1
- custom_enum_checkboxes
@@ -1,7 +0,0 @@
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 -%>
@@ -1 +0,0 @@
1
- custom_range_partial