datagrid 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe SimpleReport do
5
+
6
+ it_should_behave_like 'Datagrid'
7
+
8
+ let(:group) { Group.create!(:name => "Pop") }
9
+
10
+ subject do
11
+ SimpleReport.new(
12
+ :group_id => group.id,
13
+ :name => "Star",
14
+ :category => "first",
15
+ :disabled => false,
16
+ :confirmed => false
17
+ )
18
+ end
19
+
20
+ let!(:entry) { Entry.create!(
21
+ :group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
22
+ ) }
23
+
24
+ its(:assets) { should include(entry) }
25
+
26
+ describe ".attributes" do
27
+ it "should return report attributes" do
28
+ (subject.filters.map(&:name) + [:order, :reverse]).each do |attribute|
29
+ subject.attributes.should have_key(attribute)
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ describe ".scope" do
36
+ it "should return defined scope of objects" do
37
+ subject.scope.should respond_to(:table_name)
38
+ end
39
+
40
+
41
+ context "when not defined on class level" do
42
+ before(:each) do
43
+ SimpleReport.instance_variable_set("@scope", nil)
44
+ end
45
+
46
+ it "should raise ConfigurationError" do
47
+ lambda {
48
+ subject.scope
49
+ }.should raise_error(Datagrid::ConfigurationError)
50
+
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+
13
+ require 'rspec'
14
+ require "active_record"
15
+ require "will_paginate"
16
+ require 'datagrid'
17
+ require "datagrid/rspec"
18
+ require 'ruby-debug'
19
+
20
+
21
+ RSpec.configure do |config|
22
+
23
+
24
+ config.after(:each) do
25
+ #TODO better database truncation
26
+ Group.delete_all
27
+ Entry.delete_all
28
+
29
+ end
30
+
31
+
32
+ end
33
+
34
+
35
+
36
+ # Requires supporting files with custom matchers and macros, etc,
37
+ # in ./support/ and its subdirectories.
38
+ Dir["#{File.dirname(__FILE__)}/support/schema.rb"].each {|f| require f}
39
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,42 @@
1
+ require "nokogiri"
2
+
3
+ def equal_to_dom(text)
4
+ EqualToDom.new(text)
5
+ end
6
+
7
+
8
+ def include_dom(text)
9
+ IncludeDom.new(text)
10
+ end
11
+
12
+ class IncludeDom
13
+ def initialize(expectation)
14
+ @expectation = Nokogiri::HTML::DocumentFragment.parse(expectation).to_s
15
+ end
16
+
17
+ def matches?(text)
18
+ @matcher = Nokogiri::HTML::DocumentFragment.parse(text).to_s
19
+ @matcher.include?(@expectation)
20
+ end
21
+
22
+ def failure_message
23
+ "Expected dom #{@matcher} to include #{@expectation}, but it wasn't"
24
+ end
25
+ end
26
+
27
+
28
+ class EqualToDom
29
+
30
+ def initialize(expectation)
31
+ @expectation = Nokogiri::HTML::DocumentFragment.parse(expectation).to_s
32
+ end
33
+
34
+ def matches?(text)
35
+ @matcher = Nokogiri::HTML::DocumentFragment.parse(text).to_s
36
+ @matcher == @expectation
37
+ end
38
+
39
+ def failure_message
40
+ "Expected dom #{@matcher} to match #{@expectation}, but it wasn't"
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ require "logger"
2
+
3
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
4
+ ActiveRecord::Base.configurations = true
5
+
6
+ File.open('spec.log', "w").close
7
+ ActiveRecord::Base.logger = Logger.new('spec.log')
8
+
9
+
10
+
11
+ WillPaginate.enable
12
+
13
+ ActiveRecord::Schema.verbose = false
14
+ ActiveRecord::Schema.define(:version => 1) do
15
+
16
+ create_table :entries do |t|
17
+ t.integer :group_id
18
+ t.string :name
19
+ t.string :category
20
+ t.boolean :disabled, :null => false, :default => nil
21
+ t.boolean :confirmed, :null => false, :default => nil
22
+ end
23
+
24
+ create_table :groups do |t|
25
+ t.string :name
26
+ end
27
+
28
+ class ::Entry < ActiveRecord::Base
29
+ belongs_to :group
30
+ end
31
+ class ::Group < ActiveRecord::Base
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ class SimpleReport
2
+
3
+ include Datagrid
4
+
5
+
6
+ scope do
7
+ ::Entry.includes(:group)
8
+ end
9
+
10
+ filter(:group_id, :integer)
11
+ filter(:category, :enum, :select => ["first", "second"])
12
+ filter(:disabled, :eboolean)
13
+ filter(:confirmed, :boolean)
14
+ filter(:name) do |value|
15
+ self.scoped(:conditions => {:name => value})
16
+ end
17
+
18
+ column(:group, :order => "groups.name") do |model|
19
+ group.name
20
+ end
21
+
22
+ column(:name)
23
+
24
+ def param_name
25
+ :report
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,278 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datagrid
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Bogdan Gusiev
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-10 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 49
45
+ segments:
46
+ - 0
47
+ - 8
48
+ - 7
49
+ version: 0.8.7
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: mocha
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - "="
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 2
77
+ - 6
78
+ - 0
79
+ version: 2.6.0
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: bundler
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 23
91
+ segments:
92
+ - 1
93
+ - 0
94
+ - 0
95
+ version: 1.0.0
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 15
107
+ segments:
108
+ - 1
109
+ - 6
110
+ - 0
111
+ version: 1.6.0
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: rcov
115
+ type: :development
116
+ prerelease: false
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirement: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: ruby-debug
129
+ type: :development
130
+ prerelease: false
131
+ version_requirements: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ requirement: *id008
141
+ - !ruby/object:Gem::Dependency
142
+ name: sqlite3-ruby
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: &id009 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirement: *id009
155
+ - !ruby/object:Gem::Dependency
156
+ name: fastercsv
157
+ type: :development
158
+ prerelease: false
159
+ version_requirements: &id010 !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirement: *id010
169
+ - !ruby/object:Gem::Dependency
170
+ name: nokogiri
171
+ type: :development
172
+ prerelease: false
173
+ version_requirements: &id011 !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 3
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ requirement: *id011
183
+ - !ruby/object:Gem::Dependency
184
+ name: will_paginate
185
+ type: :development
186
+ prerelease: false
187
+ version_requirements: &id012 !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - "="
191
+ - !ruby/object:Gem::Version
192
+ hash: 29
193
+ segments:
194
+ - 2
195
+ - 3
196
+ - 15
197
+ version: 2.3.15
198
+ requirement: *id012
199
+ description: This allows you to easily build datagrid aka data tables with sortable columns and filters
200
+ email: agresso@gmail.com
201
+ executables: []
202
+
203
+ extensions: []
204
+
205
+ extra_rdoc_files:
206
+ - LICENSE.txt
207
+ - README.rdoc
208
+ files:
209
+ - .document
210
+ - .rspec
211
+ - Gemfile
212
+ - Gemfile.lock
213
+ - LICENSE.txt
214
+ - README.rdoc
215
+ - Rakefile
216
+ - Readme.md
217
+ - VERSION
218
+ - datagrid.gemspec
219
+ - lib/datagrid.rb
220
+ - lib/datagrid/columns.rb
221
+ - lib/datagrid/columns/column.rb
222
+ - lib/datagrid/core.rb
223
+ - lib/datagrid/filters.rb
224
+ - lib/datagrid/filters/base_filter.rb
225
+ - lib/datagrid/filters/boolean_enum_filter.rb
226
+ - lib/datagrid/filters/boolean_filter.rb
227
+ - lib/datagrid/filters/composite_filters.rb
228
+ - lib/datagrid/filters/date_filter.rb
229
+ - lib/datagrid/filters/default_filter.rb
230
+ - lib/datagrid/filters/enum_filter.rb
231
+ - lib/datagrid/filters/filter_eval.rb
232
+ - lib/datagrid/filters/integer_filter.rb
233
+ - lib/datagrid/form_builder.rb
234
+ - lib/datagrid/helper.rb
235
+ - lib/datagrid/rspec.rb
236
+ - spec/datagrid/form_builder_spec.rb
237
+ - spec/datagrid/helper_spec.rb
238
+ - spec/datagrid_spec.rb
239
+ - spec/spec_helper.rb
240
+ - spec/support/equal_to_dom.rb
241
+ - spec/support/schema.rb
242
+ - spec/support/simple_report.rb
243
+ has_rdoc: true
244
+ homepage: http://github.com/bogdan/datagrid
245
+ licenses:
246
+ - MIT
247
+ post_install_message:
248
+ rdoc_options: []
249
+
250
+ require_paths:
251
+ - lib
252
+ required_ruby_version: !ruby/object:Gem::Requirement
253
+ none: false
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ hash: 3
258
+ segments:
259
+ - 0
260
+ version: "0"
261
+ required_rubygems_version: !ruby/object:Gem::Requirement
262
+ none: false
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ hash: 3
267
+ segments:
268
+ - 0
269
+ version: "0"
270
+ requirements: []
271
+
272
+ rubyforge_project:
273
+ rubygems_version: 1.3.7
274
+ signing_key:
275
+ specification_version: 3
276
+ summary: Ruby gem to create datagrids
277
+ test_files: []
278
+