datagrid 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/datagrid.gemspec +26 -164
- data/lib/datagrid/columns.rb +5 -10
- data/lib/datagrid/filters.rb +3 -6
- data/lib/datagrid/filters/base_filter.rb +8 -0
- data/lib/datagrid/form_builder.rb +14 -13
- data/lib/datagrid/version.rb +3 -0
- metadata +10 -196
- data/.document +0 -5
- data/.rspec +0 -1
- data/.travis.yml +0 -23
- data/Gemfile +0 -33
- data/Rakefile +0 -43
- data/VERSION +0 -1
- data/spec/datagrid/active_model_spec.rb +0 -33
- data/spec/datagrid/column_names_attribute_spec.rb +0 -86
- data/spec/datagrid/columns/column_spec.rb +0 -19
- data/spec/datagrid/columns_spec.rb +0 -592
- data/spec/datagrid/core_spec.rb +0 -210
- data/spec/datagrid/drivers/active_record_spec.rb +0 -79
- data/spec/datagrid/drivers/array_spec.rb +0 -106
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
- data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
- data/spec/datagrid/drivers/sequel_spec.rb +0 -111
- data/spec/datagrid/filters/base_filter_spec.rb +0 -19
- data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
- data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
- data/spec/datagrid/filters/date_filter_spec.rb +0 -198
- data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
- data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
- data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
- data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
- data/spec/datagrid/filters/float_filter_spec.rb +0 -15
- data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
- data/spec/datagrid/filters/string_filter_spec.rb +0 -35
- data/spec/datagrid/filters_spec.rb +0 -332
- data/spec/datagrid/form_builder_spec.rb +0 -611
- data/spec/datagrid/helper_spec.rb +0 -683
- data/spec/datagrid/ordering_spec.rb +0 -150
- data/spec/datagrid/scaffold_spec.rb +0 -45
- data/spec/datagrid/stylesheet_spec.rb +0 -12
- data/spec/datagrid/utils_spec.rb +0 -19
- data/spec/datagrid_spec.rb +0 -94
- data/spec/spec_helper.rb +0 -123
- data/spec/support/active_record.rb +0 -38
- data/spec/support/configuration.rb +0 -28
- data/spec/support/i18n_helpers.rb +0 -6
- data/spec/support/matchers.rb +0 -101
- data/spec/support/mongo_mapper.rb +0 -32
- data/spec/support/mongoid.rb +0 -36
- data/spec/support/sequel.rb +0 -39
- data/spec/support/simple_report.rb +0 -64
- data/spec/support/test_partials/_actions.html.erb +0 -1
- data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
- data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
- data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
- data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
- data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
- data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
- data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
- 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
|
data/spec/datagrid/utils_spec.rb
DELETED
@@ -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
|
data/spec/datagrid_spec.rb
DELETED
@@ -1,94 +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 1000" do
|
64
|
-
expect(subject.batch_size).to eq(1000)
|
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
|
-
context "when set to nil in the grid class" do
|
81
|
-
subject do
|
82
|
-
test_report do
|
83
|
-
self.batch_size = nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns nil" do
|
88
|
-
expect(subject.batch_size).to eq(nil)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,123 +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
|
-
server_selection_timeout: 2,
|
62
|
-
socket_timeout: 1
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
})
|
67
|
-
|
68
|
-
Mongoid.client(:default).collections # check mongo connection
|
69
|
-
|
70
|
-
if defined?(MongoMapper)
|
71
|
-
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
|
72
|
-
MongoMapper.database = "datagrid_mongo_mapper"
|
73
|
-
end
|
74
|
-
|
75
|
-
rescue Mongo::Error::NoServerAvailable
|
76
|
-
message = "Didn't find mongodb at localhost:27017."
|
77
|
-
if NO_MONGO
|
78
|
-
warn("MONGODB WARNING: #{message}. Skipping Mongoid and Mongomapper tests.")
|
79
|
-
else
|
80
|
-
raise "#{message}. Run with NO_MONGO=true env variable to skip mongodb tests"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
RSpec.configure do |config|
|
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
|
-
end
|
107
|
-
|
108
|
-
def action_view_template
|
109
|
-
context = ActionView::LookupContext.new([
|
110
|
-
File.expand_path("../../app/views", __FILE__),
|
111
|
-
File.expand_path("../support/test_partials", __FILE__),
|
112
|
-
], {})
|
113
|
-
klass = ActionView::Base.respond_to?(:with_empty_template_cache) ? ActionView::Base.with_empty_template_cache : ActionView::Base
|
114
|
-
template = klass.new(context, {}, ::ActionController::Base.new)
|
115
|
-
allow(template).to receive(:protect_against_forgery?).and_return(false)
|
116
|
-
template
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
# Requires supporting files with custom matchers and macros, etc,
|
122
|
-
# in ./support/ and its subdirectories.
|
123
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|