rgviz-rails 0.42 → 0.43
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rgviz_rails/executor.rb +26 -10
- data/spec/blueprints.rb +7 -0
- data/spec/models/pet.rb +3 -0
- data/spec/rgviz/executor_spec.rb +11 -2
- data/spec/spec_helper.rb +10 -0
- metadata +5 -4
data/lib/rgviz_rails/executor.rb
CHANGED
@@ -517,16 +517,32 @@ module Rgviz
|
|
517
517
|
col = klass.send(:columns).select{|x| x.name == name}.first
|
518
518
|
return [klass, col, joins] if col
|
519
519
|
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
520
|
+
offset = 0
|
521
|
+
while true
|
522
|
+
idx = name.index '_', offset
|
523
|
+
if not idx
|
524
|
+
# Try to see if the name is an association, and refer to the id
|
525
|
+
assoc = klass.send :reflect_on_association, name.to_sym
|
526
|
+
if assoc
|
527
|
+
col = klass.send(:columns).select{|x| x.name == assoc.association_foreign_key}.first
|
528
|
+
return [klass, col, joins] if col
|
529
|
+
end
|
530
|
+
return nil
|
531
|
+
end
|
532
|
+
|
533
|
+
before = name[0 ... idx]
|
534
|
+
new_name = name[idx + 1 .. -1]
|
535
|
+
|
536
|
+
assoc = klass.send :reflect_on_association, before.to_sym
|
537
|
+
if assoc
|
538
|
+
name = new_name
|
539
|
+
klass = assoc.klass
|
540
|
+
joins << assoc
|
541
|
+
break
|
542
|
+
end
|
543
|
+
|
544
|
+
offset = idx + 1
|
545
|
+
end
|
530
546
|
end
|
531
547
|
end
|
532
548
|
|
data/spec/blueprints.rb
CHANGED
data/spec/models/pet.rb
ADDED
data/spec/rgviz/executor_spec.rb
CHANGED
@@ -5,11 +5,12 @@ include Rgviz
|
|
5
5
|
|
6
6
|
describe Executor do
|
7
7
|
before :each do
|
8
|
-
[Person, City, Country].each &:delete_all
|
8
|
+
[Person, Pet, City, Country].each &:delete_all
|
9
9
|
end
|
10
10
|
|
11
11
|
def exec(query, options = {})
|
12
|
-
|
12
|
+
clazz = options[:class] || Person
|
13
|
+
exec = Executor.new clazz, query
|
13
14
|
exec.execute options
|
14
15
|
end
|
15
16
|
|
@@ -286,6 +287,14 @@ describe Executor do
|
|
286
287
|
|
287
288
|
it_processes_single_select_column "1 options no_values", 'c0', :number, nil, "1"
|
288
289
|
|
290
|
+
it_processes_single_select_column "1 where city is null", 'c0', :number, 1, "1" do
|
291
|
+
Person.make :city => nil
|
292
|
+
end
|
293
|
+
|
294
|
+
it_processes_single_select_column "the_city_name where the_city_name = 'foo'", 'the_city_name', :string, 'foo', "the_city_name", :class => Pet do
|
295
|
+
Pet.make :the_city => (City.make :name => 'foo')
|
296
|
+
end
|
297
|
+
|
289
298
|
it "processes pivot" do
|
290
299
|
Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
|
291
300
|
Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
|
data/spec/spec_helper.rb
CHANGED
@@ -32,9 +32,19 @@ ActiveRecord::Schema.define do
|
|
32
32
|
t.datetime "updated_at"
|
33
33
|
t.integer "city_id"
|
34
34
|
end
|
35
|
+
|
36
|
+
create_table "pets", :force => true do |t|
|
37
|
+
t.string "name"
|
38
|
+
t.integer "age"
|
39
|
+
t.date "birthday"
|
40
|
+
t.datetime "created_at"
|
41
|
+
t.datetime "updated_at"
|
42
|
+
t.integer "city_id"
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
require File.dirname(__FILE__) + '/models/person'
|
47
|
+
require File.dirname(__FILE__) + '/models/pet'
|
38
48
|
require File.dirname(__FILE__) + '/models/city'
|
39
49
|
require File.dirname(__FILE__) + '/models/country'
|
40
50
|
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgviz-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 93
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 43
|
9
|
+
version: "0.43"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ary Borenszweig
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-14 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- spec/models/city.rb
|
43
43
|
- spec/models/country.rb
|
44
44
|
- spec/models/person.rb
|
45
|
+
- spec/models/pet.rb
|
45
46
|
- spec/rgviz/executor_spec.rb
|
46
47
|
- README
|
47
48
|
has_rdoc: true
|