baza 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5f47d6cdffb1dd17d2d21f48fb8f9c6b0839b87
4
- data.tar.gz: 23363aeb34337a30ab40ac95a3e2f627e9daa84b
3
+ metadata.gz: f015976dbd7947d3e767c03acbe2c5d5483c1548
4
+ data.tar.gz: 2c1d7124db801479e2fcbeb1b48bc2bcc4305654
5
5
  SHA512:
6
- metadata.gz: 5f96d264eb5a7b392e3772e6fe578c24192a2936aaafb2035f60f8347257e73da2be2ec012d840b4cf58e9d780f20054cf995be3f27f8bee52047f5039e690b2
7
- data.tar.gz: 5be50aaefdf6c9fcab087547fa054f2ebe4295ee9347403c7b497b9b6e5e16c2bb6f24392a4e4cd27da84104e20dd48785e9d4648709a227f86410728c1d3728
6
+ metadata.gz: 2f28b9caab9178b57d0dd4576fa07914076a0c9b8305ba8fc853f301cd86473c0769113db5521a5b06a993809b39599ebad34bbed57368724e66d4ad5ce7f92a
7
+ data.tar.gz: 44fcf2c1583d49a375f6e1afff64b565901efb65c285d1dce8c31b96f8d04a619834182608018c7ff11c387861b81fea77a4d72300a4eeeb6bec2d2abd72d511
data/Gemfile CHANGED
@@ -5,9 +5,9 @@ source "http://rubygems.org"
5
5
 
6
6
  gem "datet", "~> 0.0.25"
7
7
  gem "wref", "~> 0.0.8"
8
- gem "knjrbfw", "~> 0.0.111"
9
8
  gem "array_enumerator", "~> 0.0.7"
10
9
  gem "string-cases", "~> 0.0.1"
10
+ gem 'event_handler', '~> 0.0.0'
11
11
 
12
12
  # Add dependencies to develop your gem here.
13
13
  # Include everything needed to run rake, tests, features, etc.
@@ -25,6 +25,7 @@ GEM
25
25
  thread_safe (~> 0.3, >= 0.3.1)
26
26
  diff-lcs (1.2.5)
27
27
  docile (1.1.5)
28
+ event_handler (0.0.0)
28
29
  faraday (0.9.0)
29
30
  multipart-post (>= 1.2, < 3)
30
31
  git (1.2.8)
@@ -38,8 +39,6 @@ GEM
38
39
  oauth2
39
40
  hashie (3.3.1)
40
41
  highline (1.6.21)
41
- http2 (0.0.30)
42
- string-cases
43
42
  i18n (0.6.11)
44
43
  jeweler (2.0.1)
45
44
  builder
@@ -53,13 +52,6 @@ GEM
53
52
  json (1.8.1)
54
53
  json (1.8.1-java)
55
54
  jwt (1.0.0)
56
- knjrbfw (0.0.111)
57
- datet
58
- http2
59
- php4r
60
- ruby_process
61
- tsafe
62
- wref (>= 0.0.8)
63
55
  mini_portile (0.6.0)
64
56
  minitest (5.4.2)
65
57
  multi_json (1.10.1)
@@ -75,10 +67,6 @@ GEM
75
67
  multi_json (~> 1.3)
76
68
  multi_xml (~> 0.5)
77
69
  rack (~> 1.2)
78
- php4r (0.0.4)
79
- datet
80
- http2
81
- string-strtr
82
70
  rack (1.5.2)
83
71
  rake (10.3.2)
84
72
  rdoc (4.1.2)
@@ -95,10 +83,6 @@ GEM
95
83
  rspec-mocks (3.1.3)
96
84
  rspec-support (~> 3.1.0)
97
85
  rspec-support (3.1.2)
98
- ruby_process (0.0.13)
99
- string-cases
100
- tsafe
101
- wref
102
86
  simplecov (0.9.1)
103
87
  docile (~> 1.1.0)
104
88
  multi_json (~> 1.0)
@@ -106,10 +90,8 @@ GEM
106
90
  simplecov-html (0.8.0)
107
91
  sqlite3 (1.3.10)
