datagrid 1.5.9 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Readme.markdown +6 -4
  4. data/app/views/datagrid/_table.html.erb +1 -1
  5. data/datagrid.gemspec +29 -166
  6. data/lib/datagrid/column_names_attribute.rb +15 -16
  7. data/lib/datagrid/columns.rb +34 -37
  8. data/lib/datagrid/columns/column.rb +4 -0
  9. data/lib/datagrid/core.rb +13 -1
  10. data/lib/datagrid/drivers/active_record.rb +2 -1
  11. data/lib/datagrid/drivers/mongoid.rb +5 -1
  12. data/lib/datagrid/filters.rb +3 -6
  13. data/lib/datagrid/filters/base_filter.rb +8 -0
  14. data/lib/datagrid/filters/composite_filters.rb +4 -4
  15. data/lib/datagrid/form_builder.rb +18 -15
  16. data/lib/datagrid/helper.rb +3 -3
  17. data/lib/datagrid/renderer.rb +2 -5
  18. data/lib/datagrid/utils.rb +2 -6
  19. data/lib/datagrid/version.rb +3 -0
  20. metadata +15 -201
  21. data/.document +0 -5
  22. data/.rspec +0 -1
  23. data/.travis.yml +0 -21
  24. data/Gemfile +0 -29
  25. data/Rakefile +0 -43
  26. data/VERSION +0 -1
  27. data/spec/datagrid/active_model_spec.rb +0 -33
  28. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  29. data/spec/datagrid/columns/column_spec.rb +0 -19
  30. data/spec/datagrid/columns_spec.rb +0 -592
  31. data/spec/datagrid/core_spec.rb +0 -196
  32. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  33. data/spec/datagrid/drivers/array_spec.rb +0 -106
  34. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  35. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  36. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  37. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  38. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  39. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  40. data/spec/datagrid/filters/date_filter_spec.rb +0 -195
  41. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  42. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  43. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  44. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  45. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  46. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  47. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  48. data/spec/datagrid/filters_spec.rb +0 -332
  49. data/spec/datagrid/form_builder_spec.rb +0 -614
  50. data/spec/datagrid/helper_spec.rb +0 -640
  51. data/spec/datagrid/ordering_spec.rb +0 -150
  52. data/spec/datagrid/scaffold_spec.rb +0 -45
  53. data/spec/datagrid/stylesheet_spec.rb +0 -12
  54. data/spec/datagrid/utils_spec.rb +0 -19
  55. data/spec/datagrid_spec.rb +0 -83
  56. data/spec/spec_helper.rb +0 -114
  57. data/spec/support/active_record.rb +0 -38
  58. data/spec/support/configuration.rb +0 -28
  59. data/spec/support/i18n_helpers.rb +0 -6
  60. data/spec/support/matchers.rb +0 -101
  61. data/spec/support/mongo_mapper.rb +0 -32
  62. data/spec/support/mongoid.rb +0 -36
  63. data/spec/support/sequel.rb +0 -39
  64. data/spec/support/simple_report.rb +0 -64
  65. data/spec/support/test_partials/_actions.html.erb +0 -1
  66. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  67. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  68. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  69. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  70. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  71. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  72. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  73. data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Ordering do
