knjrbfw 0.0.59 → 0.0.62

Sign up to get free protection for your applications and to get access to all the features.
data/spec/datet_spec.rb DELETED
@@ -1,98 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Datet" do
4
- it "should be able to make ago-strings" do
5
- require "knj/datet"
6
-
7
- time = Time.at(Time.now.to_i - 5)
8
- datet = Knj::Datet.in(time)
9
- res = datet.ago_str
10
- raise "Expected '5 seconds ago' but got: '#{res}'." if res != "5 seconds ago"
11
-
12
-
13
- time = Time.at(Time.now.to_i - 1800)
14
- datet = Knj::Datet.in(time)
15
- res = datet.ago_str
16
- raise "Expected '30 minutes ago' but got: '#{res}'." if res != "30 minutes ago"
17
-
18
-
19
- time = Time.at(Time.now.to_i - 60)
20
- datet = Knj::Datet.in(time)
21
- res = datet.ago_str
22
- raise "Expected '1 minute ago' but got: '#{res}'." if res != "1 minute ago"
23
-
24
-
25
- time = Time.at(Time.now.to_i - 48 * 3600)
26
- datet = Knj::Datet.in(time)
27
- res = datet.ago_str
28
- raise "Expected '2 days ago' but got: '#{res}'." if res != "2 days ago"
29
- end
30
-
31
- #From "knjrbfw_spec.rb".
32
- it "should be able to parse various date formats." do
33
- date = Knj::Datet.in("2011-07-09 00:00:00 UTC")
34
- date = Knj::Datet.in("1985-06-17 01:00:00")
35
- date = Knj::Datet.in("1985-06-17")
36
- date = Knj::Datet.in("17/06 1985")
37
-
38
- raise "Couldnt register type 1 nullstamp." if !Knj::Datet.is_nullstamp?("0000-00-00")
39
- raise "Couldnt register type 2 nullstamp." if !Knj::Datet.is_nullstamp?("0000-00-00 00:00:00")
40
- raise "Registered nullstamp on valid date." if Knj::Datet.is_nullstamp?("1985-06-17")
41
- raise "Registered nullstamp on valid date." if Knj::Datet.is_nullstamp?("1985-06-17 10:30:00")
42
-
43
- date = Knj::Datet.in("2011-07-09 13:05:04 +0200")
44
- ltime = date.localtime_str
45
-
46
- #if RUBY_VERSION.slice(0, 3) == "1.9"
47
- # if ltime != date.time.localtime
48
- # raise "Calculated localtime (#{ltime}) was not the same as the real Time-localtime (#{date.time.localtime})."
49
- # end
50
- #end
51
-
52
- if ltime != "2011-07-09 13:05:04 +0200"
53
- raise "Datet didnt return expected result: '#{ltime}'."
54
- end
55
- end
56
-
57
- it "should be able to compare dates" do
58
- date1 = Knj::Datet.in("17/06 1985")
59
- date2 = Knj::Datet.in("18/06 1985")
60
- date3 = Knj::Datet.in("17/06 1985")
61
-
62
- raise "Date1 was wrongly higher than date2." if date1 > date2
63
-
64
- if date2 > date1
65
- #do nothing.
66
- else
67
- raise "Date2 was wrongly not higher than date1."
68
- end
69
-
70
- raise "Date1 was wrongly not the same as date3." if date1 != date3
71
- raise "Date1 was the same as date2?" if date1 == date2
72
- end
73
-
74
- it "various methods should just work" do
75
- date = Knj::Datet.new(1985, 6, 17)
76
- raise "Invalid days in month: #{date.days_in_month}" if date.days_in_month != 30
77
- end
78
-
79
- it "should be able to handle invalid timestamps" do
80
- datet = Knj::Datet.new(2012, 3, 40)
81
- raise "Expected dbstr to be '2012-04-09' but it wasnt: '#{datet.dbstr(:time => false)}'." if datet.dbstr(:time => false) != "2012-04-09"
82
-
83
- datet = Knj::Datet.new(2012, 14)
84
- raise "Expected dbstr to be '2013-02-01' but it wasnt: '#{datet.dbstr(:time => false)}'." if datet.dbstr(:time => false) != "2013-02-01"
85
-
86
- datet = Knj::Datet.new(1985, 6, 17, 28)
87
- raise "Expected dbstr to be '1985-06-18 04:00:00' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 04:00:00"
88
-
89
- datet = Knj::Datet.new(1985, 6, 17, 28, 68)
90
- raise "Expected dbstr to be '1985-06-18 05:08:00' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:08:00"
91
-
92
- datet = Knj::Datet.new(1985, 6, 17, 28, 68, 68)
93
- raise "Expected dbstr to be '1985-06-18 05:09:08' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:09:08"
94
-
95
- datet = Knj::Datet.new(1985, 6, 17, 28, 68, 68, 68)
96
- raise "Expected dbstr to be '1985-06-18 05:09:09' but it wasnt: '#{datet.dbstr}'." if datet.dbstr != "1985-06-18 05:09:09"
97
- end
98
- end
data/spec/http2_spec.rb DELETED
@@ -1,97 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Http2" do
4
- it "should be able to recursively parse post-data-hashes." do
5
- require "knj/http2"
6
-
7
- res = Knj::Http2.post_convert_data(
8
- "test1" => "test2"
9
- )
10
- raise "Expected 'test1=test2' but got: '#{res}'." if res != "test1=test2"
11
-
12
- res = Knj::Http2.post_convert_data(
13
- "test1" => [1, 2, 3]
14
- )
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
-
17
- res = Knj::Http2.post_convert_data(
18
- "test1" => {
19
- "order" => {
20
- [:Bnet_profile, "profile_id"] => 5
21
- }
22
- }
23
- )
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
- end
26
-
27
- it "should be able to do normal post-requests." do
28
- require "json"
29
-
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
75
- end
76
- end
77
-
78
- it "it should be able to handle keep-alive correctly" do
79
- require "knj/http2"
80
-
81
- urls = [
82
- "?show=users_search",
83
- "?show=users_online",
84
- "?show=drinksdb",
85
- "?show=forum&fid=9&tid=1917&page=0"
86
- ]
87
- urls = ["robots.txt"]
88
-
89
- http = Knj::Http2.new(:host => "www.partyworm.dk", :debug => false)
90
- 0.upto(105) do |count|
91
- url = urls[rand(urls.size)]
92
- #print "Doing request #{count} of 200 (#{url}).\n"
93
- #res = http.get(url)
94
- #raise "Body was empty." if res.body.to_s.length <= 0
95
- end
96
- end
97
- end