choices_related_test.rb
1.74 KB
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
require "test_helper"
require "#{Rails.root}/plugins/pairwise/test/fixtures/pairwise_content_fixtures"
class PairwisePlugin::ChoicesRelatedTest < ActiveSupport::TestCase
def setup
@pairwise_content = PairwiseContentFixtures.pairwise_content
end
should 'have choice id' do
choices_related = PairwisePlugin::ChoicesRelated.new
choices_related.valid?
assert choices_related.errors.include?(:choice_id)
choices_related.choice_id = 1
choices_related.valid?
assert !choices_related.errors.include?(:choice_id)
end
should 'have parent choice id' do
choices_related = PairwisePlugin::ChoicesRelated.new
choices_related.valid?
assert choices_related.errors.include?(:parent_choice_id)
choices_related.parent_choice_id = 1
choices_related.valid?
assert !choices_related.errors.include?(:parent_choice_id)
end
should 'belongs to a question' do
choices_related = PairwisePlugin::ChoicesRelated.new
choices_related.valid?
assert choices_related.errors.include?(:question)
choices_related.question = @pairwise_content
choices_related.valid?
assert !choices_related.errors.include?(:question)
end
should 'optionally have an user' do
@user = create_user('testinguser')
choices_related = PairwisePlugin::ChoicesRelated.new
assert choices_related.user_id.nil?
choices_related.user = @user
assert_equal @user.id, choices_related.user_id
end
should 'search for related choices' do
PairwisePlugin::ChoicesRelated.create!(:question => @pairwise_content, :choice_id => 1, :parent_choice_id =>2)
assert_equal 1, PairwisePlugin::ChoicesRelated.related_choices_for(1).size
assert_equal 1, PairwisePlugin::ChoicesRelated.related_choices_for(2).size
end
end