4
-
5
-
6
- let!(:third) { Entry.create!(:name => "cc")}
7
- let!(:second) { Entry.create!(:name => "bb")}
8
- let!(:first) { Entry.create!(:name => "aa")}
9
-
10
-
11
- it "should support order" do
12
- expect(test_report(:order => "name") do
13
- scope do
14
- Entry
15
- end
16
- column :name
17
- end.assets).to eq([first, second, third])
18
-
19
- end
20
-
21
- it "should support desc order" do
22
- expect(test_report(:order => "name", :descending => true) do
23
- scope do
24
- Entry
25
- end
26
- column :name
27
- end.assets).to eq([third, second, first])
28
- end
29
-
30
-
31
- it "should raise error if ordered by not existing column" do
32
- expect {
33
- test_report(:order => :hello).assets
34
- }.to raise_error(Datagrid::OrderUnsupported)
35
- end
36
-
37
- it "should raise error if ordered by column without order" do
38
- expect do
39
- test_report(:order => :category) do
40
- filter(:category, :default, :order => false) do |value|
41
- self
42
- end
43
- end.assets
44
- end.to raise_error(Datagrid::OrderUnsupported)
45
- end
46
-
47
- it "should override default order" do
48
- expect(test_report(:order => :name) do
49
- scope { Entry.order("name desc")}
50
- column(:name, :order => "name asc")
51
- end.assets).to eq([first, second, third])
52
- end
53
-
54
- it "should support order given as block" do
55
- expect(test_report(:order => :name) do
56
- scope { Entry }
57
- column(:name, :order => proc { order("name desc") })
58
- end.assets).to eq([third, second, first])
59
- end
60
-
61
- it "should support reversing order given as block" do
62
- expect(test_report(:order => :name, :descending => true) do
63
- scope { Entry }
64
- column(:name, :order => proc { order("name desc") })
65
- end.assets).to eq([first, second, third])
66
- end
67
-
68
- it "should support order desc given as block" do
69
- expect(test_report(:order => :name, :descending => true) do
70
- scope { Entry }
71
- column(:name, :order_desc => proc { order("name desc")})
72
- end.assets).to eq([third, second, first])
73
- end
74
-
75
- it "should treat true order as default" do
76
- expect(test_report(:order => :name) do
77
- scope { Entry }
78
- column(:name, :order => true)
79
- end.assets).to eq([first, second, third])
80
- end
81
-
82
- it "should support order_by_value" do
83
- report = test_report(:order => :the_name) do
84
- scope {Entry}
85
- column(:the_name, :order_by_value => true) do
86
- name
87
- end
88
- end
89
- expect(report.assets).to eq([first, second, third])
90
- report.descending = true
91
- expect(report.assets).to eq([third, second, first])
92
- end
93
-
94
- it "should support order_by_value as block" do
95
-
96
- order = { :aa => 2, :bb => 3, :cc => 1}
97
- report = test_report(:order => :the_name) do
98
-
99
- scope {Entry}
100
- column(:the_name, :order_by_value => proc{|model| order[model.name.to_sym]}) do
101
- name
102
- end
103
- end
104
- expect(report.assets).to eq([third, first, second])
105
- report.descending = true
106
- expect(report.assets).to eq([second, first, third])
107
- end
108
-
109
- it "should work correctly with inherited classes" do
110
- class OrderInheritenceBase
111
- include Datagrid
112
- scope { Entry }
113
- end
114
-
115
- class OrderInheritenceChild < OrderInheritenceBase
116
- column(:name)
117
- end
118
-
119
- grid = OrderInheritenceChild.new(order: 'name')
120
- expect(grid.assets).to eq([first, second, third])
121
- grid.descending = true
122
- expect(grid.assets).to eq([third, second, first])
123
- end
124
- it "should support ordering by dynamic columns" do
125
-
126
- report = test_report(:order => "name") do
127
- scope {Entry}
128
- dynamic do
129
- column(:name)
130
- end
131
- end
132
-
133
- expect(report.assets).to eq([first, second, third])
134
-
135
- end
136
-
137
- it "should support #ordered_by? method" do
138
- report = test_report(:order => "name") do
139
- scope {Entry}
140
- column(:id)
141
- column(:name)
142
- end
143
- expect(report).to be_ordered_by(:name)
144
- expect(report).to be_ordered_by("name")
145
- expect(report).to be_ordered_by(report.column_by_name(:name))
146
- expect(report).to_not be_ordered_by(:id)
147
- expect(report).to_not be_ordered_by("id")
148
- expect(report).to_not be_ordered_by(report.column_by_name(:id))
149
- end
150
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Scaffold do
4
- subject { Datagrid::Scaffold.new(["user"]) }
5
-
6
-
7
- describe '.pagination_helper_code' do
8
- it 'uses kaminari by default' do
9
- expect(subject.pagination_helper_code).to eql('paginate(@grid.assets)')
10
- end
11
-
12
- context "when WillPaginate exists" do
13
- before(:each) do
14
- Object.const_set("WillPaginate", 1)
15
- end
16
- it 'uses willpaginate' do
17
- expect(subject.pagination_helper_code).to eql('will_paginate(@grid.assets)')
18
- end
19
-
20
- after(:each) do
21
- Object.send(:remove_const, "WillPaginate")
22
- end
23
- end
24
- end
25
-
26
- describe ".index_action" do
27
-
28
- it "works" do
29
- expect(subject.index_action).to eq(<<-RUBY)
30
- def index
31
- @grid = UsersGrid.new(grid_params) do |scope|
32
- scope.page(params[:page])
33
- end
34
- end
35
-
36
- protected
37
-
38
- def grid_params
39
- params.fetch(:users_grid, {}).permit!
40
- end
41
- RUBY
42
- end
43
-
44
- end
45
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Datagrid stylesheet" do
4
-
5
- it "should work correctly" do
6
-
7
- if Rails.application.assets.respond_to?(:find_asset)
8
- asset = Rails.application.assets.find_asset("datagrid")
9
- asset
10
- end
11
- end
12
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Utils do
4
-
5
-
6
- describe ".warn_once" do
7
- it "should work" do
8
- silence_warnings do
9
- expect(Datagrid::Utils.warn_once("hello", 0.2)).to eq(true)
10
- end
11
- sleep(0.1)
12
- expect(Datagrid::Utils.warn_once("hello", 0.2)).to eq(false)
13
- sleep(0.2)
14
- silence_warnings do
15
- expect(Datagrid::Utils.warn_once("hello", 0.2)).to eq(true)
16
- end
17
- end
18
- end
19
- end
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
- require "datagrid/rspec"
3
-
4
-
5
- describe Datagrid do
6
-
7
- describe SimpleReport do
8
- it_should_behave_like 'Datagrid'
9
- end
10
-
11
- let(:group) { Group.create!(:name => "Pop") }
12
-
13
- subject do
14
- SimpleReport.new(
15
- :group_id => group.id,
16
- :name => "Star",
17
- :category => "first",
18
- :disabled => false,
19
- :confirmed => false
20
- )
21
- end
22
-
23
- let!(:entry) { Entry.create!(
24
- :group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
25
- ) }
26
-
27
- describe '#assets' do
28
- subject { super().assets }
29
- it { should include(entry) }
30
- end
31
-
32
- describe ".attributes" do
33
- it "should return report attributes" do
34
- (subject.filters.map(&:name) + [:order, :descending]).each do |attribute|
35
- expect(subject.attributes).to have_key(attribute)
36
- end
37
- end
38
-
39
- end
40
-
41
- describe ".scope" do
42
- it "should return defined scope of objects" do
43
- expect(subject.scope).to respond_to(:each)
44
- end
45
-
46
-
47
- context "when not defined on class level" do
48
- subject do
49
- test_report {}
50
- end
51
-
52
- it "should raise ConfigurationError" do
53
- expect {
54
- subject.scope
55
- }.to raise_error(Datagrid::ConfigurationError)
56
-
57
- end
58
- end
59
- end
60
-
61
- describe ".batch_size" do
62
- context "when not defined on class level" do
63
- it "returns nil" do
64
- expect(subject.batch_size).to eq(nil)
65
- end
66
- end
67
-
68
- context "when defined in the grid class" do
69
- subject do
70
- test_report do
71
- self.batch_size = 25
72
- end
73
- end
74
-
75
- it "returns the configured batch size" do
76
- expect(subject.batch_size).to eq(25)
77
- end
78
- end
79
-
80
- end
81
-
82
-
83
- end
data/spec/spec_helper.rb DELETED
@@ -1,114 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- begin
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
10
- end
11
-
12
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
-
15
- require "active_record"
16
- require 'action_view'
17
- require "rails"
18
- require "mongoid"
19
- begin
20
- require 'mongo_mapper'
21
- rescue LoadError
22
- end
23
-
24
-
25
-
26
- require 'datagrid'
27
- begin
28
- require 'ruby-debug'
29
- rescue LoadError
30
- end
31
- require 'rspec'
32
- require "logger"
33
-
34
- class DatagridTest < Rails::Application
35
-
36
- config.eager_load = false
37
-
38
- end
39
-
40
- if I18n.respond_to?(:enforce_available_locales)
41
- I18n.enforce_available_locales = true
42
- end
43
-
44
- File.open('spec.log', "w").close
45
- TEST_LOGGER = Logger.new('spec.log')
46
- NO_MONGO = ENV['NO_MONGO']
47
-
48
- begin
49
- Mongoid.load_configuration({
50
- "clients" =>
51
- {
52
- "default" =>
53
- {
54
- "hosts" => ["localhost:27017"],
55
- "database" =>"datagrid_mongoid",
56
- "autocreate_indexes" => true,
57
- "logger" => nil,
58
- "options" => {
59
- "connect_timeout" => 2,
60
- wait_queue_timeout: 2
61
- }
62
- }
63
- }
64
- })
65
-
66
- Mongoid.client(:default).collections # check mongo connection
67
-
68
- if defined?(MongoMapper)
69
- MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
70
- MongoMapper.database = "datagrid_mongo_mapper"
71
- end
72
-
73
- rescue Mongo::Error::NoServerAvailable
74
- message = "Didn't find mongodb at localhost:27017."
75
- if NO_MONGO
76
- warn("MONGODB WARNING: #{message}. Skipping Mongoid and Mongomapper tests.")
77
- else
78
- raise "#{message}. Run with NO_MONGO=true env variable to skip mongodb tests"
79
- end
80
- end
81
-
82
- RSpec.configure do |config|
83
-
84
-
85
- config.after(:each) do
86
- #TODO better database truncation
87
- Group.delete_all
88
- Entry.delete_all
89
- SequelEntry.where({}).delete
90
- unless NO_MONGO
91
- MongoidEntry.delete_all
92
- MongoMapperEntry.delete_all if defined?(MongoMapperEntry)
93
- end
94
-
95
- end
96
-
97
- if NO_MONGO
98
- config.filter_run_excluding :mongoid => true
99
- config.filter_run_excluding :mongomapper => true
100
- end
101
-
102
- config.expect_with :rspec do |c|
103
- #c.syntax = :expect
104
- c.syntax = [:should, :expect]
105
- end
106
-
107
- end
108
-
109
-
110
-
111
- # Requires supporting files with custom matchers and macros, etc,
112
- # in ./support/ and its subdirectories.
113
- Dir["#{File.dirname(__FILE__)}/support/schema.rb"].each {|f| require f}
114
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -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