spec/knjrbfw_spec.rb in knjrbfw-0.0.7 vs spec/knjrbfw_spec.rb in knjrbfw-0.0.8
- old
+ new
@@ -79,15 +79,40 @@
raise "Couldnt register type 2 nullstamp." if !Knj::Datet.is_nullstamp?("0000-00-00 00:00:00")
raise "Registered nullstamp on valid date." if Knj::Datet.is_nullstamp?("1985-06-17")
raise "Registered nullstamp on valid date." if Knj::Datet.is_nullstamp?("1985-06-17 10:30:00")
date = Knj::Datet.in("2011-07-09 13:05:04 +0200")
- if date.time.localtime.to_s != "2011-07-09 15:05:04 +0200"
- raise "Datet didnt return expected result: '#{date.time.localtime}'."
+ ltime = date.localtime_str
+
+ #if RUBY_VERSION.slice(0, 3) == "1.9"
+ # if ltime != date.time.localtime
+ # raise "Calculated localtime (#{ltime}) was not the same as the real Time-localtime (#{date.time.localtime})."
+ # end
+ #end
+
+ if ltime != "2011-07-09 13:05:04 +0200"
+ raise "Datet didnt return expected result: '#{ltime}'."
end
end
+ it "should be able to compare dates" do
+ date1 = Knj::Datet.in("17/06 1985")
+ date2 = Knj::Datet.in("18/06 1985")
+ date3 = Knj::Datet.in("17/06 1985")
+
+ raise "Date1 was wrongly higher than date2." if date1 > date2
+
+ if date2 > date1
+ #do nothing.
+ else
+ raise "Date2 was wrongly not higher than date1."
+ end
+
+ raise "Date1 was wrongly not the same as date3." if date1 != date3
+ raise "Date1 was the same as date2?" if date1 == date2
+ end
+
it "should be able to automatic generate methods on datarow-classes (has_many, has_one)." do
class Project < Knj::Datarow
has_many [
{:class => :Task, :col => :project_id, :depends => true}
]
@@ -201,20 +226,10 @@
it "should be able to join arrays with callbacks." do
res = Knj::ArrayExt.join(:arr => [1, 2, 3], :sep => ",", :callback => proc{|value| "'#{value}'"})
raise "Unexpected result from ArrayExt." if res != "'1','2','3'"
end
- it "should be able to generate valid SQL based on arrays." do
- ret = $ob.sqlhelper({
- "test_col" => [1, 2, 3]
- },{
- :cols_str => ["test_col"]
- })
-
- raise "Unexpected SQL for generating based on array: '#{ret[:sql_where]}'" if ret[:sql_where] != " AND `test_col` IN ('1','2','3')"
- end
-
it "should be able to execute various forms of Web.input methods." do
html = Knj::Web.inputs([{
:title => "Test 1",
:name => :textest1,
:type => :text,
@@ -265,10 +280,52 @@
rescue SystemExit
#ignore.
end
end
+ it "should be able to properly parse 'Set-Cookie' headers." do
+ data = Knj::Web.parse_set_cookies("TestCookie=TestValue+; Expires=Fri, 05 Aug 2011 10:58:17 GMT; Path=\n")
+
+ raise "No data returned?" if !data or !data.respond_to?(:length)
+ raise "Wrong number of cookies returned: '#{data.length}'." if data.length != 1
+
+ raise "Unexpected name: '#{data[0]["name"]}'." if data[0]["name"] != "TestCookie"
+ raise "Unexpected value: '#{data[0]["value"]}'." if data[0]["value"] != "TestValue "
+ raise "Unexpected path: '#{data[0]["path"]}'." if data[0]["path"] != ""
+ raise "Unexpected expire:' #{data[0]["expire"]}'." if data[0]["expires"] != "Fri, 05 Aug 2011 10:58:17 GMT"
+ end
+
+ it "should be able to draw rounded transparent corners on images." do
+ pic = Magick::Image.read("#{File.dirname(__FILE__)}/../testfiles/image.jpg").first
+ pic.format = "png"
+
+ Knj::Image.rounded_corners(
+ :img => pic,
+ :radius => 10
+ )
+
+ blob_cont = pic.to_blob
+ end
+
+ it "should be possible to use Strings.html_links-method." do
+ teststr = "This is a test. http://www.google.com This is a test."
+
+
+ #Test normal usage.
+ test1 = Knj::Strings.html_links(teststr)
+ raise "Unexpected string: '#{teststr}'" if test1 != "This is a test. <a href=\"http://www.google.com\">http://www.google.com</a> This is a test."
+
+
+ #Test with a block.
+ test2 = Knj::Strings.html_links(teststr) do |data|
+ data[:str].gsub(data[:match][0], "TEST")
+ end
+
+ raise "Unexpected string: '#{test2}'." if test2 != "This is a test. TEST This is a test."
+ end
+
+=begin
it "should be able to use Knj::Mutexcl with advanced arguments." do
mutex = Knj::Mutexcl.new(
:modes => {
:reader => {
:blocks => [:writer]
@@ -332,6 +389,7 @@
end
sleep 0.35
raise "Count should be 4 but it wasnt: '#{$count}'." if $count != 4
end
+=end
end