diff options
Diffstat (limited to 'test/feature.rb')
-rw-r--r-- | test/feature.rb | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/test/feature.rb b/test/feature.rb index 5aa2352..7fa266b 100644 --- a/test/feature.rb +++ b/test/feature.rb @@ -4,46 +4,58 @@ class FeatureTest < MiniTest::Test def test_opentox_feature @feature = OpenTox::Feature.new - @feature[:title] = "tost" + @feature.title = "tost" @feature.save - assert_equal true, @feature.exists?, "#{@feature.id} is not accessible." + assert_equal true, OpenTox::Feature.where(title: "tost").exists?, "#{@feature.id} is not accessible." + assert_equal true, OpenTox::Feature.where(id: @feature.id).exists?, "#{@feature.id} is not accessible." - list = OpenTox::Feature.all + list = OpenTox::Feature.all listsize1 = list.length + p list assert_equal true, list.collect{|f| f.id}.include?(@feature.id) # modify feature - @feature2 = OpenTox::Feature.find(:_id => @feature.id) + @feature2 = OpenTox::Feature.find(@feature.id) assert_equal "tost", @feature2[:title] - assert_equal 'Feature', @feature2[:type] + assert_equal "tost", @feature2.title + assert_equal 'Feature', @feature2.type @feature2[:title] = "feature2" - @feature2.put + @feature2.save list = OpenTox::Feature.all listsize2 = list.length - @feature2.get assert_match "feature2", @feature2.title refute_match "tost", @feature2.title assert_equal listsize1, listsize2 id = @feature2.id @feature2.delete - assert_nil OpenTox::Feature.find_id(id), "Feature #{id} is still accessible." + #TODO + #assert_raises OpenTox::ResourceNotFoundError do + assert_raises Mongoid::Errors::DocumentNotFound do + OpenTox::Feature.find(id) + end end def test_duplicated_features metadata = { :title => "feature duplication test", - :type => ["Feature", "StringFeature"], + :string => true, :description => "feature duplication test" } - feature = OpenTox::Feature.find_or_create metadata - dup_feature = OpenTox::Feature.find_or_create metadata + feature = OpenTox::Feature.find_or_create_by metadata + dup_feature = OpenTox::Feature.find_or_create_by metadata assert !feature.id.nil?, "No Feature ID in #{feature.inspect}" assert !feature.id.nil?, "No Feature ID in #{dup_feature.inspect}" assert_equal feature.id, dup_feature.id feature.delete - assert_nil OpenTox::Feature.find_id(feature.id), "Feature #{feature.id} is still accessible." - assert_nil OpenTox::Feature.find_id(dup_feature.id), "Feature #{dup_feature.id} is still accessible." + #TODO + #assert_raises OpenTox::ResourceNotFoundError do + assert_raises Mongoid::Errors::DocumentNotFound do + OpenTox::Feature.find(feature.id) + end + assert_raises Mongoid::Errors::DocumentNotFound do + OpenTox::Feature.find(dup_feature.id) + end end end |