108
92
  string-cases (0.0.1)
109
- string-strtr (0.0.3)
110
93
  thread_safe (0.3.4)
111
94
  thread_safe (0.3.4-java)
112
- tsafe (0.0.11)
113
95
  tzinfo (1.2.2)
114
96
  thread_safe (~> 0.1)
115
97
  wref (0.0.8)
@@ -124,8 +106,8 @@ DEPENDENCIES
124
106
  bundler
125
107
  codeclimate-test-reporter
126
108
  datet (~> 0.0.25)
109
+ event_handler (~> 0.0.0)
127
110
  jeweler
128
- knjrbfw (~> 0.0.111)
129
111
  mysql2
130
112
  rdoc
131
113
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.16
1
+ 0.0.17
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: baza 0.0.16 ruby lib
5
+ # stub: baza 0.0.17 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "baza"
9
- s.version = "0.0.16"
9
+ s.version = "0.0.17"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kasper Johansen"]
14
- s.date = "2015-05-27"
14
+ s.date = "2015-05-31"
15
15
  s.description = "A database abstraction layer, model framework and database framework."
16
16
  s.email = "kj@gfish.com"
17
17
  s.extra_rdoc_files = [
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
57
57
  "include/drivers/sqlite3/sqlite3_table.rb",
58
58
  "include/drivers/sqlite3/sqlite3_tables.rb",
59
59
  "include/dump.rb",
60
+ "include/errors.rb",
60
61
  "include/idquery.rb",
61
62
  "include/index.rb",
62
63
  "include/model.rb",
@@ -98,9 +99,9 @@ Gem::Specification.new do |s|
98
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
99
100
  s.add_runtime_dependency(%q<datet>, ["~> 0.0.25"])
100
101
  s.add_runtime_dependency(%q<wref>, ["~> 0.0.8"])
101
- s.add_runtime_dependency(%q<knjrbfw>, ["~> 0.0.111"])
102
102
  s.add_runtime_dependency(%q<array_enumerator>, ["~> 0.0.7"])
103
103
  s.add_runtime_dependency(%q<string-cases>, ["~> 0.0.1"])
104
+ s.add_runtime_dependency(%q<event_handler>, ["~> 0.0.0"])
104
105
  s.add_development_dependency(%q<rspec>, [">= 0"])
105
106
  s.add_development_dependency(%q<rdoc>, [">= 0"])
106
107
  s.add_development_dependency(%q<bundler>, [">= 0"])
@@ -111,9 +112,9 @@ Gem::Specification.new do |s|
111
112
  else
112
113
  s.add_dependency(%q<datet>, ["~> 0.0.25"])
113
114
  s.add_dependency(%q<wref>, ["~> 0.0.8"])
114
- s.add_dependency(%q<knjrbfw>, ["~> 0.0.111"])
115
115
  s.add_dependency(%q<array_enumerator>, ["~> 0.0.7"])
116
116
  s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
117
+ s.add_dependency(%q<event_handler>, ["~> 0.0.0"])
117
118
  s.add_dependency(%q<rspec>, [">= 0"])
118
119
  s.add_dependency(%q<rdoc>, [">= 0"])
119
120
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -125,9 +126,9 @@ Gem::Specification.new do |s|
125
126
  else
126
127
  s.add_dependency(%q<datet>, ["~> 0.0.25"])
127
128
  s.add_dependency(%q<wref>, ["~> 0.0.8"])
128
- s.add_dependency(%q<knjrbfw>, ["~> 0.0.111"])
129
129
  s.add_dependency(%q<array_enumerator>, ["~> 0.0.7"])
130
130
  s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
131
+ s.add_dependency(%q<event_handler>, ["~> 0.0.0"])
131
132
  s.add_dependency(%q<rspec>, [">= 0"])
132
133
  s.add_dependency(%q<rdoc>, [">= 0"])
133
134
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -1,6 +1,3 @@
1
- require "knjrbfw"
2
- Knj.gem_require([:wref, :datet])
3
-
4
1
  #A wrapper of several possible database-types.
5
2
  #
6
3
  #===Examples
@@ -567,7 +564,8 @@ class Baza::Db
567
564
 
568
565
  if value.is_a?(Array)
569
566
  raise "Array for column '#{key}' was empty." if value.empty?
570
- sql << "#{@sep_col}#{key}#{@sep_col} IN (#{Knj::ArrayExt.join(arr: value, sep: ",", surr: "'", callback: proc{|ele| self.esc(ele)})})"
567
+ values = value.map { |v| "'#{escape(v)}'" }.join(',')
568
+ sql << "#{@sep_col}#{key}#{@sep_col} IN (#{values})"
571
569
  elsif value.is_a?(Hash)
572
570
  raise "Dont know how to handle hash."
573
571
  else
@@ -9,7 +9,7 @@ class Baza::Driver::Mysql::Column < Baza::Column
9
9
  @db = @args[:db]
10
10
  end
11
11
 
12
- #Used to validate in Knj::Wrap_map.
12
+ #Used to validate in Wref::Map.
13
13
  def __object_unique_id__
14
14
  return @name
15
15
  end
@@ -6,7 +6,7 @@ class Baza::Driver::Mysql::Index < Baza::Index
6
6
  @columns = []
7
7
  end
8
8
 
9
- #Used to validate in Knj::Wrap_map.
9
+ #Used to validate in Wref::Map.
10
10
  def __object_unique_id__
11
11
  return @args[:data][:Key_name]
12
12
  end
@@ -18,7 +18,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
18
18
  @data = @db.q("SHOW TABLE STATUS WHERE `Name` = '#{@db.esc(self.name)}'").fetch
19
19
  end
20
20
 
21
- #Used to validate in Knj::Wrap_map.
21
+ #Used to validate in Wref::Map.
22
22
  def __object_unique_id__
23
23
  return @data[:Name]
24
24
  end
@@ -0,0 +1,3 @@
1
+ class Baza::Errors
2
+ class Retry < RuntimeError; end
3
+ end
@@ -87,13 +87,7 @@ class Baza::Idquery
87
87
  return nil
88
88
  end
89
89
 
90
- ids_sql = Knj::ArrayExt.join(
91
- :arr => ids,
92
- :callback => proc{|val| @args[:db].esc(val)},
93
- :sep => ",",
94
- :surr => "'"
95
- )
96
-
90
+ ids_sql = ids.map { |id| "'#{@args[:db].esc(id)}'" }.join(',')
97
91
  query_str = "SELECT * FROM #{table_esc} WHERE #{table_esc}.#{col_esc} IN (#{ids_sql})"
98
92
  print "Query: #{query_str}\n" if @debug
99
93
 
@@ -5,7 +5,10 @@ class Baza::ModelHandler
5
5
  attr_reader :args, :events, :data, :ids_cache, :ids_cache_should
6
6
 
7
7
  def initialize(args)
8
- require "monitor"
8
+ require 'array_enumerator' if args[:array_enum]
9
+ require 'event_handler'
10
+ require 'monitor'
11
+ require 'ostruct'
9
12
 
10
13
  @callbacks = {}
11
14
  @args = args
@@ -18,11 +21,8 @@ class Baza::ModelHandler
18
21
  @data = {}
19
22
  @lock_require = Monitor.new
20
23
 
21
- Knj.gem_require(:Wref, "wref") if @args[:cache] == :weak and !Kernel.const_defined?(:Wref)
22
- require "#{@args[:array_enumerator_path]}array_enumerator" if @args[:array_enum] and !Kernel.const_defined?(:Array_enumerator)
23
-
24
24
  #Set up various events.
25
- @events = Knj::Event_handler.new
25
+ @events = EventHandler.new
26
26
  @events.add_event(:name => :no_html, :connections_max => 1)
27
27
  @events.add_event(:name => :no_name, :connections_max => 1)
28
28
  @events.add_event(:name => :no_date, :connections_max => 1)
@@ -67,7 +67,7 @@ class Baza::ModelHandler
67
67
  #Caches all IDs for a specific classname.
68
68
  def cache_ids(classname)
69
69
  classname = classname.to_sym
70
- return nil if !@ids_cache_should or !@ids_cache_should[classname]
70
+ return nil if !@ids_cache_should || !@ids_cache_should[classname]
71
71
 
72
72
  newcache = {}
73
73
  @args[:db].q("SELECT `#{@args[:col_id]}` FROM `#{classname}` ORDER BY `#{@args[:col_id]}`") do |data|
@@ -270,7 +270,7 @@ class Baza::ModelHandler
270
270
  classob = @args[:module].const_get(classname)
271
271
  end
272
272
 
273
- pass_arg = Knj::Hash_methods.new(:ob => self, :db => @args[:db])
273
+ pass_arg = OpenStruct.new(:ob => self, :db => @args[:db])
274
274
  classob.load_columns(pass_arg) if classob.respond_to?(:load_columns)
275
275
  classob.datarow_init(pass_arg) if classob.respond_to?(:datarow_init)
276
276
  end
@@ -444,7 +444,7 @@ class Baza::ModelHandler
444
444
  classob = @args[:module].const_get(classname)
445
445
 
446
446
  raise "list-function has not been implemented for '#{classname}'." if !classob.respond_to?("list")
447
- ret = classob.list(Knj::Hash_methods.new(:args => args, :ob => self, :db => @args[:db]), &block)
447
+ ret = classob.list(OpenStruct.new(:args => args, :ob => self, :db => @args[:db]), &block)
448
448
 
449
449
  #If 'ret' is an array and a block is given then the list-method didnt return blocks. We emulate it instead with the following code.
450
450
  if block and ret.is_a?(Array)
@@ -485,7 +485,11 @@ class Baza::ModelHandler
485
485
  end
486
486
  end
487
487
 
488
- return Knj.handle_return(:enum => enum, :block => block)
488
+ if block
489
+ enum.each(&block)
490
+ else
491
+ return ArrayEnumerator.new(enum)
492
+ end
489
493
  end
490
494
 
491
495
  #Returns select-options-HTML for inserting into a HTML-select-element.
@@ -554,7 +558,6 @@ class Baza::ModelHandler
554
558
 
555
559
  #Returns a hash which can be used to generate HTML-select-elements.
556
560
  def list_optshash(classname, args = {})
557
- Knj::ArrayExt.hash_sym(args)
558
561
  classname = classname.to_sym
559
562
 
560
563
  if args[:list_args].is_a?(Hash)
@@ -563,11 +566,7 @@ class Baza::ModelHandler
563
566
  list_args = {}
564
567
  end
565
568
 
566
- if RUBY_VERSION[0..2] == 1.8 and Php4r.class_exists("Dictionary")
567
- list = Dictionary.new
568
- else
569
- list = {}
570
- end
569
+ list = {}
571
570
 
572
571
  if args[:addnew] or args[:add]
573
572
  list["0"] = _("Add new")
@@ -649,7 +648,7 @@ class Baza::ModelHandler
649
648
 
650
649
  if @args[:custom]
651
650
  classobj = @args[:module].const_get(classname)
652
- retob = classobj.add(Knj::Hash_methods.new(
651
+ retob = classobj.add(OpenStruct.new(
653
652
  :ob => self,
654
653
  :data => data
655
654
  ))
@@ -657,7 +656,7 @@ class Baza::ModelHandler
657
656
  classobj = @args[:module].const_get(classname)
658
657
 
659
658
  #Run the class 'add'-method to check various data.
660
- classobj.add(Knj::Hash_methods.new(:ob => self, :db => @args[:db], :data => data)) if classobj.respond_to?(:add)
659
+ classobj.add(OpenStruct.new(:ob => self, :db => @args[:db], :data => data)) if classobj.respond_to?(:add)
661
660
 
662
661
  #Check if various required data is given. If not then raise an error telling about it.
663
662
  required_data = classobj.required_data
@@ -698,7 +697,7 @@ class Baza::ModelHandler
698
697
  def adds(classname, datas)
699
698
  if @args[:module].const_get(classname).respond_to?(:add)
700
699
  datas.each do |data|
701
- @args[:module].const_get(classname).add(Knj::Hash_methods.new(
700
+ @args[:module].const_get(classname).add(OpenStruct.new(
702
701
  :ob => self,
703
702
  :db => self.db,
704
703
  :data => data
@@ -721,7 +720,7 @@ class Baza::ModelHandler
721
720
  #Sometimes this raises the exception but actually responds to the class? Therefore commented out. - knj
722
721
  #raise "The class '#{class_obj.name}' has no such method: '#{method_name}' (#{class_obj.methods.sort.join(", ")})." if !class_obj.respond_to?(method_name)
723
722
 
724
- pass_args = [Knj::Hash_methods.new(:ob => self, :db => self.db)]
723
+ pass_args = [OpenStruct.new(:ob => self, :db => self.db)]
725
724
 
726
725
  args.each do |arg|
727
726
  pass_args << arg
@@ -888,7 +887,7 @@ class Baza::ModelHandler
888
887
  elsif @args[:cache] == :none
889
888
  return false
890
889
  else
891
- return false if !@objects.key?(classn)
890
+ return false unless @objects.key?(classn)
892
891
  @objects[classn] = {}
893
892
  GC.start
894
893
 
@@ -920,5 +919,3 @@ class Baza::ModelHandler
920
919
  return @objects.keys
921
920
  end
922
921
  end
923
-
924
- require "#{$knjpath}objects/objects_sqlhelper"
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  class Baza::ModelHandler
2
4
  #This method helps build SQL from Objects-instances list-method. It should not be called directly but only through Objects.list.
3
5
  def sqlhelper(list_args, args_def)
@@ -224,14 +226,7 @@ class Baza::ModelHandler
224
226
  if val.empty? and db.opts[:type].to_s == "mysql"
225
227
  sql_where << " AND false"
226
228
  else
227
- escape_sql = Knj::ArrayExt.join(
228
- :arr => val,
229
- :callback => proc{|value|
230
- db.escape(value)
231
- },
232
- :sep => ",",
233
- :surr => "'"
234
- )
229
+ escape_sql = val.map { |v| "'#{db.escape(v)}'" }.join(',')
235
230
  sql_where << " AND #{table}`#{db.esc_col(key)}` IN (#{escape_sql})"
236
231
  end
237
232
  elsif val.is_a?(Hash) and val[:type].to_sym == :col
@@ -241,7 +236,7 @@ class Baza::ModelHandler
241
236
  elsif val.is_a?(Hash) and val[:type] == :sqlval and val[:val] == :null
242
237
  sql_where << " AND #{table}`#{db.esc_col(key)}` IS NULL"
243
238
  elsif val.is_a?(Proc)
244
- call_args = Knj::Hash_methods.new(:ob => self, :db => db)
239
+ call_args = OpenStruct.new(:ob => self, :db => db)
245
240
  sql_where << " AND #{table}`#{db.esc_col(key)}` = '#{db.esc(val.call(call_args))}'"
246
241
  else
247
242
  sql_where << " AND #{table}`#{db.esc_col(key)}` = '#{db.esc(val)}'"
@@ -42,18 +42,18 @@ class Baza::Revision
42
42
 
43
43
  schema = args[:schema]
44
44
  db = args[:db]
45
- raise "No 'db' was given." if !db
45
+ raise "No 'db' was given." unless db
46
46
 
47
47
  schema.each do |key, val|
48
48
  raise "Invalid key for schema: '#{key}' (#{key.class.name})." unless INIT_DB_SCHEMA_ALLOWED_ARGS.include?(key)
49
49
  end
50
50
 
51
51
  #Check for normal bugs and raise apropiate error.
52
- raise "'schema' argument was not a Hash: '#{schema.class.name}'." if !schema.is_a?(Hash)
53
- raise "No tables given." if !schema.has_key?(:tables)
52
+ raise "'schema' argument was not a Hash: '#{schema.class.name}'." unless schema.is_a?(Hash)
53
+ raise "No tables given." unless schema.has_key?(:tables)
54
54
 
55
55
  #Cache tables to avoid constant reloading.
56
- if !args.key?(:tables_cache) or args[:tables_cache]
56
+ if !args.key?(:tables_cache) || args[:tables_cache]
57
57
  puts "Caching tables-list." if args[:debug]
58
58
  tables = db.tables.list
59
59
  else
@@ -157,7 +157,7 @@ class Baza::Revision
157
157
  callback_data = col_data[:on_before_alter].call(:db => db, :table => table_obj, :col => col_obj, :col_data => col_data)
158
158
  if callback_data and callback_data[:action]
159
159
  if callback_data[:action] == :retry
160
- raise Knj::Errors::Retry
160
+ raise Baza::Errors::Retry
161
161
  end
162
162
  end
163
163
  end
@@ -288,7 +288,7 @@ class Baza::Revision
288
288
  puts "Renaming table: '#{table_name_rename}' to '#{table_name}'." if args[:debug]
289
289
  table_rename = db.tables[table_name_rename.to_sym]
290
290
  table_rename.rename(table_name)
291
- raise Knj::Errors::Retry
291
+ raise Baza::Errors::Retry
292
292
  rescue Errno::ENOENT
293
293
  next
294
294
  end
@@ -317,7 +317,7 @@ class Baza::Revision
317
317
 
318
318
  rows_init(:db => db, :table => table_obj, :rows => table_data[:rows]) if table_data[:rows]
319
319
  end
320
- rescue Knj::Errors::Retry
320
+ rescue Baza::Errors::Retry
321
321
  retry
322
322
  end
323
323
  end
@@ -1,4 +1,6 @@
1
- require "string-cases"
1
+ require 'wref'
2
+ require 'datet'
3
+ require 'string-cases'
2
4
 
3
5
  class Baza
4
6
  #Autoloader for subclasses.
@@ -1,14 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Objects" do
4
- it "should be able to cache rows" do
5
- begin
6
- require "#{File.dirname(__FILE__)}/../../array_enumerator/lib/array_enumerator"
7
- rescue LoadError
8
- require "array_enumerator"
9
- end
10
-
11
- require "sqlite3" if RUBY_ENGINE != "jruby"
4
+ before(:all) do
5
+ require "sqlite3" unless RUBY_ENGINE == "jruby"
12
6
  require "tmpdir"
13
7
 
14
8
  $db_path = "#{Dir.tmpdir}/knjrbfw_objects_cache_test.sqlite3"
@@ -55,6 +49,36 @@ describe "Objects" do
55
49
  {:username => "User 5"}
56
50
  ])
57
51
 
52
+ class Project < Baza::Model
53
+ has_many [
54
+ {:class => :Task, :col => :project_id, :depends => true}
55
+ ]
56
+ end
57
+
58
+ class Task < Baza::Model
59
+ has_one [
60
+ {:class => :Person, :required => true},
61
+ :Project
62
+ ]
63
+ end
64
+
65
+ class Person < Baza::Model
66
+ has_one [:Project]
67
+
68
+ has_many [
69
+ {:class => :Timelog, :autozero => true}
70
+ ]
71
+
72
+ def html
73
+ return self[:name]
74
+ end
75
+ end
76
+
77
+ class Timelog < Baza::Model
78
+ end
79
+ end
80
+
81
+ it "should be able to cache rows" do
58
82
  raise "Expected user-ID-cache to be 5 but it wasnt: #{$ob.ids_cache[:User].length}" if $ob.ids_cache[:User].length != 5
59
83
 
60
84
  user = $ob.get(:User, 4)
@@ -83,7 +107,9 @@ describe "Objects" do
83
107
  #Stress it to test threadsafety...
84
108
  threads = []
85
109
  0.upto(5) do |tc|
86
- threads << Knj::Thread.new do
110
+ threads << Thread.new do
111
+ Thread.current.abort_on_exception = true
112
+
87
113
  0.upto(5) do |ic|
88
114
  user = $ob.add(:User, {:username => "User #{tc}-#{ic}"})
89
115
  raise "No user returned." if !user
@@ -123,7 +149,9 @@ describe "Objects" do
123
149
 
124
150
  threads = []
125
151
  0.upto(5) do
126
- threads << Knj::Thread.new do
152
+ threads << Thread.new do
153
+ Thread.current.abort_on_exception = true
154
+
127
155
  0.upto(5) do
128
156
  ret = $ob2.add(:Group, {:groupname => "User 1"}, {:skip_ret => true})
129
157
  raise "Expected empty return but got something: #{ret}" if ret
@@ -142,7 +170,9 @@ describe "Objects" do
142
170
 
143
171
  #Moved from "knjrbfw_spec.rb"
144
172
  it "should be able to generate a sample SQLite database and add a sample table, with sample columns and with a sample index to it" do
145
- $db_path = "#{Knj::Os.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
173
+ require 'tmpdir'
174
+
175
+ $db_path = "#{Dir.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
146
176
  $db = Baza::Db.new(
147
177
  :type => :sqlite3,
148
178
  :path => $db_path,
@@ -192,7 +222,7 @@ describe "Objects" do
192
222
  table = $db.tables[:Project]
193
223
 
194
224
  indexes = table.indexes
195
- raise "Could not find the sample-index 'category_id' that should have been created." if !indexes[:Project__category_id]
225
+ raise "Could not find the sample-index 'category_id' that should have been created." unless indexes[:Project__category_id]
196
226
 
197
227
 
198
228
  #If we insert a row the ID should increase and the name should be the same as inserted (or something is very very wrong)...
@@ -211,35 +241,6 @@ describe "Objects" do
211
241
  end
212
242
 
213
243
  it "should be able to automatic generate methods on datarow-classes (has_many, has_one)." do
214
- class Project < Baza::Model
215
- has_many [
216
- {:class => :Task, :col => :project_id, :depends => true}
217
- ]
218
- end
219
-
220
- class Task < Baza::Model
221
- has_one [
222
- {:class => :Person, :required => true},
223
- :Project
224
- ]
225
- end
226
-
227
- class Person < Baza::Model
228
- has_one [:Project]
229
-
230
- has_many [
231
- {:class => :Timelog, :autozero => true}
232
- ]
233
-
234
- def html
235
- return self[:name]
236
- end
237
- end
238
-
239
- class Timelog < Baza::Model
240
-
241
- end
242
-
243
244
  $ob = Baza::ModelHandler.new(:db => $db, :datarow => true, :require => false)
244
245
 
245
246
  $ob.add(:Person, {
@@ -312,13 +313,9 @@ describe "Objects" do
312
313
  end
313
314
 
314
315
  it "should be able to generate lists for inputs" do
315
- Knj::Web.inputs([{
316
- :title => "Test 3",
317
- :name => :seltest3,
318
- :type => :select,
319
- :default => 1,
320
- :opts => $ob.list_optshash(:Task)
321
- }])
316
+ list = $ob.list_optshash(:Task)
317
+ list.length.should eq 1
318
+ list[1].should eq 'Test task'
322
319
  end
323
320
 
324
321
  it "should be able to connect to objects 'no-html' callback and test it." do
@@ -408,7 +405,8 @@ describe "Objects" do
408
405
  end
409
406
 
410
407
  it "should delete the temp database again." do
411
- db_path = "#{Knj::Os.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
408
+ require 'tmpdir'
409
+ db_path = "#{Dir.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
412
410
  File.unlink(db_path) if File.exists?(db_path)
413
411
  end
414
412
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datet
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.8
41
41
  - !ruby/object:Gem::Dependency
42
- name: knjrbfw
42
+ name: array_enumerator
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.111
47
+ version: 0.0.7
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.111
54
+ version: 0.0.7
55
55
  - !ruby/object:Gem::Dependency
56
- name: array_enumerator
56
+ name: string-cases
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.7
61
+ version: 0.0.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.7
68
+ version: 0.0.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: string-cases
70
+ name: event_handler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.0.1
75
+ version: 0.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.0.1
82
+ version: 0.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +224,7 @@ files:
224
224
  - include/drivers/sqlite3/sqlite3_table.rb
225
225
  - include/drivers/sqlite3/sqlite3_tables.rb
226
226
  - include/dump.rb
227
+ - include/errors.rb
227
228
  - include/idquery.rb
228
229
  - include/index.rb
229
230
  - include/model.rb