Merge remote branch 'origin/answer-specs' into next
[shapado:piglops-shapado.git] / spec / models / answer_spec.rb
1 require 'spec_helper'
2
3 describe Answer do
4   before(:each) do
5     @answer = Answer.make(:votes => {})
6   end
7
8   describe "module/plugin inclusions (optional)" do
9   end
10
11   describe "validations" do
12     it "the answer of a user in a question should be unique" do
13       answer = Answer.make_unsaved(:question_id => @answer.question_id,
14                                    :created_at => @answer.created_at+1.day,
15                                    :user_id => @answer.user_id,
16                                    :group_id => @answer.group_id,
17                                    :votes => {})
18       answer.valid?.should be_false
19       answer.errors[:limitation].should_not be_nil
20     end
21
22     it "elapsed time between two answers by the same user should be greater than 20 secs" do
23       answer = Answer.make_unsaved(:question_id => @answer.question_id,
24                                    :created_at => @answer.created_at+1,
25                                    :user_id => @answer.user_id,
26                                    :group_id => @answer.group_id,
27                                    :votes => {})
28       answer.valid?.should be_false
29     end
30   end
31
32   describe "association" do
33   end
34
35   describe "callbacks" do
36     describe "Answer#unsolve_question" do
37       it "should set the answer's question as unsolved when the question is deleted" do
38         question = @answer.question
39         question.answer = @answer
40         question.accepted = true
41         question.save
42         question.reload
43
44         question.accepted.should be_true
45         question.answer.should_not be_nil
46
47         @answer.destroy
48
49         question.reload
50         question.accepted.should be_false
51         question.answer.should be_nil
52       end
53     end
54   end
55
56   describe "named scopes" do
57   end
58
59   describe "class methods" do
60     describe "Answer#minimal" do
61       it "should return a answer context without some keys" do
62         Answer.should_receive(:without).with(:_keywords,
63                                              :flags,
64                                              :votes,
65                                              :versions)
66         Answer.minimal
67       end
68     end
69
70     describe "Answer#ban" do
71       it "should ban the answer" do
72         @answer.banned.should be_false
73         Answer.ban([@answer.id])
74         @answer.reload
75         @answer.banned.should be_true
76       end
77     end
78
79     describe "Answer#unban" do
80       it "should unban the answer" do
81         @answer.ban
82         @answer.reload
83         Answer.unban([@answer.id])
84         @answer.reload
85         @answer.banned.should be_false
86       end
87     end
88   end
89
90   describe "instance methods" do
91     describe "Answer#ban" do
92     end
93
94     describe "Answer#can_be_deleted_by?" do
95     end
96
97     describe "Answer#on_add_vote" do
98     end
99
100     describe "Answer#on_remove_vote" do
101     end
102
103     describe "Answer#flagged!" do
104     end
105
106     describe "Answer#to_html" do
107     end
108
109     describe "Answer#disable_limits?" do
110     end
111
112     describe "Answer#add_favorite!" do
113     end
114
115     describe "Answer#remove_favorite!" do
116     end
117
118     describe "Answer#favorite_for?" do
119     end
120   end
121 end