1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
require_relative "setup.rb"
class FeatureTest < MiniTest::Test
def test_opentox_feature
@feature = OpenTox::Feature.new
@feature.title = "tost"
@feature.save
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
listsize1 = list.length
p list
assert_equal true, list.collect{|f| f.id}.include?(@feature.id)
# modify feature
@feature2 = OpenTox::Feature.find(@feature.id)
assert_equal "tost", @feature2[:title]
assert_equal "tost", @feature2.title
assert_equal 'Feature', @feature2.type
@feature2[:title] = "feature2"
@feature2.save
list = OpenTox::Feature.all
listsize2 = list.length
assert_match "feature2", @feature2.title
refute_match "tost", @feature2.title
assert_equal listsize1, listsize2
id = @feature2.id
@feature2.delete
#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",
:string => true,
:description => "feature duplication test"
}
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
#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
|