knjrbfw 0.0.39 → 0.0.40

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/spec/db_spec.rb CHANGED
@@ -36,7 +36,7 @@ describe "Db" do
36
36
  raise "Table-name expected to be 'test' but wasnt: '#{list["test"].name}'." if list["test"].name != "test"
37
37
 
38
38
 
39
- #Test revision to create tables.
39
+ #Test revision to create tables, indexes and insert rows.
40
40
  schema = {
41
41
  "tables" => {
42
42
  "test_table" => {
@@ -44,6 +44,9 @@ describe "Db" do
44
44
  {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
45
45
  {"name" => "name", "type" => "varchar"}
46
46
  ],
47
+ "indexes" => [
48
+ "name"
49
+ ],
47
50
  "rows" => [
48
51
  {
49
52
  "find_by" => {"id" => 1},
@@ -57,15 +60,74 @@ describe "Db" do
57
60
  rev = Knj::Db::Revision.new
58
61
  rev.init_db("schema" => schema, "db" => db)
59
62
 
60
- begin
61
- cont = File.read("#{File.dirname(__FILE__)}/db_spec_encoding_test_file.txt")
62
- cont.force_encoding("ASCII-8BIT")
63
-
64
- db.insert("test", {
65
- "text" => cont
66
- })
67
- ensure
68
- File.unlink(db_path) if File.exists?(db_path)
63
+
64
+ #Test wrong encoding.
65
+ cont = File.read("#{File.dirname(__FILE__)}/db_spec_encoding_test_file.txt")
66
+ cont.force_encoding("ASCII-8BIT")
67
+
68
+ db.insert("test", {
69
+ "text" => cont
70
+ })
71
+
72
+
73
+ #Throw out invalid encoding because it will make dumping fail.
74
+ db.tables[:test].truncate
75
+
76
+
77
+
78
+ #Test IDQueries.
79
+ rows_count = 1250
80
+ db.transaction do
81
+ 0.upto(rows_count) do |count|
82
+ db.insert(:test_table, {:name => "User #{count}"})
83
+ end
84
+ end
85
+
86
+ block_ran = 0
87
+ idq = Knj::Db::Idquery.new(:db => db, :debug => false, :table => :test_table, :query => "SELECT id FROM test_table") do |data|
88
+ block_ran += 1
89
+ end
90
+
91
+ raise "Block with should have ran too little: #{block_ran}." if block_ran < rows_count
92
+
93
+ block_ran = 0
94
+ db.select(:test_table, {}, {:idquery => true}) do |data|
95
+ block_ran += 1
96
+ end
97
+
98
+ raise "Block with should have ran too little: #{block_ran}." if block_ran < rows_count
99
+
100
+
101
+ #Test dumping.
102
+ dump = Knj::Db::Dump.new(:db => db, :debug => false)
103
+ str_io = StringIO.new
104
+ dump.dump(str_io)
105
+ str_io.rewind
106
+
107
+
108
+ #Remember some numbers for validation.
109
+ tables_count = db.tables.list.length
110
+
111
+
112
+ #Remove everything in the db.
113
+ db.tables.list do |table|
114
+ table.drop
69
115
  end
116
+
117
+
118
+ #Run the exported SQL.
119
+ db.transaction do
120
+ str_io.each_line do |sql|
121
+ db.q(sql)
122
+ end
123
+ end
124
+
125
+
126
+ #Vaildate import.
127
+ raise "Not same amount of tables: #{tables_count}, #{db.tables.list.length}" if tables_count != db.tables.list.length
128
+
129
+
130
+ #Delete test-database if everything went well.
131
+ File.unlink(db_path) if File.exists?(db_path)
70
132
  end
71
133
  end
data/spec/http2_spec.rb CHANGED
@@ -12,7 +12,7 @@ describe "Http2" do
12
12
  res = Knj::Http2.post_convert_data(
13
13
  "test1" => [1, 2, 3]
14
14
  )
15
- raise "Expected 'test1=1%3D12%3D23%3D3' but got: '#{res}'." if res != "test1=1%3D12%3D23%3D3"
15
+ raise "Expected 'test1%5B0%5D=1test1%5B1%5D=2test1%5B2%5D=3' but got: '#{res}'." if res != "test1%5B0%5D=1test1%5B1%5D=2test1%5B2%5D=3"
16
16
 
17
17
  res = Knj::Http2.post_convert_data(
18
18
  "test1" => {
@@ -21,20 +21,57 @@ describe "Http2" do
21
21
  }
22
22
  }
23
23
  )
24
- raise "Expected 'test1=order%3D1%25253DBnet_profile2%25253Dprofile_id%253D5' but got: '#{res}'." if res != "test1=order%3D1%25253DBnet_profile2%25253Dprofile_id%253D5"
24
+ raise "Expected 'test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5' but got: '#{res}'." if res != "test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5"
25
25
  end
26
26
 
27
- it "should be able to do multipart-requests." do
28
- require "knj/http2"
29
- require "knj/php"
30
-
31
- http = Knj::Http2.new(:host => "www.partyworm.dk")
32
- resp = http.post_multipart("multipart_test.php", {
33
- "test_var" => "true"
34
- })
27
+ it "should be able to do normal post-requests." do
28
+ require "json"
35
29
 
36
- if resp.body != "multipart-test-test_var=true"
37
- raise "Expected body to be 'test_var=true' but it wasnt: '#{resp.body}'."
30
+ #Test posting keep-alive and advanced post-data.
31
+ Knj::Http2.new(:host => "www.partyworm.dk") do |http|
32
+ 0.upto(5) do
33
+ resp = http.get("multipart_test.php")
34
+
35
+ resp = http.post("multipart_test.php?choice=post-test", {
36
+ "val1" => "test1",
37
+ "val2" => "test2",
38
+ "val3" => [
39
+ "test3"
40
+ ],
41
+ "val4" => {
42
+ "val5" => "test5"
43
+ },
44
+ "val6" => {
45
+ "val7" => [
46
+ {
47
+ "val8" => "test8"
48
+ }
49
+ ]
50
+ }
51
+ })
52
+ res = JSON.parse(resp.body)
53
+
54
+ raise "Expected 'res' to be a hash." if !res.is_a?(Hash)
55
+ raise "Error 1" if res["val1"] != "test1"
56
+ raise "Error 2" if res["val2"] != "test2"
57
+ raise "Error 3" if !res["val3"] or res["val3"][0] != "test3"
58
+ raise "Error 4" if res["val4"]["val5"] != "test5"
59
+ raise "Error 5" if res["val6"]["val7"][0]["val8"] != "test8"
60
+ end
61
+ end
62
+ end
63
+
64
+ it "should be able to do multipart-requests and keep-alive when using multipart." do
65
+ Knj::Http2.new(:host => "www.partyworm.dk", :follow_redirects => false) do |http|
66
+ 0.upto(5) do
67
+ resp = http.post_multipart("multipart_test.php", {
68
+ "test_var" => "true"
69
+ })
70
+
71
+ if resp.body != "multipart-test-test_var=true"
72
+ raise "Expected body to be 'test_var=true' but it wasnt: '#{resp.body}'."
73
+ end
74
+ end
38
75
  end
39
76
  end
40
77
 
@@ -53,8 +90,8 @@ describe "Http2" do
53
90
  0.upto(105) do |count|
54
91
  url = urls[rand(urls.size)]
55
92
  #print "Doing request #{count} of 200 (#{url}).\n"
56
- res = http.get(url)
57
- raise "Body was empty." if res.body.to_s.length <= 0
93
+ #res = http.get(url)
94
+ #raise "Body was empty." if res.body.to_s.length <= 0
58
95
  end
59
96
  end
60
97
  end
@@ -6,7 +6,23 @@ describe "Process_meta" do
6
6
  require "timeout"
7
7
 
8
8
  #Start the activity.
9
- $process_meta = Knj::Process_meta.new("debug" => false, "debug_err" => true, "id" => "process_meta_spec")
9
+ $process_meta = Knj::Process_meta.new("debug" => true, "debug_err" => true, "id" => "process_meta_spec")
10
+ end
11
+
12
+ it "should be able to do simple blocks" do
13
+ block_ran = false
14
+ fpath = "#{Knj::Os.tmpdir}/process_meta_file_open"
15
+
16
+ Timeout.timeout(4) do
17
+ $process_meta.static(:File, :open, fpath, "w") do |fp|
18
+ block_ran = true
19
+ fp.write("Test!")
20
+ end
21
+ end
22
+
23
+ raise "Block didnt run!" if !block_ran
24
+ raise "Unexpected file-content." if File.read(fpath) != "Test!"
25
+ File.unlink(fpath) if File.exists?(fpath)
10
26
  end
11
27
 
12
28
  it "should be able to do various operations" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.39
5
+ version: 0.0.40
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-21 00:00:00 +02:00
13
+ date: 2012-05-25 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -267,10 +267,13 @@ files:
267
267
  - lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb
268
268
  - lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_sqlspecs.rb
269
269
  - lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb
270
+ - lib/knj/knjdb/dump.rb
271
+ - lib/knj/knjdb/idquery.rb
270
272
  - lib/knj/knjdb/libknjdb.rb
271
273
  - lib/knj/knjdb/libknjdb_java_sqlite3.rb
272
274
  - lib/knj/knjdb/libknjdb_row.rb
273
275
  - lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb
276
+ - lib/knj/knjdb/query_buffer.rb
274
277
  - lib/knj/knjdb/revision.rb
275
278
  - lib/knj/knjdb/sqlspecs.rb
276
279
  - lib/knj/kvm.rb
@@ -374,7 +377,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
374
377
  requirements:
375
378
  - - ">="
376
379
  - !ruby/object:Gem::Version
377
- hash: -4326648523750519043
380
+ hash: 2365172852586319088
378
381
  segments:
379
382
  - 0
380
383
  version: "0"