forked from josedonizetti/ruby-duration
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration from minitest/unit for minitest/spec
- Loading branch information
Showing
3 changed files
with
66 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
# -*- encoding: utf-8 -*- | ||
require 'helper' | ||
|
||
class Duration::TestMongoid < MiniTest::Unit::TestCase | ||
describe "mongoid support" do | ||
|
||
# Returns seconds to serialization | ||
def test_get_seconds | ||
assert_equal Duration.new(90), Duration.get(90) | ||
end | ||
|
||
def test_get_nil | ||
assert_nil Duration.get(nil) | ||
end | ||
describe "#get - Mongoid's deserialization" do | ||
it "should return the duration given the total in seconds" do | ||
assert_equal Duration.new(90), Duration.get(90) | ||
end | ||
|
||
def test_set_nil | ||
assert_nil Duration.set([1,2,3]) | ||
assert_nil Duration.set(nil) | ||
assert_nil Duration.set("") | ||
assert_nil Duration.set({}) | ||
assert_nil Duration.set({:seconds => "", :hours => ""}) | ||
assert_nil Duration.set({:x => 100, :seconds => ""}) | ||
it "should return nil for nil serialized values" do | ||
assert_nil Duration.get(nil) | ||
end | ||
end | ||
|
||
def test_set_duration | ||
assert_equal 90, Duration.set(Duration.new(:minutes => 1, :seconds => 30)) | ||
end | ||
describe "#set - Mongoid's serialization" do | ||
it "should serialize to nil given an invalid serialized value or nil" do | ||
assert_nil Duration.set([1,2,3]) | ||
assert_nil Duration.set(nil) | ||
assert_nil Duration.set("") | ||
assert_nil Duration.set({}) | ||
assert_nil Duration.set({:seconds => "", :hours => ""}) | ||
assert_nil Duration.set({:x => 100, :seconds => ""}) | ||
end | ||
|
||
def test_set_seconds | ||
assert_equal 10, Duration.set(10) | ||
end | ||
it "should return total seconds given a duration" do | ||
assert_equal 90, Duration.set(Duration.new(:minutes => 1, :seconds => 30)) | ||
end | ||
|
||
it "should return total seconds given a duration in seconds" do | ||
assert_equal 10, Duration.set(10) | ||
end | ||
|
||
def test_set_string | ||
assert_equal 10, Duration.set("10") | ||
assert_equal 10, Duration.set("10string") | ||
assert_equal 0, Duration.set("string") | ||
end | ||
it "should return total seconds given a duration in string" do | ||
assert_equal 10, Duration.set("10") | ||
assert_equal 10, Duration.set("10string") | ||
assert_equal 0, Duration.set("string") # not blank | ||
end | ||
|
||
def test_set_hash | ||
assert_equal 90, Duration.set(:minutes => 1, :seconds => 30) | ||
it "should return total seconds given a duration in hash" do | ||
assert_equal 90, Duration.set(:minutes => 1, :seconds => 30) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
# -*- encoding: utf-8 -*- | ||
require 'rubygems' | ||
require 'minitest/unit' | ||
require 'minitest/spec' | ||
|
||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
require 'duration' | ||
require 'duration/mongoid' | ||
|
||
class MiniTest::Unit::TestCase | ||
end | ||
|
||
MiniTest::Unit.autorun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters