fossil 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/fossil.gemspec +42 -3
- data/lib/fossil.rb +3 -2
- data/lib/hash_extentions.rb +20 -0
- data/lib/sequel/pervasive_adapter.rb +6 -6
- data/spec/be_model_with_values_matcher.rb +44 -0
- data/spec/be_model_with_values_matcher_spec.rb +46 -0
- data/spec/hash_extentions_spec.rb +20 -0
- data/spec/helper_classes.rb +30 -0
- data/spec/helper_methods.rb +49 -0
- data/spec/sequel/fos_dates_spec.rb +25 -0
- data/spec/sequel/model_patch_spec.rb +281 -0
- data/spec/sequel/pervasive_adapter_spec.rb +0 -0
- data/spec/sequel/serializer/json_serializer_spec.rb +21 -0
- data/spec/sequel/serializer/xml_serializer_spec.rb +105 -0
- data/spec/sequel/spec_helper_fos_tables.rb +94 -0
- data/spec/sequel/spec_helper_tables.rb +169 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +55 -0
- metadata +62 -6
data/Rakefile
CHANGED
@@ -8,8 +8,11 @@
|
|
8
8
|
gemspec.summary = "Sequel orm wrapper to FOS"
|
9
9
|
gemspec.description = "Access FOS/betrieve db with this Sequel based orm wrapper"
|
10
10
|
gemspec.email = "plardin@xojet.com"
|
11
|
-
gemspec.homepage = ""
|
12
|
-
gemspec.
|
11
|
+
gemspec.homepage = ""
|
12
|
+
gemspec.add_dependency('sequel', '= 3.5.0')
|
13
|
+
gemspec.add_dependency('active_support', '= 2.3.5')
|
14
|
+
gemspec.add_development_dependency('rspec')
|
15
|
+
gemspec.authors = ["Patrick Lardin, Daniel Sudol"]
|
13
16
|
end
|
14
17
|
Jeweler::GemcutterTasks.new
|
15
18
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/fossil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fossil}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Patrick Lardin, Daniel Sudol"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-12}
|
13
13
|
s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
|
14
14
|
s.email = %q{plardin@xojet.com}
|
15
15
|
s.files = [
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
"VERSION",
|
18
18
|
"fossil.gemspec",
|
19
19
|
"lib/fossil.rb",
|
20
|
+
"lib/hash_extentions.rb",
|
20
21
|
"lib/models/ac_qualification.rb",
|
21
22
|
"lib/models/aircraft.rb",
|
22
23
|
"lib/models/aircraft_cost.rb",
|
@@ -117,22 +118,60 @@ Gem::Specification.new do |s|
|
|
117
118
|
"lib/sequel/pervasive_adapter.rb",
|
118
119
|
"lib/sequel/serializer/json_serializer.rb",
|
119
120
|
"lib/sequel/serializer/serializer.rb",
|
120
|
-
"lib/sequel/serializer/xml_serializer.rb"
|
121
|
+
"lib/sequel/serializer/xml_serializer.rb",
|
122
|
+
"spec/be_model_with_values_matcher.rb",
|
123
|
+
"spec/be_model_with_values_matcher_spec.rb",
|
124
|
+
"spec/hash_extentions_spec.rb",
|
125
|
+
"spec/helper_classes.rb",
|
126
|
+
"spec/helper_methods.rb",
|
127
|
+
"spec/sequel/fos_dates_spec.rb",
|
128
|
+
"spec/sequel/model_patch_spec.rb",
|
129
|
+
"spec/sequel/pervasive_adapter_spec.rb",
|
130
|
+
"spec/sequel/serializer/json_serializer_spec.rb",
|
131
|
+
"spec/sequel/serializer/xml_serializer_spec.rb",
|
132
|
+
"spec/sequel/spec_helper_fos_tables.rb",
|
133
|
+
"spec/sequel/spec_helper_tables.rb",
|
134
|
+
"spec/spec.opts",
|
135
|
+
"spec/spec_helper.rb"
|
121
136
|
]
|
122
137
|
s.homepage = %q{}
|
123
138
|
s.rdoc_options = ["--charset=UTF-8"]
|
124
139
|
s.require_paths = ["lib"]
|
125
140
|
s.rubygems_version = %q{1.3.5}
|
126
141
|
s.summary = %q{Sequel orm wrapper to FOS}
|
142
|
+
s.test_files = [
|
143
|
+
"spec/be_model_with_values_matcher.rb",
|
144
|
+
"spec/be_model_with_values_matcher_spec.rb",
|
145
|
+
"spec/hash_extentions_spec.rb",
|
146
|
+
"spec/helper_classes.rb",
|
147
|
+
"spec/helper_methods.rb",
|
148
|
+
"spec/sequel/fos_dates_spec.rb",
|
149
|
+
"spec/sequel/model_patch_spec.rb",
|
150
|
+
"spec/sequel/pervasive_adapter_spec.rb",
|
151
|
+
"spec/sequel/serializer/json_serializer_spec.rb",
|
152
|
+
"spec/sequel/serializer/xml_serializer_spec.rb",
|
153
|
+
"spec/sequel/spec_helper_fos_tables.rb",
|
154
|
+
"spec/sequel/spec_helper_tables.rb",
|
155
|
+
"spec/spec_helper.rb"
|
156
|
+
]
|
127
157
|
|
128
158
|
if s.respond_to? :specification_version then
|
129
159
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
130
160
|
s.specification_version = 3
|
131
161
|
|
132
162
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
163
|
+
s.add_runtime_dependency(%q<sequel>, ["= 3.5.0"])
|
164
|
+
s.add_runtime_dependency(%q<active_support>, ["= 2.3.5"])
|
165
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
133
166
|
else
|
167
|
+
s.add_dependency(%q<sequel>, ["= 3.5.0"])
|
168
|
+
s.add_dependency(%q<active_support>, ["= 2.3.5"])
|
169
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
134
170
|
end
|
135
171
|
else
|
172
|
+
s.add_dependency(%q<sequel>, ["= 3.5.0"])
|
173
|
+
s.add_dependency(%q<active_support>, ["= 2.3.5"])
|
174
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
136
175
|
end
|
137
176
|
end
|
138
177
|
|
data/lib/fossil.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
begin
|
4
4
|
gem 'sequel', '=3.5.0'
|
5
|
-
|
5
|
+
require('sequel')
|
6
6
|
rescue LoadError => e
|
7
7
|
warn 'To use Fossil you need the sequel gem:'
|
8
8
|
warn '$ sudo gem install sequel -v=3.5.0'
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
begin
|
13
13
|
gem 'activesupport', '=2.3.5'
|
14
|
-
|
14
|
+
require('active_support')
|
15
15
|
rescue LoadError => e
|
16
16
|
p e
|
17
17
|
warn 'To use Fossil you need the active_support gem:'
|
@@ -21,6 +21,7 @@ end
|
|
21
21
|
|
22
22
|
dir = File.dirname(__FILE__)
|
23
23
|
files = [File.join(dir,'number_helper.rb')] +
|
24
|
+
[File.join(dir,'hash_extentions.rb')] +
|
24
25
|
[File.join(dir,'sequel','serializer','serializer.rb')] +
|
25
26
|
Dir.glob(File.join(dir,'sequel','*.rb')) +
|
26
27
|
Dir.glob(File.join(dir,'models','*.rb'))
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Hash
|
2
|
+
def limit_to_keys(limit_keys)
|
3
|
+
dup.limit_to_keys!(limit_keys)
|
4
|
+
end
|
5
|
+
|
6
|
+
def limit_to_keys!(limit_keys)
|
7
|
+
keys.each { |key| delete(key) unless limit_keys.include? key }
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def soft_delete(key)
|
12
|
+
cloned_hash = deep_clone
|
13
|
+
cloned_hash.delete(key)
|
14
|
+
cloned_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def deep_clone
|
18
|
+
Marshal::load(Marshal.dump(self))
|
19
|
+
end
|
20
|
+
end
|
@@ -11,12 +11,12 @@ module Sequel
|
|
11
11
|
ds.extend(DatasetMethods)
|
12
12
|
ds
|
13
13
|
end
|
14
|
-
|
15
|
-
def connect(server)
|
16
|
-
conn = super(server)
|
17
|
-
conn.autocommit = false if RAILS_ENV == 'test'
|
18
|
-
conn
|
19
|
-
end
|
14
|
+
|
15
|
+
# def connect(server)
|
16
|
+
# conn = super(server)
|
17
|
+
# conn.autocommit = false if RAILS_ENV == 'test'
|
18
|
+
# conn
|
19
|
+
# end
|
20
20
|
|
21
21
|
def select_fields(table, *fields)
|
22
22
|
dataset.select_fields(table, *fields)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module BeModelWithValuesMatcher
|
2
|
+
|
3
|
+
class BeModelWithValues
|
4
|
+
def initialize(expected_hash, compare_as_strings=false)
|
5
|
+
@compare_as_strings = compare_as_strings
|
6
|
+
@expected_hash = expected_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(model)
|
10
|
+
@model_hash = model.fill_hash(@expected_hash.keys)
|
11
|
+
@diff_keys = @expected_hash.keys - @model_hash.keys
|
12
|
+
@diff_act_values = {}
|
13
|
+
@diff_exp_values = {}
|
14
|
+
return false unless @diff_keys.empty?
|
15
|
+
@model_hash.each do |k,v|
|
16
|
+
model_value = @compare_as_strings ? @model_hash[k].to_s : @model_hash[k]
|
17
|
+
expected_value = @compare_as_strings ? @expected_hash[k].to_s : @expected_hash[k]
|
18
|
+
unless model_value == expected_value
|
19
|
+
@diff_act_values[k] = v
|
20
|
+
@diff_exp_values[k] = @expected_hash[k]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return @diff_act_values.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message
|
27
|
+
str = "expected:\n#{@expected_hash.inspect}\n but got:\n#{@model_hash.inspect}"
|
28
|
+
str += "\n\nmissing keys: #{@diff_keys.inspect}" unless @diff_keys.empty?
|
29
|
+
unless @diff_act_values.empty?
|
30
|
+
str += "\n\nunequal values: \nexpected: #{@diff_exp_values.inspect} \n but got:\n#{@diff_act_values.inspect}"
|
31
|
+
end
|
32
|
+
str
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def be_model_with_values(expected)
|
37
|
+
BeModelWithValues.new(expected)
|
38
|
+
end
|
39
|
+
|
40
|
+
def be_model_with_values_as_strings(expected)
|
41
|
+
BeModelWithValues.new(expected,true)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "spec matchers" do
|
4
|
+
|
5
|
+
describe "be_model_with_values matcher" do
|
6
|
+
|
7
|
+
it "should match a models values if they are all in the expected hash" do
|
8
|
+
dude = MockModel.new({:kid_date=>1, :kid_time=>2})
|
9
|
+
dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should match (as strings) a models values if they are all in the expected hash" do
|
13
|
+
dude = MockModel.new({:kid_date=>"1", :kid_time=>"2"})
|
14
|
+
dude.should be_model_with_values_as_strings( {:kid_date=>1, :kid_time=>2} )
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should fail match for models values if they are in the expected hash but of wrong type" do
|
18
|
+
dude = MockModel.new({:kid_date=>1, :kid_time=>"2"})
|
19
|
+
begin
|
20
|
+
dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
|
21
|
+
rescue => e
|
22
|
+
e.message.should match("unequal values: \nexpected: \\{:kid_time=>2\\} \n but got:\n\\{:kid_time=>\"2\"\\}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fail if model does not have all the keys as expected hash" do
|
27
|
+
dude = MockModel.new({:kid_date=>1})
|
28
|
+
begin
|
29
|
+
dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
|
30
|
+
rescue => e
|
31
|
+
e.message.should match("missing keys: \\[:kid_time\\]")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail if one of the values does not match" do
|
36
|
+
dude = MockModel.new( {:kid_date=>1, :kid_time=>3} )
|
37
|
+
begin
|
38
|
+
dude.should be_model_with_values( {:kid_date=>1, :kid_time=>2} )
|
39
|
+
rescue => e
|
40
|
+
e.message.should match("unequal values: \nexpected: \\{:kid_time=>2\\} \n but got:\n\\{:kid_time=>3\\}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "hash extentions" do
|
4
|
+
it "limit_to_keys should limit keys in hash" do
|
5
|
+
h = {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
|
6
|
+
h.limit_to_keys([:bro1,:bro2]).should == {:bro1=>'me',:bro2=>'rob'}
|
7
|
+
h.should == {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "limit_to_keys! should destructively limit keys in hash" do
|
11
|
+
h = {:bro1=>'me',:bro2=>'rob',:bro3=>'eric'}
|
12
|
+
h.limit_to_keys!([:bro1,:bro2]).should == {:bro1=>'me',:bro2=>'rob'}
|
13
|
+
h.should == {:bro1=>'me',:bro2=>'rob'}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "soft deletes" do
|
17
|
+
h = {:dan=>1,:eric=>2}
|
18
|
+
h.soft_delete(:dan).should == {:eric=>2}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class MockDataset < Sequel::Dataset
|
2
|
+
def insert(*args); end
|
3
|
+
def insert_select(*args); end
|
4
|
+
def update(*args); end
|
5
|
+
def fetch_rows(sql); end
|
6
|
+
def quoted_identifier(c); end
|
7
|
+
end
|
8
|
+
|
9
|
+
class MockDatabase < Sequel::Database
|
10
|
+
def execute(sql, opts={}); end
|
11
|
+
def reset; end
|
12
|
+
def transaction(opts={}); end
|
13
|
+
def dataset; MockDataset.new(self); end
|
14
|
+
end
|
15
|
+
|
16
|
+
MOCK_DB = MockDatabase.new unless defined?(MOCK_DB)
|
17
|
+
|
18
|
+
class MockModel < Sequel::Model(MOCK_DB)
|
19
|
+
def initialize(values)
|
20
|
+
@values = values
|
21
|
+
end
|
22
|
+
def respond_to?(m)
|
23
|
+
@values.has_key?(m)
|
24
|
+
end
|
25
|
+
def method_missing(m, *args, &block)
|
26
|
+
return @values[m] if @values.has_key?(m)
|
27
|
+
super(m, *args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module HelperMethods
|
2
|
+
|
3
|
+
def set_fos_db(models)
|
4
|
+
set_db(models,DB_FOS)
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_demo_db(models)
|
8
|
+
set_db(models,DB_DEMO)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_db(models,db)
|
12
|
+
models.each{ |model| model.db=db }
|
13
|
+
end
|
14
|
+
|
15
|
+
# delete other rows, and create new one
|
16
|
+
def add_test_table_data(hash)
|
17
|
+
DB_DEMO[:test_table].delete
|
18
|
+
DB_DEMO[:test_table] << hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_fos_fixture(file_name)
|
22
|
+
YAML.load_file(File.join(RAILS_ROOT,'spec','fos_fixtures',"#{file_name}.yml"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_ipc_fixture(file_name)
|
26
|
+
YAML.load_file(File.join(RAILS_ROOT,'spec','ipc_fixtures',"#{file_name}.yml"))
|
27
|
+
end
|
28
|
+
|
29
|
+
# controller helpers
|
30
|
+
def should_render_json_for(obj,path)
|
31
|
+
mock(obj).to_fos_json(is_a(Hash)) {"json"}
|
32
|
+
call_controller path
|
33
|
+
response.body.should == "json"
|
34
|
+
end
|
35
|
+
|
36
|
+
def should_render_xml_for(obj,path)
|
37
|
+
request.env["HTTP_ACCEPT"] = "application/xml"
|
38
|
+
mock(obj).to_fos_xml(is_a(Hash)) {"xml"}
|
39
|
+
call_controller path
|
40
|
+
response.body.should == "xml"
|
41
|
+
end
|
42
|
+
|
43
|
+
def equal_xml(other)
|
44
|
+
simple_matcher("xml #{other} not equal") do |actual|
|
45
|
+
actual.gsub(/\s/,'').should == other.gsub(/\s/,'')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "fos_dates" do
|
4
|
+
|
5
|
+
it "converts fos date number to a Ruby Date" do
|
6
|
+
Date.from_fos_days(10).should == Date.new(1900,1,10)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "converts fos time number to a Ruby Time" do
|
10
|
+
Time.from_fos_time(100).should == Time.utc(2000,"jan",1,1,40,0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "converts a Ruby Time to hundredths" do
|
14
|
+
Time.from_fos_time(100).in_hundredths.should == "1.7"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Date view defaults to y-m-d" do
|
18
|
+
Date.parse('Sept 9, 2009').to_s.should == "2009-09-09"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "Time view defaults to M:H" do
|
22
|
+
Time.parse('Sept 9, 2009 07:10').to_s.should == "07:10"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,281 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables
|
3
|
+
|
4
|
+
describe "Sequel::Model extentions" do
|
5
|
+
|
6
|
+
it "has fill_hash method" do
|
7
|
+
Dude.first.should respond_to(:fill_hash)
|
8
|
+
Dude.first.fill_hash([:'kid - date']).should == {:'kid - date'=>1}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can update and save" do
|
12
|
+
add_test_table_data({:date_col => 123, :time_col=>60})
|
13
|
+
record = TestTable.first
|
14
|
+
record[:'goofy name col'] = 124
|
15
|
+
record.save_changes
|
16
|
+
TestTable.first[:'goofy name col'].should ==124
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "select_fields method" do
|
20
|
+
|
21
|
+
it "works on model" do
|
22
|
+
dude = Dude.select_fields(:self => ['kid - date']).first
|
23
|
+
dude[:'kid - date'].should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "works on dataset" do
|
27
|
+
dude = Dude.filter(:'kid - date'=>1).select_fields(:self => ['kid - time']).first
|
28
|
+
dude[:'kid - time'].should == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "selects column alias" do
|
32
|
+
Dude.column_alias :kid_date, :'kid - date'
|
33
|
+
Dude.select_fields(:self => [:kid_date]).first.kid_date.should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can select more than one table with columns of the same name" do
|
37
|
+
# dude = Dude.eager_graph(:horses).select(*(Dude.pk_for_select + Horse.pk_for_select(:table=>:horses,:alias=>true) + [:'dudes__name', :'horses__name___horses_name'])).all.first
|
38
|
+
dude = Dude.eager_graph(:horses).select_fields(:self => [:name], :horses => [:name]).all.first
|
39
|
+
dude.name.should == "dano"
|
40
|
+
dude.horses.first.name.should == 'pinto'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "selects column alias from correct table" do
|
44
|
+
Dude.column_alias :doo, :'kid - date'
|
45
|
+
Horse.column_alias :hoo, :'kid - time'
|
46
|
+
dude = Dude.eager_graph(:horses).select_fields(:self => [:doo], :horses => [:hoo]).all.first
|
47
|
+
dude.doo.should == 1
|
48
|
+
dude.horses.first.hoo.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "selects particular columns from joined tables" do
|
52
|
+
dude = Dude.eager_graph(:ranch_code, :my_friend, :horses).select_fields(:self => [:name], :ranch_code => [:code], :my_friend => [:name], :horses => [:name]).all.first
|
53
|
+
dude.ranch_code_code.should == "men"
|
54
|
+
dude.name.should == "dano"
|
55
|
+
dude.horses.first.name.should == 'pinto'
|
56
|
+
dude.my_friend.name.should == 'dans buddy'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
describe "column_view" do
|
63
|
+
|
64
|
+
after :each do
|
65
|
+
TestTable.clear_schema
|
66
|
+
end
|
67
|
+
|
68
|
+
before do
|
69
|
+
add_test_table_data({:date_col => 123, :time_col=>60, :price=>1215, :paid=>1})
|
70
|
+
TestTable.column_view :date_col, :date
|
71
|
+
TestTable.column_view :time_col, :time
|
72
|
+
TestTable.column_view :time_col, :time, :my_special_name
|
73
|
+
TestTable.column_view :price, :currency
|
74
|
+
TestTable.column_view :price, :precision
|
75
|
+
TestTable.column_view :paid, :boolean
|
76
|
+
@record = TestTable.first
|
77
|
+
end
|
78
|
+
|
79
|
+
it "creates method to display value" do
|
80
|
+
@record.should respond_to(:date_col_date)
|
81
|
+
@record.should respond_to(:date_col_date_view)
|
82
|
+
@record.should respond_to(:date_col_date_view_mdy)
|
83
|
+
@record.should respond_to(:date_col_date_view_mdy_ipc)
|
84
|
+
@record.should respond_to(:time_col_time)
|
85
|
+
@record.should respond_to(:time_col_time_view)
|
86
|
+
@record.should respond_to(:price_currency)
|
87
|
+
@record.should respond_to(:price_precision)
|
88
|
+
@record.should respond_to(:paid_boolean)
|
89
|
+
@record.should respond_to(:my_special_name)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "shows correct date view" do
|
93
|
+
@record.date_col_date_view.should == "1900-05-03"
|
94
|
+
@record.date_col_date_view_mdy.should == "05/03/1900"
|
95
|
+
@record.date_col_date_view_mdy_ipc.should == "5/3/1900"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "shows correct time view" do
|
99
|
+
@record.time_col_time_view.should == "01:00"
|
100
|
+
@record.my_special_name_view.should == "01:00"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "shows correct currency view" do
|
104
|
+
@record.price_currency.should == "12.15"
|
105
|
+
@record.price_precision.should == "12.15"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "shows correct currency view" do
|
109
|
+
@record.paid_boolean.should == "True"
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "column_alias" do
|
115
|
+
|
116
|
+
before :each do
|
117
|
+
add_test_table_data({:id=>1, :'goofy name col' => 123})
|
118
|
+
end
|
119
|
+
|
120
|
+
after :each do
|
121
|
+
TestTable.clear_schema
|
122
|
+
end
|
123
|
+
|
124
|
+
it "makes alias" do
|
125
|
+
TestTable.column_alias :'nice_name', :'goofy name col'
|
126
|
+
|
127
|
+
TestTable.first.should respond_to(:nice_name)
|
128
|
+
TestTable.first.nice_name.should == 123
|
129
|
+
end
|
130
|
+
|
131
|
+
it "alias name also had entry in datatypes" do
|
132
|
+
TestTable.column_alias :'nice_name', :'goofy name col'
|
133
|
+
|
134
|
+
TestTable.db_schema[:nice_name].should_not be_nil
|
135
|
+
end
|
136
|
+
|
137
|
+
it "sets column type if param exists" do
|
138
|
+
TestTable.column_alias :'new_date_col', :'goofy name col', :type => :date
|
139
|
+
|
140
|
+
TestTable.first.new_date_col.should be_a_kind_of(Date)
|
141
|
+
TestTable.first.new_date_col.should == Date.from_fos_days(123)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "column alias expands to real column name in filtered search" do
|
145
|
+
TestTable.column_alias :'goofy_col', :'goofy name col'
|
146
|
+
TestTable.filter(:goofy_col=>123).first.goofy_col.should == 123
|
147
|
+
end
|
148
|
+
|
149
|
+
it "column alias creates setter to real column name" do
|
150
|
+
TestTable.column_alias :'goofy_col', :'goofy name col'
|
151
|
+
testrow = TestTable.first
|
152
|
+
testrow.goofy_col = 124
|
153
|
+
testrow.goofy_col.should == 124
|
154
|
+
end
|
155
|
+
|
156
|
+
# seems like ridiculous case, but it is a case in use
|
157
|
+
it "can makes an alias with same name and then an alias to that still works with existing record" do
|
158
|
+
add_test_table_data({:id=>2, :'date_col' => 10})
|
159
|
+
TestTable.column_alias :date_col, :'date_col' # our autogenerate script sometimes makes same name alias
|
160
|
+
TestTable.column_alias :save_date_col, :date_col, :type => :integer
|
161
|
+
testrow = TestTable.first
|
162
|
+
testrow.save_date_col = 11
|
163
|
+
testrow.date_col.should == 11
|
164
|
+
end
|
165
|
+
|
166
|
+
it "can makes an alias with same name and then an alias to that still works with new record" do
|
167
|
+
TestTable.column_alias :date_col, :'date_col' # our autogenerate script sometimes makes same name alias
|
168
|
+
TestTable.column_alias :save_date_col, :date_col, :type => :integer
|
169
|
+
testrow = TestTable.new({:save_date_col=>10})
|
170
|
+
testrow.save_date_col = 10
|
171
|
+
testrow.date_col.should == 10
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "column_type" do
|
177
|
+
|
178
|
+
before :each do
|
179
|
+
add_test_table_data({:date_col => 123, :time_col=>60})
|
180
|
+
end
|
181
|
+
|
182
|
+
after :each do
|
183
|
+
TestTable.clear_schema
|
184
|
+
end
|
185
|
+
|
186
|
+
it "sets a date type" do
|
187
|
+
TestTable.column_type :date_col, :date
|
188
|
+
|
189
|
+
TestTable.first[:date_col].should be_a_kind_of(Date)
|
190
|
+
TestTable.first[:date_col].should == Date.from_fos_days(123)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "sets a time type" do
|
194
|
+
TestTable.column_type :time_col, :time
|
195
|
+
|
196
|
+
TestTable.first[:time_col].should be_a_kind_of(DateTime)
|
197
|
+
TestTable.first[:time_col].should == Date.from_fos_days(0).to_time.utc + 60.minutes
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should find rows" do
|
201
|
+
TestTable.filter('date_col < ?', Date.today).all.size.should == 1
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "column_def" do
|
207
|
+
|
208
|
+
before do
|
209
|
+
add_test_table_data({:date_col => 39992, :time_col=>60})
|
210
|
+
end
|
211
|
+
|
212
|
+
it "datetime" do
|
213
|
+
TestTable.column_def_datetime :datetime_col, :date_col, :time_col
|
214
|
+
|
215
|
+
TestTable.first.should respond_to(:datetime_col)
|
216
|
+
TestTable.first.datetime_col.should == Time.parse("2009-06-29 01:00 UTC")
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "association methods" do
|
222
|
+
|
223
|
+
describe "code association" do
|
224
|
+
|
225
|
+
before(:each) do
|
226
|
+
set_demo_db([Code,Dude])
|
227
|
+
end
|
228
|
+
|
229
|
+
it "finds the associated code" do
|
230
|
+
Dude.first.ranch_code.description.should == 'manly ranch'
|
231
|
+
end
|
232
|
+
|
233
|
+
it "finds two associated codes" do
|
234
|
+
Dude.first.ranch_code.description.should == 'manly ranch'
|
235
|
+
Dude.first.pool_type.description.should == 'big round pool'
|
236
|
+
end
|
237
|
+
|
238
|
+
it "creates delegators for code and description" do
|
239
|
+
Dude.first.ranch_code_code.should == "men"
|
240
|
+
Dude.first.ranch_code_description.should == "manly ranch"
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should create a class method to get all codes for that type" do
|
244
|
+
Dude.should respond_to(:get_all_ranch_codes)
|
245
|
+
Dude.get_all_ranch_codes.should have(1).things
|
246
|
+
Dude.get_all_ranch_codes.first.should == 'manly ranch'
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "o_to_n" do
|
252
|
+
|
253
|
+
it "retrieves the association" do
|
254
|
+
Dude.first.horses.first.name.should == 'pinto'
|
255
|
+
end
|
256
|
+
|
257
|
+
it "retrieves association eagerly with eager graph" do
|
258
|
+
ds = Dude.eager_graph(:horses)
|
259
|
+
mock.proxy(ds).fetch_rows(is_a(String)).times(1)
|
260
|
+
ds.all.first.horses.first
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "n_to_o" do
|
266
|
+
|
267
|
+
it "retrieves the association" do
|
268
|
+
Horse.first.dude.name.should == 'dano'
|
269
|
+
end
|
270
|
+
|
271
|
+
it "retrieves association eagerly" do
|
272
|
+
ds = Horse.eager_graph(:dude).select()
|
273
|
+
mock.proxy(ds).fetch_rows(is_a(String)).times(1)
|
274
|
+
ds.all.first.dude
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables
|
3
|
+
|
4
|
+
describe "Sequel::Serializer" do
|
5
|
+
describe "to_fos_json method adds options to only for" do
|
6
|
+
it "single sequel model" do
|
7
|
+
add_test_table_data({:id=>1,:'goofy name col' => 123})
|
8
|
+
data = TestTable.first
|
9
|
+
mock(data).to_json({:only=>[]})
|
10
|
+
data.to_fos_json
|
11
|
+
end
|
12
|
+
|
13
|
+
it "an array of sequel models" do
|
14
|
+
add_test_table_data({:id=>1,:'goofy name col' => 123})
|
15
|
+
data = [TestTable.first]
|
16
|
+
mock(data).to_json({:only=>[]})
|
17
|
+
data.to_fos_json
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables
|
3
|
+
require 'active_resource'
|
4
|
+
|
5
|
+
describe "Sequel::Serializer" do
|
6
|
+
|
7
|
+
describe "to_fos_xml method adds options to skip instructions, dasherize, and only for" do
|
8
|
+
it "single sequel model" do
|
9
|
+
add_test_table_data({:id=>1,:'goofy name col' => 123})
|
10
|
+
data = TestTable.first
|
11
|
+
mock(data).to_xml({:dasherize=>false, :skip_instruct=>true, :only=>[]})
|
12
|
+
data.to_fos_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "an array of sequel models" do
|
16
|
+
add_test_table_data({:id=>1,:'goofy name col' => 123})
|
17
|
+
data = [TestTable.first]
|
18
|
+
mock(data).to_xml({:dasherize=>false, :skip_instruct=>true, :only=>[]})
|
19
|
+
data.to_fos_xml
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "to_xml works with references to aliased columns" do
|
24
|
+
add_test_table_data({:id=>1,:'goofy name col' => 123})
|
25
|
+
TestTable.column_alias :'nice_name', :'goofy name col'
|
26
|
+
|
27
|
+
TestTable.first.to_fos_xml(:only => :nice_name).should equal_xml(
|
28
|
+
%{
|
29
|
+
<test_table>
|
30
|
+
<nice_name>123</nice_name>
|
31
|
+
</test_table>
|
32
|
+
} )
|
33
|
+
end
|
34
|
+
|
35
|
+
it "to_fos_xml with many to one assoc" do
|
36
|
+
Dude.o_to_n :horses, :class=>:Horse, :prefix => 'dude'
|
37
|
+
|
38
|
+
Dude.first.to_fos_xml(:only=> :name, :include=> :horses).should equal_xml(
|
39
|
+
%{ <dude>
|
40
|
+
<name>dano</name>
|
41
|
+
<horses type="array">
|
42
|
+
<horse> <name>pinto</name> </horse>
|
43
|
+
<horse> <name>silver</name> </horse>
|
44
|
+
</horses>
|
45
|
+
</dude>
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
it "to_xml with many to one assoc" do
|
51
|
+
Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude'
|
52
|
+
|
53
|
+
Horse.first.to_fos_xml(:only=> [:name], :include=> :dude).should equal_xml(
|
54
|
+
%{ <horse>
|
55
|
+
<name>pinto</name>
|
56
|
+
<dude> <name>dano</name> </dude>
|
57
|
+
</horse>
|
58
|
+
})
|
59
|
+
end
|
60
|
+
|
61
|
+
it "to_xml with array of horses" do
|
62
|
+
Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude'
|
63
|
+
|
64
|
+
Horse.all.to_fos_xml(:only=> [:name], :include=> :dude).should equal_xml(
|
65
|
+
%{ <horses type="array">
|
66
|
+
<horse> <name>pinto</name>
|
67
|
+
<dude> <name>dano</name> </dude>
|
68
|
+
</horse>
|
69
|
+
<horse> <name>silver</name>
|
70
|
+
<dude> <name>dano</name> </dude>
|
71
|
+
</horse>
|
72
|
+
</horses>
|
73
|
+
} )
|
74
|
+
end
|
75
|
+
|
76
|
+
it "converts to ActiveResource::Base from xml" do
|
77
|
+
class Dudeman < ActiveResource::Base; self.site = ""; end
|
78
|
+
hash = Hash.from_xml( Dude.first.to_xml(:only=> :name, :include=> :horses) )
|
79
|
+
dudeman = Dudeman.new( hash.values.first )
|
80
|
+
dudeman.name.should == 'dano'
|
81
|
+
dudeman.horses.size.should == 2
|
82
|
+
dudeman.horses.first.name == 'pinto'
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# it "creates sql model from xml" do
|
89
|
+
# hash = Hash.from_xml( Dude.first.to_xml(:only=> :name, :include=> :horses) )
|
90
|
+
# d = Dude.new(hash.values.first)
|
91
|
+
# end
|
92
|
+
|
93
|
+
# it "can take the flatten option to flatten associations" do
|
94
|
+
# Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude'
|
95
|
+
#
|
96
|
+
# Horse.all.to_xml(:flatten=>true, :only=> [:name], :include=> :dude).should equal_xml(
|
97
|
+
# %{ <?xml version="1.0" encoding="UTF-8"?>
|
98
|
+
# <horses type="array">
|
99
|
+
# <horse>
|
100
|
+
# <name>pinto</name>
|
101
|
+
# <name>dano</name>
|
102
|
+
# </horse>
|
103
|
+
# </horses>
|
104
|
+
# } )
|
105
|
+
# end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
DB_DEMO.create_table! :ztrip_legs do
|
2
|
+
Integer :'kid - date'
|
3
|
+
Integer :'kid - time'
|
4
|
+
Integer :'kid - user'
|
5
|
+
Integer :'kid - mult'
|
6
|
+
Integer :'kid - comm'
|
7
|
+
String :'name'
|
8
|
+
Integer :'ranch code'
|
9
|
+
Integer :'my friend kid - date'
|
10
|
+
Integer :'my friend kid - time'
|
11
|
+
Integer :'my friend kid - user'
|
12
|
+
Integer :'my friend kid - mult'
|
13
|
+
Integer :'my friend kid - comm'
|
14
|
+
end
|
15
|
+
|
16
|
+
DB_DEMO.create_table! :'my friends' do
|
17
|
+
Integer :'kid - date'
|
18
|
+
Integer :'kid - time'
|
19
|
+
Integer :'kid - user'
|
20
|
+
Integer :'kid - mult'
|
21
|
+
Integer :'kid - comm'
|
22
|
+
String :name
|
23
|
+
end
|
24
|
+
|
25
|
+
DB_DEMO.create_table! :'zcrew legs' do
|
26
|
+
String :'name'
|
27
|
+
Integer :'kid - date'
|
28
|
+
Integer :'kid - time'
|
29
|
+
Integer :'kid - user'
|
30
|
+
Integer :'kid - mult'
|
31
|
+
Integer :'kid - comm'
|
32
|
+
Integer :'dude kid - date'
|
33
|
+
Integer :'dude kid - time'
|
34
|
+
Integer :'dude kid - user'
|
35
|
+
Integer :'dude kid - mult'
|
36
|
+
Integer :'dude kid - comm'
|
37
|
+
end
|
38
|
+
|
39
|
+
DB_DEMO.create_table! :codes do
|
40
|
+
Integer :'kid - date'
|
41
|
+
Integer :'kid - time'
|
42
|
+
Integer :'kid - user'
|
43
|
+
Integer :'kid - mult'
|
44
|
+
Integer :'kid - comm'
|
45
|
+
String :'description'
|
46
|
+
String :'code'
|
47
|
+
Integer :'value'
|
48
|
+
String :'name'
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
DB_DEMO[:dudes] << { :name=>'dano',:'ranch code'=>1,
|
53
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1,
|
54
|
+
:'my friend kid - date'=>1,:'my friend kid - time'=>1,:'my friend kid - user'=>1,:'my friend kid - mult'=>1,:'my friend kid - comm'=>1}
|
55
|
+
|
56
|
+
DB_DEMO[:'my friends'] << {:name=>'good buddy',
|
57
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1}
|
58
|
+
|
59
|
+
DB_DEMO[:'the horses'] << {:name=>'pinto',
|
60
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1,
|
61
|
+
:'dude kid - date'=>1,:'dude kid - time'=>1,:'dude kid - user'=>1,:'dude kid - mult'=>1,:'dude kid - comm'=>1}
|
62
|
+
|
63
|
+
DB_DEMO[:codes] << {:value=>1, :name=>'ranch_id__', :description=>'manly ranch', :code=>'men',
|
64
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1}
|
65
|
+
|
66
|
+
|
67
|
+
class TestTable < Sequel::Model(:test_table)
|
68
|
+
set_primary_key [:id]
|
69
|
+
end
|
70
|
+
|
71
|
+
class Dude < Sequel::Model(:dudes)
|
72
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
73
|
+
end
|
74
|
+
|
75
|
+
class MyFriend < Sequel::Model(:'my friends')
|
76
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
77
|
+
end
|
78
|
+
|
79
|
+
class Horse < Sequel::Model(:'the horses')
|
80
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
81
|
+
end
|
82
|
+
|
83
|
+
class Code < Sequel::Model(:codes)
|
84
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
85
|
+
def Code.get_codes(code_name)
|
86
|
+
self.filter(:name=>code_name).collect(&:description)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
module CodeGroup
|
92
|
+
def CodeGroup.ranch_id; 'ranch_id__'; end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
DB_DEMO.create_table!(:test_table) do
|
2
|
+
Integer :id
|
3
|
+
Integer :'goofy name col'
|
4
|
+
Integer :'date_col'
|
5
|
+
Integer :'time_col'
|
6
|
+
Integer :'price'
|
7
|
+
Integer :'paid'
|
8
|
+
end
|
9
|
+
|
10
|
+
DB_DEMO.create_table! :dudes do
|
11
|
+
Integer :'kid - date'
|
12
|
+
Integer :'kid - time'
|
13
|
+
Integer :'kid - user'
|
14
|
+
Integer :'kid - mult'
|
15
|
+
Integer :'kid - comm'
|
16
|
+
String :'name'
|
17
|
+
Integer :'ranch code'
|
18
|
+
Integer :'pool type'
|
19
|
+
Integer :'my friend kid - date'
|
20
|
+
Integer :'my friend kid - time'
|
21
|
+
Integer :'my friend kid - user'
|
22
|
+
Integer :'my friend kid - mult'
|
23
|
+
Integer :'my friend kid - comm'
|
24
|
+
end
|
25
|
+
|
26
|
+
DB_DEMO.create_table! :'my friends' do
|
27
|
+
Integer :'kid - date'
|
28
|
+
Integer :'kid - time'
|
29
|
+
Integer :'kid - user'
|
30
|
+
Integer :'kid - mult'
|
31
|
+
Integer :'kid - comm'
|
32
|
+
String :name
|
33
|
+
end
|
34
|
+
|
35
|
+
DB_DEMO.create_table! :'the horses' do
|
36
|
+
String :'name'
|
37
|
+
String :'goofy name'
|
38
|
+
Integer :'kid - date'
|
39
|
+
Integer :'kid - time'
|
40
|
+
Integer :'kid - user'
|
41
|
+
Integer :'kid - mult'
|
42
|
+
Integer :'kid - comm'
|
43
|
+
Integer :'dude kid - date'
|
44
|
+
Integer :'dude kid - time'
|
45
|
+
Integer :'dude kid - user'
|
46
|
+
Integer :'dude kid - mult'
|
47
|
+
Integer :'dude kid - comm'
|
48
|
+
end
|
49
|
+
|
50
|
+
DB_DEMO.create_table! :codes do
|
51
|
+
Integer :'kid - date'
|
52
|
+
Integer :'kid - time'
|
53
|
+
Integer :'kid - user'
|
54
|
+
Integer :'kid - mult'
|
55
|
+
Integer :'kid - comm'
|
56
|
+
String :'description'
|
57
|
+
String :'code'
|
58
|
+
Integer :'value'
|
59
|
+
String :'name'
|
60
|
+
end
|
61
|
+
|
62
|
+
module CodeGroup
|
63
|
+
def CodeGroup.ranch_id; 'ranch_id__'; end
|
64
|
+
def CodeGroup.pool_type; 'pool_id___'; end
|
65
|
+
end
|
66
|
+
|
67
|
+
Sequel::Model.db = DB_DEMO
|
68
|
+
|
69
|
+
class TestTable < Sequel::Model(:test_table)
|
70
|
+
set_primary_key [:id]
|
71
|
+
end
|
72
|
+
|
73
|
+
class Dude < Sequel::Model(:dudes)
|
74
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
75
|
+
|
76
|
+
code_association :ranch_code, :'ranch code', :ranch_id
|
77
|
+
code_association :pool_type, :'pool type', :pool_type
|
78
|
+
column_alias :kid_date, :'kid - date'
|
79
|
+
o_to_n :horses, :class=>:Horse, :prefix => 'dude'
|
80
|
+
n_to_o :one_horse, :class=>:Horse, :prefix => 'dude'
|
81
|
+
# many_to_one :one_horse, :class => :Horse, :key=>nil,
|
82
|
+
# :eager_loader=>(proc do |key_hash, parents, associations|
|
83
|
+
# id_map = {}
|
84
|
+
# parents.each do |p|
|
85
|
+
# key_arr = primary_key.map{|k| p[k]}
|
86
|
+
# id_map[key_arr] = p
|
87
|
+
# end
|
88
|
+
# prefix = 'dude'
|
89
|
+
# parent_to_child_keys = primary_key.collect{|k| (prefix + " " + k.to_s).to_sym }
|
90
|
+
# Horse.filter(parent_to_child_keys=>id_map.keys).all do |h|
|
91
|
+
# parent_key_values = parent_to_child_keys.collect{|k| h[k]}
|
92
|
+
# id_map[parent_key_values].associations[:one_horse] = h
|
93
|
+
# end
|
94
|
+
# end)
|
95
|
+
#
|
96
|
+
# one_to_many :my_horses, :class => :Horse, :key=>nil,
|
97
|
+
# :eager_loader=>(proc do |key_hash, parents, associations|
|
98
|
+
# id_map = {}
|
99
|
+
# parents.each do |p|
|
100
|
+
# key_arr = key_hash.keys[0].map{|k| p[k]}
|
101
|
+
# id_map[key_arr] = p
|
102
|
+
# end
|
103
|
+
# prefix = 'dude'
|
104
|
+
# parent_keys = key_hash.keys[0].collect{|j| (prefix + " " + j.to_s).to_sym }
|
105
|
+
# Horse.filter(parent_keys => id_map.keys).all do |h|
|
106
|
+
# parent_key_values = parent_keys.collect{|k| h[k]}
|
107
|
+
# if d = id_map[parent_key_values]
|
108
|
+
# d.associations[:my_horses] = [] unless d.associations[:my_horses]
|
109
|
+
# d.associations[:my_horses] << h
|
110
|
+
# end
|
111
|
+
# end
|
112
|
+
# end
|
113
|
+
# )
|
114
|
+
|
115
|
+
#:graph_only_conditions => { :'dude kid - date'=>:"kid - date", :'dude kid - time'=>:"kid - time", :'dude kid - user'=>:"kid - user", :'dude kid - mult'=>:"kid - mult", :'dude kid - comm'=>:"kid - comm", :pinto_horse__name=>'pinto'}
|
116
|
+
n_to_o :my_friend, :class=>:MyFriend, :prefix=>'my friend'
|
117
|
+
end
|
118
|
+
|
119
|
+
class MyFriend < Sequel::Model(:'my friends')
|
120
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
class Horse < Sequel::Model(:'the horses')
|
125
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
126
|
+
|
127
|
+
# validations do
|
128
|
+
# presence_of :name
|
129
|
+
# end
|
130
|
+
n_to_o :dude, :class=>:Dude, :prefix=>'dude'
|
131
|
+
end
|
132
|
+
|
133
|
+
#require 'memcache'
|
134
|
+
#CACHE = MemCache.new 'localhost:11211', :namespace => 'cachetest'
|
135
|
+
#Horse.plugin :caching, CACHE
|
136
|
+
|
137
|
+
class Code < Sequel::Model(:codes)
|
138
|
+
set_primary_key [:'kid - date',:'kid - time',:'kid - user',:'kid - mult',:'kid - comm']
|
139
|
+
|
140
|
+
def Code.get_codes(code_name)
|
141
|
+
self.filter(:name=>code_name).collect(&:description)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
DB_DEMO[:dudes] << { :name=>'dano',:'ranch code'=>1,:'pool type'=>2,
|
146
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1,
|
147
|
+
:'my friend kid - date'=>1,:'my friend kid - time'=>1,:'my friend kid - user'=>1,:'my friend kid - mult'=>1,:'my friend kid - comm'=>1}
|
148
|
+
DB_DEMO[:dudes] << { :name=>'eric',
|
149
|
+
:'kid - date'=>2,:'kid - time'=>2,:'kid - user'=>2,:'kid - mult'=>2,:'kid - comm'=>2,
|
150
|
+
:'my friend kid - date'=>2,:'my friend kid - time'=>2,:'my friend kid - user'=>2,:'my friend kid - mult'=>2,:'my friend kid - comm'=>2}
|
151
|
+
|
152
|
+
DB_DEMO[:'my friends'] << {:name=>'dans buddy',
|
153
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1}
|
154
|
+
DB_DEMO[:'my friends'] << {:name=>'erics buddy',
|
155
|
+
:'kid - date'=>2,:'kid - time'=>2,:'kid - user'=>2,:'kid - mult'=>2,:'kid - comm'=>2}
|
156
|
+
|
157
|
+
DB_DEMO[:'the horses'] << {:name=>'pinto', :'goofy name'=>'pinto-meister',
|
158
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1,
|
159
|
+
:'dude kid - date'=>1,:'dude kid - time'=>1,:'dude kid - user'=>1,:'dude kid - mult'=>1,:'dude kid - comm'=>1}
|
160
|
+
DB_DEMO[:'the horses'] << {:name=>'silver', :'goofy name'=>'heio silver',
|
161
|
+
:'kid - date'=>2,:'kid - time'=>2,:'kid - user'=>2,:'kid - mult'=>2,:'kid - comm'=>2,
|
162
|
+
:'dude kid - date'=>1,:'dude kid - time'=>1,:'dude kid - user'=>1,:'dude kid - mult'=>1,:'dude kid - comm'=>1}
|
163
|
+
|
164
|
+
DB_DEMO[:codes] << {:value=>1, :name=>'ranch_id__', :description=>'manly ranch', :code=>'men',
|
165
|
+
:'kid - date'=>1,:'kid - time'=>1,:'kid - user'=>1,:'kid - mult'=>1,:'kid - comm'=>1}
|
166
|
+
DB_DEMO[:codes] << {:value=>2, :name=>'pool_id___', :description=>'big round pool', :code=>'splash',
|
167
|
+
:'kid - date'=>2,:'kid - time'=>2,:'kid - user'=>2,:'kid - mult'=>2,:'kid - comm'=>2}
|
168
|
+
|
169
|
+
@@set_up_demo_tables = true
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
RAILS_ENV = "test"
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require 'lib/fossil'
|
6
|
+
require 'spec'
|
7
|
+
require 'rr'
|
8
|
+
|
9
|
+
unless defined?(DB_DEMO) #and defined?(DB_FOS)
|
10
|
+
DB_DEMO = Sequel.odbc('demodata')#, :loggers=>[Logger.new($stdout)])
|
11
|
+
DB_DEMO.extend(Sequel::Pervasive::DatabaseMethods)
|
12
|
+
|
13
|
+
DB_FOS = Sequel.odbc('fos')#, :loggers=>[Logger.new($stdout)])
|
14
|
+
DB_FOS.extend(Sequel::Pervasive::DatabaseMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + "/helper_methods"
|
18
|
+
require File.dirname(__FILE__) + "/helper_classes"
|
19
|
+
##### custom matchers #####
|
20
|
+
require File.dirname(__FILE__) + "/be_model_with_values_matcher"
|
21
|
+
|
22
|
+
|
23
|
+
Spec::Runner.configure do |config|
|
24
|
+
config.include(HelperMethods)
|
25
|
+
config.mock_with :rr
|
26
|
+
config.include(BeModelWithValuesMatcher)
|
27
|
+
end
|
28
|
+
|
29
|
+
################ these are special modifictations for testing with mysql db on non win platform ###################
|
30
|
+
unless RUBY_PLATFORM =~ /mswin32|linux/
|
31
|
+
# if its not windows ( pervasive db ) .. modify the pervasive adapter to act more like mysql for certain things
|
32
|
+
|
33
|
+
module Sequel::Pervasive::DatabaseMethods
|
34
|
+
def auto_increment_sql; "AUTO_INCREMENT" end
|
35
|
+
def begin_transaction_sql; "BEGIN" end
|
36
|
+
def commit_transaction_sql; "COMMIT" end
|
37
|
+
def rollback_transaction_sql; "ROLLBACK" end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Sequel::Pervasive::DatasetMethods
|
41
|
+
def quoted_identifier(name, convert=true)
|
42
|
+
convert ? "`#{convert_aliased_col_to_real_col(name)}`" : "`#{name}`"
|
43
|
+
end
|
44
|
+
|
45
|
+
def select_clause_methods
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def select_limit_sql(sql)
|
50
|
+
super(sql)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
################ end of special section ###################
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fossil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Lardin, Daniel Sudol
|
@@ -9,10 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sequel
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.5.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: active_support
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
16
45
|
description: Access FOS/betrieve db with this Sequel based orm wrapper
|
17
46
|
email: plardin@xojet.com
|
18
47
|
executables: []
|
@@ -26,6 +55,7 @@ files:
|
|
26
55
|
- VERSION
|
27
56
|
- fossil.gemspec
|
28
57
|
- lib/fossil.rb
|
58
|
+
- lib/hash_extentions.rb
|
29
59
|
- lib/models/ac_qualification.rb
|
30
60
|
- lib/models/aircraft.rb
|
31
61
|
- lib/models/aircraft_cost.rb
|
@@ -127,6 +157,20 @@ files:
|
|
127
157
|
- lib/sequel/serializer/json_serializer.rb
|
128
158
|
- lib/sequel/serializer/serializer.rb
|
129
159
|
- lib/sequel/serializer/xml_serializer.rb
|
160
|
+
- spec/be_model_with_values_matcher.rb
|
161
|
+
- spec/be_model_with_values_matcher_spec.rb
|
162
|
+
- spec/hash_extentions_spec.rb
|
163
|
+
- spec/helper_classes.rb
|
164
|
+
- spec/helper_methods.rb
|
165
|
+
- spec/sequel/fos_dates_spec.rb
|
166
|
+
- spec/sequel/model_patch_spec.rb
|
167
|
+
- spec/sequel/pervasive_adapter_spec.rb
|
168
|
+
- spec/sequel/serializer/json_serializer_spec.rb
|
169
|
+
- spec/sequel/serializer/xml_serializer_spec.rb
|
170
|
+
- spec/sequel/spec_helper_fos_tables.rb
|
171
|
+
- spec/sequel/spec_helper_tables.rb
|
172
|
+
- spec/spec.opts
|
173
|
+
- spec/spec_helper.rb
|
130
174
|
has_rdoc: true
|
131
175
|
homepage: ""
|
132
176
|
licenses: []
|
@@ -155,5 +199,17 @@ rubygems_version: 1.3.5
|
|
155
199
|
signing_key:
|
156
200
|
specification_version: 3
|
157
201
|
summary: Sequel orm wrapper to FOS
|
158
|
-
test_files:
|
159
|
-
|
202
|
+
test_files:
|
203
|
+
- spec/be_model_with_values_matcher.rb
|
204
|
+
- spec/be_model_with_values_matcher_spec.rb
|
205
|
+
- spec/hash_extentions_spec.rb
|
206
|
+
- spec/helper_classes.rb
|
207
|
+
- spec/helper_methods.rb
|
208
|
+
- spec/sequel/fos_dates_spec.rb
|
209
|
+
- spec/sequel/model_patch_spec.rb
|
210
|
+
- spec/sequel/pervasive_adapter_spec.rb
|
211
|
+
- spec/sequel/serializer/json_serializer_spec.rb
|
212
|
+
- spec/sequel/serializer/xml_serializer_spec.rb
|
213
|
+
- spec/sequel/spec_helper_fos_tables.rb
|
214
|
+
- spec/sequel/spec_helper_tables.rb
|
215
|
+
- spec/spec_helper.rb
|