Commit c68e03522509c8efa83c511fde2971391eccad77
1 parent
b05b6378
Exists in
master
and in
1 other branch
specified and implemented model functionality
Showing
136 changed files
with
3680 additions
and
0 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 136 files displayed.
... | ... | @@ -0,0 +1,85 @@ |
1 | +class ChoicesController < ApplicationController | |
2 | + # GET /choices | |
3 | + # GET /choices.xml | |
4 | + def index | |
5 | + @choices = Choice.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @choices } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /choices/1 | |
14 | + # GET /choices/1.xml | |
15 | + def show | |
16 | + @choice = Choice.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @choice } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /choices/new | |
25 | + # GET /choices/new.xml | |
26 | + def new | |
27 | + @choice = Choice.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @choice } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /choices/1/edit | |
36 | + def edit | |
37 | + @choice = Choice.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /choices | |
41 | + # POST /choices.xml | |
42 | + def create | |
43 | + @choice = Choice.new(params[:choice]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @choice.save | |
47 | + flash[:notice] = 'Choice was successfully created.' | |
48 | + format.html { redirect_to(@choice) } | |
49 | + format.xml { render :xml => @choice, :status => :created, :location => @choice } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /choices/1 | |
58 | + # PUT /choices/1.xml | |
59 | + def update | |
60 | + @choice = Choice.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @choice.update_attributes(params[:choice]) | |
64 | + flash[:notice] = 'Choice was successfully updated.' | |
65 | + format.html { redirect_to(@choice) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /choices/1 | |
75 | + # DELETE /choices/1.xml | |
76 | + def destroy | |
77 | + @choice = Choice.find(params[:id]) | |
78 | + @choice.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(choices_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +class ClicksController < ApplicationController | |
2 | + # GET /clicks | |
3 | + # GET /clicks.xml | |
4 | + def index | |
5 | + @clicks = Click.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @clicks } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /clicks/1 | |
14 | + # GET /clicks/1.xml | |
15 | + def show | |
16 | + @click = Click.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @click } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /clicks/new | |
25 | + # GET /clicks/new.xml | |
26 | + def new | |
27 | + @click = Click.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @click } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /clicks/1/edit | |
36 | + def edit | |
37 | + @click = Click.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /clicks | |
41 | + # POST /clicks.xml | |
42 | + def create | |
43 | + @click = Click.new(params[:click]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @click.save | |
47 | + flash[:notice] = 'Click was successfully created.' | |
48 | + format.html { redirect_to(@click) } | |
49 | + format.xml { render :xml => @click, :status => :created, :location => @click } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @click.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /clicks/1 | |
58 | + # PUT /clicks/1.xml | |
59 | + def update | |
60 | + @click = Click.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @click.update_attributes(params[:click]) | |
64 | + flash[:notice] = 'Click was successfully updated.' | |
65 | + format.html { redirect_to(@click) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @click.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /clicks/1 | |
75 | + # DELETE /clicks/1.xml | |
76 | + def destroy | |
77 | + @click = Click.find(params[:id]) | |
78 | + @click.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(clicks_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +class ItemsController < ApplicationController | |
2 | + # GET /items | |
3 | + # GET /items.xml | |
4 | + def index | |
5 | + @items = Item.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @items } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /items/1 | |
14 | + # GET /items/1.xml | |
15 | + def show | |
16 | + @item = Item.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @item } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /items/new | |
25 | + # GET /items/new.xml | |
26 | + def new | |
27 | + @item = Item.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @item } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /items/1/edit | |
36 | + def edit | |
37 | + @item = Item.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /items | |
41 | + # POST /items.xml | |
42 | + def create | |
43 | + @item = Item.new(params[:item]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @item.save | |
47 | + flash[:notice] = 'Item was successfully created.' | |
48 | + format.html { redirect_to(@item) } | |
49 | + format.xml { render :xml => @item, :status => :created, :location => @item } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @item.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /items/1 | |
58 | + # PUT /items/1.xml | |
59 | + def update | |
60 | + @item = Item.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @item.update_attributes(params[:item]) | |
64 | + flash[:notice] = 'Item was successfully updated.' | |
65 | + format.html { redirect_to(@item) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @item.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /items/1 | |
75 | + # DELETE /items/1.xml | |
76 | + def destroy | |
77 | + @item = Item.find(params[:id]) | |
78 | + @item.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(items_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +class PromptsController < ApplicationController | |
2 | + # GET /prompts | |
3 | + # GET /prompts.xml | |
4 | + def index | |
5 | + @prompts = Prompt.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @prompts } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /prompts/1 | |
14 | + # GET /prompts/1.xml | |
15 | + def show | |
16 | + @prompt = Prompt.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @prompt } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /prompts/new | |
25 | + # GET /prompts/new.xml | |
26 | + def new | |
27 | + @prompt = Prompt.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @prompt } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /prompts/1/edit | |
36 | + def edit | |
37 | + @prompt = Prompt.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /prompts | |
41 | + # POST /prompts.xml | |
42 | + def create | |
43 | + @prompt = Prompt.new(params[:prompt]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @prompt.save | |
47 | + flash[:notice] = 'Prompt was successfully created.' | |
48 | + format.html { redirect_to(@prompt) } | |
49 | + format.xml { render :xml => @prompt, :status => :created, :location => @prompt } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @prompt.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /prompts/1 | |
58 | + # PUT /prompts/1.xml | |
59 | + def update | |
60 | + @prompt = Prompt.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @prompt.update_attributes(params[:prompt]) | |
64 | + flash[:notice] = 'Prompt was successfully updated.' | |
65 | + format.html { redirect_to(@prompt) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @prompt.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /prompts/1 | |
75 | + # DELETE /prompts/1.xml | |
76 | + def destroy | |
77 | + @prompt = Prompt.find(params[:id]) | |
78 | + @prompt.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(prompts_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +class QuestionsController < ApplicationController | |
2 | + # GET /questions | |
3 | + # GET /questions.xml | |
4 | + def index | |
5 | + @questions = Question.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @questions } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /questions/1 | |
14 | + # GET /questions/1.xml | |
15 | + def show | |
16 | + @question = Question.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @question } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /questions/new | |
25 | + # GET /questions/new.xml | |
26 | + def new | |
27 | + @question = Question.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @question } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /questions/1/edit | |
36 | + def edit | |
37 | + @question = Question.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /questions | |
41 | + # POST /questions.xml | |
42 | + def create | |
43 | + @question = Question.new(params[:question]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @question.save | |
47 | + flash[:notice] = 'Question was successfully created.' | |
48 | + format.html { redirect_to(@question) } | |
49 | + format.xml { render :xml => @question, :status => :created, :location => @question } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @question.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /questions/1 | |
58 | + # PUT /questions/1.xml | |
59 | + def update | |
60 | + @question = Question.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @question.update_attributes(params[:question]) | |
64 | + flash[:notice] = 'Question was successfully updated.' | |
65 | + format.html { redirect_to(@question) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @question.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /questions/1 | |
75 | + # DELETE /questions/1.xml | |
76 | + def destroy | |
77 | + @question = Question.find(params[:id]) | |
78 | + @question.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(questions_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +class VisitorsController < ApplicationController | |
2 | + # GET /visitors | |
3 | + # GET /visitors.xml | |
4 | + def index | |
5 | + @visitors = Visitor.all | |
6 | + | |
7 | + respond_to do |format| | |
8 | + format.html # index.html.erb | |
9 | + format.xml { render :xml => @visitors } | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + # GET /visitors/1 | |
14 | + # GET /visitors/1.xml | |
15 | + def show | |
16 | + @visitor = Visitor.find(params[:id]) | |
17 | + | |
18 | + respond_to do |format| | |
19 | + format.html # show.html.erb | |
20 | + format.xml { render :xml => @visitor } | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + # GET /visitors/new | |
25 | + # GET /visitors/new.xml | |
26 | + def new | |
27 | + @visitor = Visitor.new | |
28 | + | |
29 | + respond_to do |format| | |
30 | + format.html # new.html.erb | |
31 | + format.xml { render :xml => @visitor } | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + # GET /visitors/1/edit | |
36 | + def edit | |
37 | + @visitor = Visitor.find(params[:id]) | |
38 | + end | |
39 | + | |
40 | + # POST /visitors | |
41 | + # POST /visitors.xml | |
42 | + def create | |
43 | + @visitor = Visitor.new(params[:visitor]) | |
44 | + | |
45 | + respond_to do |format| | |
46 | + if @visitor.save | |
47 | + flash[:notice] = 'Visitor was successfully created.' | |
48 | + format.html { redirect_to(@visitor) } | |
49 | + format.xml { render :xml => @visitor, :status => :created, :location => @visitor } | |
50 | + else | |
51 | + format.html { render :action => "new" } | |
52 | + format.xml { render :xml => @visitor.errors, :status => :unprocessable_entity } | |
53 | + end | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + # PUT /visitors/1 | |
58 | + # PUT /visitors/1.xml | |
59 | + def update | |
60 | + @visitor = Visitor.find(params[:id]) | |
61 | + | |
62 | + respond_to do |format| | |
63 | + if @visitor.update_attributes(params[:visitor]) | |
64 | + flash[:notice] = 'Visitor was successfully updated.' | |
65 | + format.html { redirect_to(@visitor) } | |
66 | + format.xml { head :ok } | |
67 | + else | |
68 | + format.html { render :action => "edit" } | |
69 | + format.xml { render :xml => @visitor.errors, :status => :unprocessable_entity } | |
70 | + end | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + # DELETE /visitors/1 | |
75 | + # DELETE /visitors/1.xml | |
76 | + def destroy | |
77 | + @visitor = Visitor.find(params[:id]) | |
78 | + @visitor.destroy | |
79 | + | |
80 | + respond_to do |format| | |
81 | + format.html { redirect_to(visitors_url) } | |
82 | + format.xml { head :ok } | |
83 | + end | |
84 | + end | |
85 | +end | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +class Choice < ActiveRecord::Base | |
2 | + belongs_to :question | |
3 | + belongs_to :item | |
4 | + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" | |
5 | + validates_presence_of :creator, :on => :create, :message => "can't be blank" | |
6 | + validates_presence_of :question, :on => :create, :message => "can't be blank" | |
7 | + has_many :votes, :as => :voteable | |
8 | + | |
9 | + attr_accessor :data | |
10 | + | |
11 | + | |
12 | + after_create :generate_prompts | |
13 | + def before_create | |
14 | + @item = Item.create!(:creator => creator, :data => data) | |
15 | + self.item = @item | |
16 | + end | |
17 | + | |
18 | + protected | |
19 | + | |
20 | + def generate_prompts | |
21 | + #once a choice is added, we need to generate the new prompts (possible combinations of choices) | |
22 | + #do this in a new process (via delayed jobs) | |
23 | + previous_choices = (self.question.choices - [self]) | |
24 | + return if previous_choices.empty? | |
25 | + for c in previous_choices | |
26 | + question.prompts.create!(:left_choice => c, :right_choice => self) | |
27 | + question.prompts.create!(:left_choice => self, :right_choice => c) | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +class Item < ActiveRecord::Base | |
2 | + belongs_to :question, :counter_cache => true | |
3 | + belongs_to :site, :class_name => "User", :foreign_key => "site_id" | |
4 | + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" | |
5 | + | |
6 | + named_scope :active, :conditions => { :active => true } | |
7 | + | |
8 | + # has_many :items_questions, :dependent => :destroy | |
9 | + # has_many :questions, :through => :items_questions | |
10 | + # has_and_belongs_to_many :prompts | |
11 | + # | |
12 | + # has_and_belongs_to_many :votes | |
13 | + # has_and_belongs_to_many :prompt_requests | |
14 | + | |
15 | + validates_presence_of :creator_id | |
16 | +end | ... | ... |
... | ... | @@ -0,0 +1,54 @@ |
1 | +class Prompt < ActiveRecord::Base | |
2 | + #has_many :choices, :order => 'position DESC' | |
3 | + | |
4 | + has_many :skips | |
5 | + has_many :votes, :as => :voteable | |
6 | + | |
7 | + | |
8 | + belongs_to :question | |
9 | + belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id" | |
10 | + belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id" | |
11 | + | |
12 | + named_scope :with_left_choice, lambda { |*args| {:conditions => ["left_choice_id = ?", (args.first.id)]} } | |
13 | + named_scope :with_right_choice, lambda { |*args| {:conditions => ["right_choice_id = ?", (args.first.id)]} } | |
14 | + named_scope :with_choice, lambda { |*args| {:conditions => ["(right_choice_id = ?) OR (left_choice_id = ?)", (args.first.id)]} } | |
15 | + named_scope :with_choice_id, lambda { |*args| {:conditions => ["(right_choice_id = ?) OR (left_choice_id = ?)", (args.first)]} } | |
16 | + #named_scope :voted_on_by, :include => :choices, :conditions => | |
17 | + #named_scope :voted_on_by, proc {|u| { :conditions => { :methodology => methodology } } } | |
18 | + | |
19 | + def self.voted_on_by(u) | |
20 | + select {|z| z.voted_on_by_user?(u)} | |
21 | + end | |
22 | + | |
23 | + | |
24 | + named_scope :visible, :include => :category, :conditions => { 'categories.hidden' => false } | |
25 | + | |
26 | + validates_presence_of :left_choice, :on => :create, :message => "can't be blank" | |
27 | + validates_presence_of :right_choice, :on => :create, :message => "can't be blank" | |
28 | + | |
29 | + def choices | |
30 | + [left_choice, right_choice] | |
31 | + end | |
32 | + | |
33 | + def voted_on_by_user?(u) | |
34 | + u.voted_for?(left_choice) || u.voted_for?(right_choice) | |
35 | + end | |
36 | + | |
37 | + def left_choice_text(prompt = nil) | |
38 | + left_choice.item.data | |
39 | + end | |
40 | + | |
41 | + def left_choice_id | |
42 | + left_choice.id | |
43 | + end | |
44 | + | |
45 | + def right_choice_id | |
46 | + right_choice.id | |
47 | + end | |
48 | + | |
49 | + | |
50 | + def right_choice_text(prompt = nil) | |
51 | + right_choice.item.data | |
52 | + end | |
53 | + | |
54 | +end | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +class Question < ActiveRecord::Base | |
2 | + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" | |
3 | + belongs_to :site, :class_name => "User", :foreign_key => "site_id" | |
4 | + | |
5 | + has_many :choices | |
6 | + has_many :prompts do | |
7 | + def pick(algorithm = nil) | |
8 | + if algorithm | |
9 | + algorithm.pick_from(self) #todo | |
10 | + else | |
11 | + lambda {prompts[rand(prompts.size-1)]}.call | |
12 | + end | |
13 | + end | |
14 | + end | |
15 | + after_save :ensure_at_least_two_choices | |
16 | + | |
17 | + validates_presence_of :site, :on => :create, :message => "can't be blank" | |
18 | + validates_presence_of :creator, :on => :create, :message => "can't be blank" | |
19 | + | |
20 | + def ensure_at_least_two_choices | |
21 | + if self.choices.empty? | |
22 | + ["sample choice 1", "sample choice 2"].each { |choice_text| | |
23 | + item = Item.create!({:data => choice_text, :creator => creator}) | |
24 | + puts item.inspect | |
25 | + choice = choices.create!(:item => item, :creator => creator) | |
26 | + puts choice.inspect | |
27 | + } | |
28 | + end | |
29 | + end | |
30 | + | |
31 | +end | |
32 | +#@site = User.create!(:email => 'pius+7@alum.mit.edu', :password => 'password', :password_confirmation => 'password') | |
33 | +#@site.questions.create!(:name => 'what do you want?', :creator => @site.default_visitor) | ... | ... |
app/models/user.rb
1 | 1 | class User < ActiveRecord::Base |
2 | 2 | include Clearance::User |
3 | + has_many :visitors, :class_name => "Visitor", :foreign_key => "site_id" | |
4 | + has_many :questions, :class_name => "Question", :foreign_key => "site_id" | |
5 | + has_many :clicks, :class_name => "Click", :foreign_key => "site_id" | |
6 | + | |
7 | + def default_visitor | |
8 | + visitors.find(:first, :conditions => {:identifier => 'owner'}) | |
9 | + end | |
10 | + | |
11 | + def create_question(visitor_identifier, question_params) | |
12 | + visitor = visitors.find_or_create_by_identifier(visitor_identifier) | |
13 | + question = visitor.questions.create(question_params.merge(:site => self)) | |
14 | + end | |
15 | + | |
16 | + def create_choice(visitor_identifier, question, choice_params) | |
17 | + visitor = visitors.find_or_create_by_identifier(visitor_identifier) | |
18 | + raise "Question not found" if question.nil? | |
19 | + if visitor.owns?(question) | |
20 | + choice = question.choices.create(choice_params.merge(:active => true)) | |
21 | + else | |
22 | + choice = question.choices.create(choice_params.merge(:active => false)) | |
23 | + end | |
24 | + notify_question_owner_that_new_choice_has_been_added(choice) | |
25 | + end | |
26 | + | |
27 | + def record_vote(visitor_identifier, prompt, ordinality) | |
28 | + visitor = visitors.find_or_create_by_identifier(visitor_identifier) | |
29 | + visitor.vote_for!(prompt, ordinality) | |
30 | + end | |
31 | + | |
32 | + def record_skip(visitor_identifier, prompt) | |
33 | + visitor = visitors.find_or_create_by_identifier(visitor_identifier) | |
34 | + question = prompt.question | |
35 | + visitor.skip!(prompt) | |
36 | + end | |
37 | + | |
38 | + def activate_question(question_id, options) | |
39 | + question = questions.find(question_id) | |
40 | + question.activate! | |
41 | + end | |
42 | + | |
43 | + def activate_choice(choice_id, options) | |
44 | + choice = Choice.find(choice_id) | |
45 | + choice.activate! | |
46 | + end | |
47 | + | |
48 | + def deactivate_choice(choice_id, options) | |
49 | + choice = Choice.find(choice_id) | |
50 | + choice.deactivate! | |
51 | + end | |
52 | + | |
53 | + def deactivate_question(question_id, options) | |
54 | + question = questions.find(question_id) | |
55 | + question.deactivate! | |
56 | + end | |
57 | + | |
58 | + def after_create | |
59 | + visitors.create!(:site => self, :identifier => 'owner') | |
60 | + end | |
61 | + | |
62 | + private | |
63 | + | |
64 | + def notify_question_owner_that_new_choice_has_been_added(choice) | |
65 | + #ChoiceNotifier.deliver_notification(choice) #this may be the responsibility of the client | |
66 | + end | |
3 | 67 | end | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +class Visitor < ActiveRecord::Base | |
2 | + belongs_to :site, :class_name => "User", :foreign_key => "site_id" | |
3 | + has_many :questions, :class_name => "Question", :foreign_key => "creator_id" | |
4 | + has_many :votes, :class_name => "Vote", :foreign_key => "voter_id" | |
5 | + has_many :skips, :class_name => "Skip", :foreign_key => "skipper_id" | |
6 | + has_many :clicks | |
7 | + validates_presence_of :site, :on => :create, :message => "can't be blank" | |
8 | + validates_uniqueness_of :identifier, :on => :create, :message => "must be unique", :scope => :site_id | |
9 | + | |
10 | + def owns?(question) | |
11 | + questions.include? question | |
12 | + end | |
13 | + | |
14 | + def vote_for!(prompt, ordinality) | |
15 | + choice = prompt.choices[ordinality] #we need to guarantee that the choices are in the right order (by position) | |
16 | + prompt_vote = votes.create!(:voteable => prompt) | |
17 | + choice_vote = votes.create!(:voteable => choice) | |
18 | + end | |
19 | + | |
20 | + def skip!(prompt) | |
21 | + prompt_skip = skips.create!(:prompt => prompt) | |
22 | + end | |
23 | +end | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<h1>Editing choice</h1> | |
2 | + | |
3 | +<% form_for(@choice) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.submit 'Update' %> | |
8 | + </p> | |
9 | +<% end %> | |
10 | + | |
11 | +<%= link_to 'Show', @choice %> | | |
12 | +<%= link_to 'Back', choices_path %> | |
0 | 13 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h1>Listing choices</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + </tr> | |
6 | + | |
7 | +<% @choices.each do |choice| %> | |
8 | + <tr> | |
9 | + <td><%= link_to 'Show', choice %></td> | |
10 | + <td><%= link_to 'Edit', edit_choice_path(choice) %></td> | |
11 | + <td><%= link_to 'Destroy', choice, :confirm => 'Are you sure?', :method => :delete %></td> | |
12 | + </tr> | |
13 | +<% end %> | |
14 | +</table> | |
15 | + | |
16 | +<br /> | |
17 | + | |
18 | +<%= link_to 'New choice', new_choice_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<h1>Editing click</h1> | |
2 | + | |
3 | +<% form_for(@click) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.label :site_id %><br /> | |
8 | + <%= f.text_field :site_id %> | |
9 | + </p> | |
10 | + <p> | |
11 | + <%= f.label :visitor_id %><br /> | |
12 | + <%= f.text_field :visitor_id %> | |
13 | + </p> | |
14 | + <p> | |
15 | + <%= f.label :additional_info %><br /> | |
16 | + <%= f.text_area :additional_info %> | |
17 | + </p> | |
18 | + <p> | |
19 | + <%= f.submit 'Update' %> | |
20 | + </p> | |
21 | +<% end %> | |
22 | + | |
23 | +<%= link_to 'Show', @click %> | | |
24 | +<%= link_to 'Back', clicks_path %> | |
0 | 25 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<h1>Listing clicks</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + <th>Site</th> | |
6 | + <th>Visitor</th> | |
7 | + <th>Additional info</th> | |
8 | + </tr> | |
9 | + | |
10 | +<% @clicks.each do |click| %> | |
11 | + <tr> | |
12 | + <td><%=h click.site_id %></td> | |
13 | + <td><%=h click.visitor_id %></td> | |
14 | + <td><%=h click.additional_info %></td> | |
15 | + <td><%= link_to 'Show', click %></td> | |
16 | + <td><%= link_to 'Edit', edit_click_path(click) %></td> | |
17 | + <td><%= link_to 'Destroy', click, :confirm => 'Are you sure?', :method => :delete %></td> | |
18 | + </tr> | |
19 | +<% end %> | |
20 | +</table> | |
21 | + | |
22 | +<br /> | |
23 | + | |
24 | +<%= link_to 'New click', new_click_path %> | |
0 | 25 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +<h1>New click</h1> | |
2 | + | |
3 | +<% form_for(@click) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.label :site_id %><br /> | |
8 | + <%= f.text_field :site_id %> | |
9 | + </p> | |
10 | + <p> | |
11 | + <%= f.label :visitor_id %><br /> | |
12 | + <%= f.text_field :visitor_id %> | |
13 | + </p> | |
14 | + <p> | |
15 | + <%= f.label :additional_info %><br /> | |
16 | + <%= f.text_area :additional_info %> | |
17 | + </p> | |
18 | + <p> | |
19 | + <%= f.submit 'Create' %> | |
20 | + </p> | |
21 | +<% end %> | |
22 | + | |
23 | +<%= link_to 'Back', clicks_path %> | |
0 | 24 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<p> | |
2 | + <b>Site:</b> | |
3 | + <%=h @click.site_id %> | |
4 | +</p> | |
5 | + | |
6 | +<p> | |
7 | + <b>Visitor:</b> | |
8 | + <%=h @click.visitor_id %> | |
9 | +</p> | |
10 | + | |
11 | +<p> | |
12 | + <b>Additional info:</b> | |
13 | + <%=h @click.additional_info %> | |
14 | +</p> | |
15 | + | |
16 | + | |
17 | +<%= link_to 'Edit', edit_click_path(@click) %> | | |
18 | +<%= link_to 'Back', clicks_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h1>Listing items</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + </tr> | |
6 | + | |
7 | +<% @items.each do |item| %> | |
8 | + <tr> | |
9 | + <td><%= link_to 'Show', item %></td> | |
10 | + <td><%= link_to 'Edit', edit_item_path(item) %></td> | |
11 | + <td><%= link_to 'Destroy', item, :confirm => 'Are you sure?', :method => :delete %></td> | |
12 | + </tr> | |
13 | +<% end %> | |
14 | +</table> | |
15 | + | |
16 | +<br /> | |
17 | + | |
18 | +<%= link_to 'New item', new_item_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Choices: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Clicks: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Items: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Prompts: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Questions: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | + | |
4 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
5 | +<head> | |
6 | + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
7 | + <title>Visitors: <%= controller.action_name %></title> | |
8 | + <%= stylesheet_link_tag 'scaffold' %> | |
9 | +</head> | |
10 | +<body> | |
11 | + | |
12 | +<p style="color: green"><%= flash[:notice] %></p> | |
13 | + | |
14 | +<%= yield %> | |
15 | + | |
16 | +</body> | |
17 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<h1>Editing prompt</h1> | |
2 | + | |
3 | +<% form_for(@prompt) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.submit 'Update' %> | |
8 | + </p> | |
9 | +<% end %> | |
10 | + | |
11 | +<%= link_to 'Show', @prompt %> | | |
12 | +<%= link_to 'Back', prompts_path %> | |
0 | 13 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h1>Listing prompts</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + </tr> | |
6 | + | |
7 | +<% @prompts.each do |prompt| %> | |
8 | + <tr> | |
9 | + <td><%= link_to 'Show', prompt %></td> | |
10 | + <td><%= link_to 'Edit', edit_prompt_path(prompt) %></td> | |
11 | + <td><%= link_to 'Destroy', prompt, :confirm => 'Are you sure?', :method => :delete %></td> | |
12 | + </tr> | |
13 | +<% end %> | |
14 | +</table> | |
15 | + | |
16 | +<br /> | |
17 | + | |
18 | +<%= link_to 'New prompt', new_prompt_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<h1>Editing question</h1> | |
2 | + | |
3 | +<% form_for(@question) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.submit 'Update' %> | |
8 | + </p> | |
9 | +<% end %> | |
10 | + | |
11 | +<%= link_to 'Show', @question %> | | |
12 | +<%= link_to 'Back', questions_path %> | |
0 | 13 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h1>Listing questions</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + </tr> | |
6 | + | |
7 | +<% @questions.each do |question| %> | |
8 | + <tr> | |
9 | + <td><%= link_to 'Show', question %></td> | |
10 | + <td><%= link_to 'Edit', edit_question_path(question) %></td> | |
11 | + <td><%= link_to 'Destroy', question, :confirm => 'Are you sure?', :method => :delete %></td> | |
12 | + </tr> | |
13 | +<% end %> | |
14 | +</table> | |
15 | + | |
16 | +<br /> | |
17 | + | |
18 | +<%= link_to 'New question', new_question_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<h1>Editing visitor</h1> | |
2 | + | |
3 | +<% form_for(@visitor) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.label :site_id %><br /> | |
8 | + <%= f.text_field :site_id %> | |
9 | + </p> | |
10 | + <p> | |
11 | + <%= f.label :identifier %><br /> | |
12 | + <%= f.text_field :identifier %> | |
13 | + </p> | |
14 | + <p> | |
15 | + <%= f.label :tracking %><br /> | |
16 | + <%= f.text_area :tracking %> | |
17 | + </p> | |
18 | + <p> | |
19 | + <%= f.submit 'Update' %> | |
20 | + </p> | |
21 | +<% end %> | |
22 | + | |
23 | +<%= link_to 'Show', @visitor %> | | |
24 | +<%= link_to 'Back', visitors_path %> | |
0 | 25 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<h1>Listing visitors</h1> | |
2 | + | |
3 | +<table> | |
4 | + <tr> | |
5 | + <th>Site</th> | |
6 | + <th>Identifier</th> | |
7 | + <th>Tracking</th> | |
8 | + </tr> | |
9 | + | |
10 | +<% @visitors.each do |visitor| %> | |
11 | + <tr> | |
12 | + <td><%=h visitor.site_id %></td> | |
13 | + <td><%=h visitor.identifier %></td> | |
14 | + <td><%=h visitor.tracking %></td> | |
15 | + <td><%= link_to 'Show', visitor %></td> | |
16 | + <td><%= link_to 'Edit', edit_visitor_path(visitor) %></td> | |
17 | + <td><%= link_to 'Destroy', visitor, :confirm => 'Are you sure?', :method => :delete %></td> | |
18 | + </tr> | |
19 | +<% end %> | |
20 | +</table> | |
21 | + | |
22 | +<br /> | |
23 | + | |
24 | +<%= link_to 'New visitor', new_visitor_path %> | |
0 | 25 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +<h1>New visitor</h1> | |
2 | + | |
3 | +<% form_for(@visitor) do |f| %> | |
4 | + <%= f.error_messages %> | |
5 | + | |
6 | + <p> | |
7 | + <%= f.label :site_id %><br /> | |
8 | + <%= f.text_field :site_id %> | |
9 | + </p> | |
10 | + <p> | |
11 | + <%= f.label :identifier %><br /> | |
12 | + <%= f.text_field :identifier %> | |
13 | + </p> | |
14 | + <p> | |
15 | + <%= f.label :tracking %><br /> | |
16 | + <%= f.text_area :tracking %> | |
17 | + </p> | |
18 | + <p> | |
19 | + <%= f.submit 'Create' %> | |
20 | + </p> | |
21 | +<% end %> | |
22 | + | |
23 | +<%= link_to 'Back', visitors_path %> | |
0 | 24 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<p> | |
2 | + <b>Site:</b> | |
3 | + <%=h @visitor.site_id %> | |
4 | +</p> | |
5 | + | |
6 | +<p> | |
7 | + <b>Identifier:</b> | |
8 | + <%=h @visitor.identifier %> | |
9 | +</p> | |
10 | + | |
11 | +<p> | |
12 | + <b>Tracking:</b> | |
13 | + <%=h @visitor.tracking %> | |
14 | +</p> | |
15 | + | |
16 | + | |
17 | +<%= link_to 'Edit', edit_visitor_path(@visitor) %> | | |
18 | +<%= link_to 'Back', visitors_path %> | |
0 | 19 | \ No newline at end of file | ... | ... |
config/routes.rb
1 | 1 | ActionController::Routing::Routes.draw do |map| |
2 | + map.resources :clicks | |
3 | + | |
4 | + map.resources :prompts | |
5 | + | |
6 | + map.resources :items | |
7 | + | |
8 | + map.resources :choices | |
9 | + | |
10 | + map.resources :visitors | |
11 | + | |
12 | + map.resources :questions | |
13 | + | |
2 | 14 | map.root :controller => "clearance/sessions", :action => "new" |
3 | 15 | |
4 | 16 | # rake routes | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +class CreateQuestions < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table "questions", :force => true do |t| | |
4 | + t.integer "creator_id" | |
5 | + t.string "name", :default => "" | |
6 | + t.datetime "created_at" | |
7 | + t.datetime "updated_at" | |
8 | + t.integer "items_count", :default => 0 | |
9 | + t.integer "active_items_count", :default => 0 | |
10 | + t.integer "choices_count", :default => 0 | |
11 | + t.integer "prompts_count", :default => 0 | |
12 | + t.boolean "active", :default => false | |
13 | + t.text "tracking" | |
14 | + t.integer "first_prompt_algorithm_id" | |
15 | + t.text "information" | |
16 | + end | |
17 | + | |
18 | + end | |
19 | + | |
20 | + def self.down | |
21 | + drop_table :questions | |
22 | + end | |
23 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +class CreateVisitors < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table :visitors do |table| | |
4 | + table.integer :site_id | |
5 | + table.string :identifier, :default => "" | |
6 | + table.text :tracking | |
7 | + table.boolean :activated | |
8 | + table.integer :user_id | |
9 | + table.timestamps | |
10 | + end | |
11 | + | |
12 | + end | |
13 | + | |
14 | + def self.down | |
15 | + drop_table :visitors | |
16 | + end | |
17 | +end | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +class CreateChoices < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table "choices", :force => true do |t| | |
4 | + t.integer "item_id" | |
5 | + t.integer "question_id" | |
6 | + t.integer "position" | |
7 | + t.integer "wins" | |
8 | + t.integer "ratings" | |
9 | + t.integer "losses" | |
10 | + t.datetime "created_at" | |
11 | + t.datetime "updated_at" | |
12 | + t.integer "request_id" | |
13 | + t.integer "prompt_id" | |
14 | + t.boolean "active", :default => false | |
15 | + t.text "tracking" | |
16 | + t.float "score" | |
17 | + end | |
18 | + | |
19 | + end | |
20 | + | |
21 | + def self.down | |
22 | + drop_table :choices | |
23 | + end | |
24 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +class CreateItems < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table "items", :force => true do |t| | |
4 | + t.text "data" | |
5 | + t.boolean "active" | |
6 | + t.text "tracking" | |
7 | + t.integer "creator_id" | |
8 | + t.integer "voter_id" | |
9 | + t.integer "site_id" | |
10 | + t.datetime "created_at" | |
11 | + t.datetime "updated_at" | |
12 | + end | |
13 | + | |
14 | + end | |
15 | + | |
16 | + def self.down | |
17 | + drop_table :items | |
18 | + end | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +class CreatePrompts < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table "prompts", :force => true do |t| | |
4 | + t.integer "algorithm_id" | |
5 | + t.integer "question_id" | |
6 | + t.integer "left_choice_id" | |
7 | + t.integer "right_choice_id" | |
8 | + t.integer "voter_id" | |
9 | + t.boolean "active" | |
10 | + t.datetime "created_at" | |
11 | + t.datetime "updated_at" | |
12 | + t.text "tracking" | |
13 | + end | |
14 | + | |
15 | + end | |
16 | + | |
17 | + def self.down | |
18 | + drop_table :prompts | |
19 | + end | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +class CreateVotes < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table :votes do |table| | |
4 | + table.text :tracking | |
5 | + table.integer :site_id | |
6 | + table.integer :voter_id | |
7 | + table.integer :voteable_id | |
8 | + table.string :voteable_type, :default => "" | |
9 | + table.timestamps | |
10 | + end | |
11 | + | |
12 | + end | |
13 | + | |
14 | + def self.down | |
15 | + drop_table :votes | |
16 | + end | |
17 | +end | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +class CreateSkips < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table "skips", :force => true do |t| | |
4 | + t.integer "skipper_id" | |
5 | + t.integer "prompt_id" | |
6 | + t.text "tracking" | |
7 | + t.datetime "created_at" | |
8 | + t.datetime "updated_at" | |
9 | + end | |
10 | + | |
11 | + end | |
12 | + | |
13 | + def self.down | |
14 | + drop_table :skips | |
15 | + end | |
16 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +class CreateClicks < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table :clicks do |table| | |
4 | + table.integer :site_id | |
5 | + table.integer :visitor_id | |
6 | + table.text :additional_info | |
7 | + table.timestamps | |
8 | + end | |
9 | + | |
10 | + end | |
11 | + | |
12 | + def self.down | |
13 | + drop_table :clicks | |
14 | + end | |
15 | +end | ... | ... |
... | ... | @@ -0,0 +1,182 @@ |
1 | +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
2 | +rspec_gem_dir = nil | |
3 | +Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| | |
4 | + rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") | |
5 | +end | |
6 | +rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') | |
7 | + | |
8 | +if rspec_gem_dir && (test ?d, rspec_plugin_dir) | |
9 | + raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n" | |
10 | +end | |
11 | + | |
12 | +if rspec_gem_dir | |
13 | + $LOAD_PATH.unshift("#{rspec_gem_dir}/lib") | |
14 | +elsif File.exist?(rspec_plugin_dir) | |
15 | + $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") | |
16 | +end | |
17 | + | |
18 | +# Don't load rspec if running "rake gems:*" | |
19 | +unless ARGV.any? {|a| a =~ /^gems/} | |
20 | + | |
21 | +begin | |
22 | + require 'spec/rake/spectask' | |
23 | +rescue MissingSourceFile | |
24 | + module Spec | |
25 | + module Rake | |
26 | + class SpecTask | |
27 | + def initialize(name) | |
28 | + task name do | |
29 | + # if rspec-rails is a configured gem, this will output helpful material and exit ... | |
30 | + require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") | |
31 | + | |
32 | + # ... otherwise, do this: | |
33 | + raise <<-MSG | |
34 | + | |
35 | +#{"*" * 80} | |
36 | +* You are trying to run an rspec rake task defined in | |
37 | +* #{__FILE__}, | |
38 | +* but rspec can not be found in vendor/gems, vendor/plugins or system gems. | |
39 | +#{"*" * 80} | |
40 | +MSG | |
41 | + end | |
42 | + end | |
43 | + end | |
44 | + end | |
45 | + end | |
46 | +end | |
47 | + | |
48 | +Rake.application.instance_variable_get('@tasks').delete('default') | |
49 | + | |
50 | +spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop | |
51 | +task :noop do | |
52 | +end | |
53 | + | |
54 | +task :default => :spec | |
55 | +task :stats => "spec:statsetup" | |
56 | + | |
57 | +desc "Run all specs in spec directory (excluding plugin specs)" | |
58 | +Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| | |
59 | + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] | |
60 | + t.spec_files = FileList['spec/**/*_spec.rb'] | |
61 | +end | |
62 | + | |
63 | +namespace :spec do | |
64 | + desc "Run all specs in spec directory with RCov (excluding plugin specs)" | |
65 | + Spec::Rake::SpecTask.new(:rcov) do |t| | |
66 | + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] | |
67 | + t.spec_files = FileList['spec/**/*_spec.rb'] | |
68 | + t.rcov = true | |
69 | + t.rcov_opts = lambda do | |
70 | + IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten | |
71 | + end | |
72 | + end | |
73 | + | |
74 | + desc "Print Specdoc for all specs (excluding plugin specs)" | |
75 | + Spec::Rake::SpecTask.new(:doc) do |t| | |
76 | + t.spec_opts = ["--format", "specdoc", "--dry-run"] | |
77 | + t.spec_files = FileList['spec/**/*_spec.rb'] | |
78 | + end | |
79 | + | |
80 | + desc "Print Specdoc for all plugin examples" | |
81 | + Spec::Rake::SpecTask.new(:plugin_doc) do |t| | |
82 | + t.spec_opts = ["--format", "specdoc", "--dry-run"] | |
83 | + t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*') | |
84 | + end | |
85 | + | |
86 | + [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| | |
87 | + desc "Run the code examples in spec/#{sub}" | |
88 | + Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| | |
89 | + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] | |
90 | + t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] | |
91 | + end | |
92 | + end | |
93 | + | |
94 | + desc "Run the code examples in vendor/plugins (except RSpec's own)" | |
95 | + Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| | |
96 | + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] | |
97 | + t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") | |
98 | + end | |
99 | + | |
100 | + namespace :plugins do | |
101 | + desc "Runs the examples for rspec_on_rails" | |
102 | + Spec::Rake::SpecTask.new(:rspec_on_rails) do |t| | |
103 | + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] | |
104 | + t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb'] | |
105 | + end | |
106 | + end | |
107 | + | |
108 | + # Setup specs for stats | |
109 | + task :statsetup do | |
110 | + require 'code_statistics' | |
111 | + ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models') | |
112 | + ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views') | |
113 | + ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers') | |
114 | + ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') | |
115 | + ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib') | |
116 | + ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing') | |
117 | + ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration') | |
118 | + ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') | |
119 | + ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') | |
120 | + ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers') | |
121 | + ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') | |
122 | + ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib') | |
123 | + ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing') | |
124 | + ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration') | |
125 | + end | |
126 | + | |
127 | + namespace :db do | |
128 | + namespace :fixtures do | |
129 | + desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z." | |
130 | + task :load => :environment do | |
131 | + ActiveRecord::Base.establish_connection(Rails.env) | |
132 | + base_dir = File.join(Rails.root, 'spec', 'fixtures') | |
133 | + fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir | |
134 | + | |
135 | + require 'active_record/fixtures' | |
136 | + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file| | |
137 | + Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) | |
138 | + end | |
139 | + end | |
140 | + end | |
141 | + end | |
142 | + | |
143 | + namespace :server do | |
144 | + daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid") | |
145 | + | |
146 | + desc "start spec_server." | |
147 | + task :start do | |
148 | + if File.exist?(daemonized_server_pid) | |
149 | + $stderr.puts "spec_server is already running." | |
150 | + else | |
151 | + $stderr.puts %Q{Starting up spec_server ...} | |
152 | + FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids' | |
153 | + system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid) | |
154 | + end | |
155 | + end | |
156 | + | |
157 | + desc "stop spec_server." | |
158 | + task :stop do | |
159 | + unless File.exist?(daemonized_server_pid) | |
160 | + $stderr.puts "No server running." | |
161 | + else | |
162 | + $stderr.puts "Shutting down spec_server ..." | |
163 | + system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) && | |
164 | + File.delete(daemonized_server_pid) | |
165 | + end | |
166 | + end | |
167 | + | |
168 | + desc "restart spec_server." | |
169 | + task :restart => [:stop, :start] | |
170 | + | |
171 | + desc "check if spec server is running" | |
172 | + task :status do | |
173 | + if File.exist?(daemonized_server_pid) | |
174 | + $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})} | |
175 | + else | |
176 | + $stderr.puts "No server running." | |
177 | + end | |
178 | + end | |
179 | + end | |
180 | +end | |
181 | + | |
182 | +end | ... | ... |
... | ... | @@ -0,0 +1,54 @@ |
1 | +body { background-color: #fff; color: #333; } | |
2 | + | |
3 | +body, p, ol, ul, td { | |
4 | + font-family: verdana, arial, helvetica, sans-serif; | |
5 | + font-size: 13px; | |
6 | + line-height: 18px; | |
7 | +} | |
8 | + | |
9 | +pre { | |
10 | + background-color: #eee; | |
11 | + padding: 10px; | |
12 | + font-size: 11px; | |
13 | +} | |
14 | + | |
15 | +a { color: #000; } | |
16 | +a:visited { color: #666; } | |
17 | +a:hover { color: #fff; background-color:#000; } | |
18 | + | |
19 | +.fieldWithErrors { | |
20 | + padding: 2px; | |
21 | + background-color: red; | |
22 | + display: table; | |
23 | +} | |
24 | + | |
25 | +#errorExplanation { | |
26 | + width: 400px; | |
27 | + border: 2px solid red; | |
28 | + padding: 7px; | |
29 | + padding-bottom: 12px; | |
30 | + margin-bottom: 20px; | |
31 | + background-color: #f0f0f0; | |
32 | +} | |
33 | + | |
34 | +#errorExplanation h2 { | |
35 | + text-align: left; | |
36 | + font-weight: bold; | |
37 | + padding: 5px 5px 5px 15px; | |
38 | + font-size: 12px; | |
39 | + margin: -7px; | |
40 | + background-color: #c00; | |
41 | + color: #fff; | |
42 | +} | |
43 | + | |
44 | +#errorExplanation p { | |
45 | + color: #333; | |
46 | + margin-bottom: 0; | |
47 | + padding: 5px; | |
48 | +} | |
49 | + | |
50 | +#errorExplanation ul li { | |
51 | + font-size: 12px; | |
52 | + list-style: square; | |
53 | +} | |
54 | + | ... | ... |
... | ... | @@ -0,0 +1,6 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
3 | +ENV['RSPEC'] = 'true' # allows autotest to discover rspec | |
4 | +ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux | |
5 | +system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) || | |
6 | + $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH") | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} | |
3 | + require 'rubygems' unless ENV['NO_RUBYGEMS'] | |
4 | +else | |
5 | + gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
6 | + ENV["RAILS_ENV"] ||= 'test' | |
7 | + require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
8 | +end | |
9 | +require 'spec/autorun' | |
10 | +exit ::Spec::Runner::CommandLine.run | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
3 | + | |
4 | +puts "Loading Rails environment" | |
5 | +ENV["RAILS_ENV"] ||= 'test' | |
6 | +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
7 | + | |
8 | +require 'optparse' | |
9 | +require 'spec/rails/spec_server' | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ChoicesController do | |
4 | + | |
5 | + def mock_choice(stubs={}) | |
6 | + @mock_choice ||= mock_model(Choice, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all choices as @choices" do | |
11 | + Choice.stub!(:find).with(:all).and_return([mock_choice]) | |
12 | + get :index | |
13 | + assigns[:choices].should == [mock_choice] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested choice as @choice" do | |
19 | + Choice.stub!(:find).with("37").and_return(mock_choice) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:choice].should equal(mock_choice) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new choice as @choice" do | |
27 | + Choice.stub!(:new).and_return(mock_choice) | |
28 | + get :new | |
29 | + assigns[:choice].should equal(mock_choice) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested choice as @choice" do | |
35 | + Choice.stub!(:find).with("37").and_return(mock_choice) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:choice].should equal(mock_choice) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created choice as @choice" do | |
45 | + Choice.stub!(:new).with({'these' => 'params'}).and_return(mock_choice(:save => true)) | |
46 | + post :create, :choice => {:these => 'params'} | |
47 | + assigns[:choice].should equal(mock_choice) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created choice" do | |
51 | + Choice.stub!(:new).and_return(mock_choice(:save => true)) | |
52 | + post :create, :choice => {} | |
53 | + response.should redirect_to(choice_url(mock_choice)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved choice as @choice" do | |
59 | + Choice.stub!(:new).with({'these' => 'params'}).and_return(mock_choice(:save => false)) | |
60 | + post :create, :choice => {:these => 'params'} | |
61 | + assigns[:choice].should equal(mock_choice) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Choice.stub!(:new).and_return(mock_choice(:save => false)) | |
66 | + post :create, :choice => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested choice" do | |
77 | + Choice.should_receive(:find).with("37").and_return(mock_choice) | |
78 | + mock_choice.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :choice => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested choice as @choice" do | |
83 | + Choice.stub!(:find).and_return(mock_choice(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:choice].should equal(mock_choice) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the choice" do | |
89 | + Choice.stub!(:find).and_return(mock_choice(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(choice_url(mock_choice)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested choice" do | |
97 | + Choice.should_receive(:find).with("37").and_return(mock_choice) | |
98 | + mock_choice.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :choice => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the choice as @choice" do | |
103 | + Choice.stub!(:find).and_return(mock_choice(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:choice].should equal(mock_choice) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Choice.stub!(:find).and_return(mock_choice(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested choice" do | |
119 | + Choice.should_receive(:find).with("37").and_return(mock_choice) | |
120 | + mock_choice.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the choices list" do | |
125 | + Choice.stub!(:find).and_return(mock_choice(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(choices_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ClicksController do | |
4 | + | |
5 | + def mock_click(stubs={}) | |
6 | + @mock_click ||= mock_model(Click, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all clicks as @clicks" do | |
11 | + Click.stub!(:find).with(:all).and_return([mock_click]) | |
12 | + get :index | |
13 | + assigns[:clicks].should == [mock_click] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested click as @click" do | |
19 | + Click.stub!(:find).with("37").and_return(mock_click) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:click].should equal(mock_click) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new click as @click" do | |
27 | + Click.stub!(:new).and_return(mock_click) | |
28 | + get :new | |
29 | + assigns[:click].should equal(mock_click) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested click as @click" do | |
35 | + Click.stub!(:find).with("37").and_return(mock_click) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:click].should equal(mock_click) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created click as @click" do | |
45 | + Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => true)) | |
46 | + post :create, :click => {:these => 'params'} | |
47 | + assigns[:click].should equal(mock_click) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created click" do | |
51 | + Click.stub!(:new).and_return(mock_click(:save => true)) | |
52 | + post :create, :click => {} | |
53 | + response.should redirect_to(click_url(mock_click)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved click as @click" do | |
59 | + Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => false)) | |
60 | + post :create, :click => {:these => 'params'} | |
61 | + assigns[:click].should equal(mock_click) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Click.stub!(:new).and_return(mock_click(:save => false)) | |
66 | + post :create, :click => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested click" do | |
77 | + Click.should_receive(:find).with("37").and_return(mock_click) | |
78 | + mock_click.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :click => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested click as @click" do | |
83 | + Click.stub!(:find).and_return(mock_click(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:click].should equal(mock_click) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the click" do | |
89 | + Click.stub!(:find).and_return(mock_click(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(click_url(mock_click)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested click" do | |
97 | + Click.should_receive(:find).with("37").and_return(mock_click) | |
98 | + mock_click.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :click => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the click as @click" do | |
103 | + Click.stub!(:find).and_return(mock_click(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:click].should equal(mock_click) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Click.stub!(:find).and_return(mock_click(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested click" do | |
119 | + Click.should_receive(:find).with("37").and_return(mock_click) | |
120 | + mock_click.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the clicks list" do | |
125 | + Click.stub!(:find).and_return(mock_click(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(clicks_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ItemsController do | |
4 | + | |
5 | + def mock_item(stubs={}) | |
6 | + @mock_item ||= mock_model(Item, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all items as @items" do | |
11 | + Item.stub!(:find).with(:all).and_return([mock_item]) | |
12 | + get :index | |
13 | + assigns[:items].should == [mock_item] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested item as @item" do | |
19 | + Item.stub!(:find).with("37").and_return(mock_item) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:item].should equal(mock_item) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new item as @item" do | |
27 | + Item.stub!(:new).and_return(mock_item) | |
28 | + get :new | |
29 | + assigns[:item].should equal(mock_item) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested item as @item" do | |
35 | + Item.stub!(:find).with("37").and_return(mock_item) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:item].should equal(mock_item) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created item as @item" do | |
45 | + Item.stub!(:new).with({'these' => 'params'}).and_return(mock_item(:save => true)) | |
46 | + post :create, :item => {:these => 'params'} | |
47 | + assigns[:item].should equal(mock_item) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created item" do | |
51 | + Item.stub!(:new).and_return(mock_item(:save => true)) | |
52 | + post :create, :item => {} | |
53 | + response.should redirect_to(item_url(mock_item)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved item as @item" do | |
59 | + Item.stub!(:new).with({'these' => 'params'}).and_return(mock_item(:save => false)) | |
60 | + post :create, :item => {:these => 'params'} | |
61 | + assigns[:item].should equal(mock_item) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Item.stub!(:new).and_return(mock_item(:save => false)) | |
66 | + post :create, :item => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested item" do | |
77 | + Item.should_receive(:find).with("37").and_return(mock_item) | |
78 | + mock_item.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :item => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested item as @item" do | |
83 | + Item.stub!(:find).and_return(mock_item(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:item].should equal(mock_item) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the item" do | |
89 | + Item.stub!(:find).and_return(mock_item(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(item_url(mock_item)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested item" do | |
97 | + Item.should_receive(:find).with("37").and_return(mock_item) | |
98 | + mock_item.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :item => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the item as @item" do | |
103 | + Item.stub!(:find).and_return(mock_item(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:item].should equal(mock_item) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Item.stub!(:find).and_return(mock_item(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested item" do | |
119 | + Item.should_receive(:find).with("37").and_return(mock_item) | |
120 | + mock_item.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the items list" do | |
125 | + Item.stub!(:find).and_return(mock_item(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(items_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe PromptsController do | |
4 | + | |
5 | + def mock_prompt(stubs={}) | |
6 | + @mock_prompt ||= mock_model(Prompt, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all prompts as @prompts" do | |
11 | + Prompt.stub!(:find).with(:all).and_return([mock_prompt]) | |
12 | + get :index | |
13 | + assigns[:prompts].should == [mock_prompt] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested prompt as @prompt" do | |
19 | + Prompt.stub!(:find).with("37").and_return(mock_prompt) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:prompt].should equal(mock_prompt) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new prompt as @prompt" do | |
27 | + Prompt.stub!(:new).and_return(mock_prompt) | |
28 | + get :new | |
29 | + assigns[:prompt].should equal(mock_prompt) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested prompt as @prompt" do | |
35 | + Prompt.stub!(:find).with("37").and_return(mock_prompt) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:prompt].should equal(mock_prompt) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created prompt as @prompt" do | |
45 | + Prompt.stub!(:new).with({'these' => 'params'}).and_return(mock_prompt(:save => true)) | |
46 | + post :create, :prompt => {:these => 'params'} | |
47 | + assigns[:prompt].should equal(mock_prompt) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created prompt" do | |
51 | + Prompt.stub!(:new).and_return(mock_prompt(:save => true)) | |
52 | + post :create, :prompt => {} | |
53 | + response.should redirect_to(prompt_url(mock_prompt)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved prompt as @prompt" do | |
59 | + Prompt.stub!(:new).with({'these' => 'params'}).and_return(mock_prompt(:save => false)) | |
60 | + post :create, :prompt => {:these => 'params'} | |
61 | + assigns[:prompt].should equal(mock_prompt) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Prompt.stub!(:new).and_return(mock_prompt(:save => false)) | |
66 | + post :create, :prompt => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested prompt" do | |
77 | + Prompt.should_receive(:find).with("37").and_return(mock_prompt) | |
78 | + mock_prompt.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :prompt => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested prompt as @prompt" do | |
83 | + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:prompt].should equal(mock_prompt) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the prompt" do | |
89 | + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(prompt_url(mock_prompt)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested prompt" do | |
97 | + Prompt.should_receive(:find).with("37").and_return(mock_prompt) | |
98 | + mock_prompt.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :prompt => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the prompt as @prompt" do | |
103 | + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:prompt].should equal(mock_prompt) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested prompt" do | |
119 | + Prompt.should_receive(:find).with("37").and_return(mock_prompt) | |
120 | + mock_prompt.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the prompts list" do | |
125 | + Prompt.stub!(:find).and_return(mock_prompt(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(prompts_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe QuestionsController do | |
4 | + | |
5 | + def mock_question(stubs={}) | |
6 | + @mock_question ||= mock_model(Question, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all questions as @questions" do | |
11 | + Question.stub!(:find).with(:all).and_return([mock_question]) | |
12 | + get :index | |
13 | + assigns[:questions].should == [mock_question] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested question as @question" do | |
19 | + Question.stub!(:find).with("37").and_return(mock_question) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:question].should equal(mock_question) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new question as @question" do | |
27 | + Question.stub!(:new).and_return(mock_question) | |
28 | + get :new | |
29 | + assigns[:question].should equal(mock_question) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested question as @question" do | |
35 | + Question.stub!(:find).with("37").and_return(mock_question) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:question].should equal(mock_question) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created question as @question" do | |
45 | + Question.stub!(:new).with({'these' => 'params'}).and_return(mock_question(:save => true)) | |
46 | + post :create, :question => {:these => 'params'} | |
47 | + assigns[:question].should equal(mock_question) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created question" do | |
51 | + Question.stub!(:new).and_return(mock_question(:save => true)) | |
52 | + post :create, :question => {} | |
53 | + response.should redirect_to(question_url(mock_question)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved question as @question" do | |
59 | + Question.stub!(:new).with({'these' => 'params'}).and_return(mock_question(:save => false)) | |
60 | + post :create, :question => {:these => 'params'} | |
61 | + assigns[:question].should equal(mock_question) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Question.stub!(:new).and_return(mock_question(:save => false)) | |
66 | + post :create, :question => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested question" do | |
77 | + Question.should_receive(:find).with("37").and_return(mock_question) | |
78 | + mock_question.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :question => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested question as @question" do | |
83 | + Question.stub!(:find).and_return(mock_question(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:question].should equal(mock_question) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the question" do | |
89 | + Question.stub!(:find).and_return(mock_question(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(question_url(mock_question)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested question" do | |
97 | + Question.should_receive(:find).with("37").and_return(mock_question) | |
98 | + mock_question.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :question => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the question as @question" do | |
103 | + Question.stub!(:find).and_return(mock_question(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:question].should equal(mock_question) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Question.stub!(:find).and_return(mock_question(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested question" do | |
119 | + Question.should_receive(:find).with("37").and_return(mock_question) | |
120 | + mock_question.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the questions list" do | |
125 | + Question.stub!(:find).and_return(mock_question(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(questions_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,131 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe VisitorsController do | |
4 | + | |
5 | + def mock_visitor(stubs={}) | |
6 | + @mock_visitor ||= mock_model(Visitor, stubs) | |
7 | + end | |
8 | + | |
9 | + describe "GET index" do | |
10 | + it "assigns all visitors as @visitors" do | |
11 | + Visitor.stub!(:find).with(:all).and_return([mock_visitor]) | |
12 | + get :index | |
13 | + assigns[:visitors].should == [mock_visitor] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + describe "GET show" do | |
18 | + it "assigns the requested visitor as @visitor" do | |
19 | + Visitor.stub!(:find).with("37").and_return(mock_visitor) | |
20 | + get :show, :id => "37" | |
21 | + assigns[:visitor].should equal(mock_visitor) | |
22 | + end | |
23 | + end | |
24 | + | |
25 | + describe "GET new" do | |
26 | + it "assigns a new visitor as @visitor" do | |
27 | + Visitor.stub!(:new).and_return(mock_visitor) | |
28 | + get :new | |
29 | + assigns[:visitor].should equal(mock_visitor) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + describe "GET edit" do | |
34 | + it "assigns the requested visitor as @visitor" do | |
35 | + Visitor.stub!(:find).with("37").and_return(mock_visitor) | |
36 | + get :edit, :id => "37" | |
37 | + assigns[:visitor].should equal(mock_visitor) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "POST create" do | |
42 | + | |
43 | + describe "with valid params" do | |
44 | + it "assigns a newly created visitor as @visitor" do | |
45 | + Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => true)) | |
46 | + post :create, :visitor => {:these => 'params'} | |
47 | + assigns[:visitor].should equal(mock_visitor) | |
48 | + end | |
49 | + | |
50 | + it "redirects to the created visitor" do | |
51 | + Visitor.stub!(:new).and_return(mock_visitor(:save => true)) | |
52 | + post :create, :visitor => {} | |
53 | + response.should redirect_to(visitor_url(mock_visitor)) | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + describe "with invalid params" do | |
58 | + it "assigns a newly created but unsaved visitor as @visitor" do | |
59 | + Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => false)) | |
60 | + post :create, :visitor => {:these => 'params'} | |
61 | + assigns[:visitor].should equal(mock_visitor) | |
62 | + end | |
63 | + | |
64 | + it "re-renders the 'new' template" do | |
65 | + Visitor.stub!(:new).and_return(mock_visitor(:save => false)) | |
66 | + post :create, :visitor => {} | |
67 | + response.should render_template('new') | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + end | |
72 | + | |
73 | + describe "PUT update" do | |
74 | + | |
75 | + describe "with valid params" do | |
76 | + it "updates the requested visitor" do | |
77 | + Visitor.should_receive(:find).with("37").and_return(mock_visitor) | |
78 | + mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) | |
79 | + put :update, :id => "37", :visitor => {:these => 'params'} | |
80 | + end | |
81 | + | |
82 | + it "assigns the requested visitor as @visitor" do | |
83 | + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => true)) | |
84 | + put :update, :id => "1" | |
85 | + assigns[:visitor].should equal(mock_visitor) | |
86 | + end | |
87 | + | |
88 | + it "redirects to the visitor" do | |
89 | + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => true)) | |
90 | + put :update, :id => "1" | |
91 | + response.should redirect_to(visitor_url(mock_visitor)) | |
92 | + end | |
93 | + end | |
94 | + | |
95 | + describe "with invalid params" do | |
96 | + it "updates the requested visitor" do | |
97 | + Visitor.should_receive(:find).with("37").and_return(mock_visitor) | |
98 | + mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) | |
99 | + put :update, :id => "37", :visitor => {:these => 'params'} | |
100 | + end | |
101 | + | |
102 | + it "assigns the visitor as @visitor" do | |
103 | + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => false)) | |
104 | + put :update, :id => "1" | |
105 | + assigns[:visitor].should equal(mock_visitor) | |
106 | + end | |
107 | + | |
108 | + it "re-renders the 'edit' template" do | |
109 | + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => false)) | |
110 | + put :update, :id => "1" | |
111 | + response.should render_template('edit') | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + end | |
116 | + | |
117 | + describe "DELETE destroy" do | |
118 | + it "destroys the requested visitor" do | |
119 | + Visitor.should_receive(:find).with("37").and_return(mock_visitor) | |
120 | + mock_visitor.should_receive(:destroy) | |
121 | + delete :destroy, :id => "37" | |
122 | + end | |
123 | + | |
124 | + it "redirects to the visitors list" do | |
125 | + Visitor.stub!(:find).and_return(mock_visitor(:destroy => true)) | |
126 | + delete :destroy, :id => "1" | |
127 | + response.should redirect_to(visitors_url) | |
128 | + end | |
129 | + end | |
130 | + | |
131 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +Factory.define(:item) do |f| | |
2 | + f.sequence(:data) { |i| "Item #{i}" } | |
3 | +end | |
4 | + | |
5 | +Factory.define(:question) do |f| | |
6 | + f.sequence(:name) { |i| "Name #{i}" } | |
7 | +end | |
8 | + | |
9 | +Factory.define(:visitor) do |f| | |
10 | + f.sequence(:identifier) { |i| "Identifier #{i}" } | |
11 | +end | |
12 | + | |
13 | +Factory.define(:prompt) do |f| | |
14 | + f.sequence(:tracking) { |i| "Prompt we're calling #{i}" } | |
15 | +end | |
16 | + | |
17 | +Factory.define(:choice) do |f| | |
18 | + f.sequence(:data) { |i| "Choice: #{i}" } | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ChoicesHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(ChoicesHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ClicksHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(ClicksHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe ItemsHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(ItemsHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe PromptsHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(PromptsHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe QuestionsHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(QuestionsHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe VisitorsHelper do | |
4 | + | |
5 | + #Delete this example and add some real ones or delete this file | |
6 | + it "is included in the helper object" do | |
7 | + included_modules = (class << helper; self; end).send :included_modules | |
8 | + included_modules.should include(VisitorsHelper) | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Choice do | |
4 | + | |
5 | + it {should belong_to :question} | |
6 | + it {should belong_to :item} | |
7 | + it {should validate_presence_of :question} | |
8 | + | |
9 | + before(:each) do | |
10 | + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) | |
11 | + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) | |
12 | + @question = Question.create(:name => 'which do you like better?', :site => @aoi_clone, :creator => @johndoe) | |
13 | + | |
14 | + @valid_attributes = { | |
15 | + :creator => @johndoe, | |
16 | + :question => @question | |
17 | + } | |
18 | + end | |
19 | + | |
20 | + it "should create a new instance given valid attributes" do | |
21 | + Choice.create!(@valid_attributes) | |
22 | + end | |
23 | + | |
24 | + it "should generate prompts after creation" do | |
25 | + @question.prompts.should_not be_empty | |
26 | + choice1 = Choice.create!(@valid_attributes.merge(:data => '1234')) | |
27 | + @question.prompts.should_not be_empty | |
28 | + end | |
29 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Click do | |
4 | + | |
5 | + it {should belong_to :visitor} | |
6 | + it {should belong_to :site} | |
7 | + | |
8 | + before(:each) do | |
9 | + @valid_attributes = { | |
10 | + :site_id => 1, | |
11 | + :visitor_id => 1, | |
12 | + :additional_info => "value for additional_info" | |
13 | + } | |
14 | + end | |
15 | + | |
16 | + it "should create a new instance given valid attributes" do | |
17 | + Click.create!(@valid_attributes) | |
18 | + end | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Item do | |
4 | + it {should belong_to :creator} | |
5 | + it {should belong_to :site} | |
6 | + | |
7 | + before(:each) do | |
8 | + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) | |
9 | + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) | |
10 | + @valid_attributes = { | |
11 | + :site => @aoi_clone, | |
12 | + :creator => @johndoe | |
13 | + } | |
14 | + end | |
15 | + | |
16 | + it "should create a new instance given valid attributes" do | |
17 | + Item.create!(@valid_attributes) | |
18 | + end | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Prompt do | |
4 | + it {should belong_to :question} | |
5 | + it {should belong_to :left_choice} | |
6 | + it {should belong_to :right_choice} | |
7 | + | |
8 | + before(:each) do | |
9 | + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) | |
10 | + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) | |
11 | + @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor) | |
12 | + @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous') | |
13 | + @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous') | |
14 | + @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc) | |
15 | + @valid_attributes = { | |
16 | + :left_choice => @lc, | |
17 | + :right_choice => @rc, | |
18 | + :question => @question | |
19 | + | |
20 | + } | |
21 | + end | |
22 | + | |
23 | + it "should create a new instance given valid attributes" do | |
24 | + Prompt.create!(@valid_attributes) | |
25 | + end | |
26 | +end | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Question do | |
4 | + | |
5 | + it {should belong_to :creator} | |
6 | + it {should belong_to :site} | |
7 | + it {should have_many :choices} | |
8 | + it {should have_many :prompts} | |
9 | + it {should validate_presence_of :site} | |
10 | + | |
11 | + before(:each) do | |
12 | + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) | |
13 | + @valid_attributes = { | |
14 | + :site => @aoi_clone, | |
15 | + :creator => @aoi_clone.default_visitor | |
16 | + | |
17 | + } | |
18 | + | |
19 | + # @item1 = Factory.create(:item, :data => "foo", :id => 1, :creator_id => 8) | |
20 | + # @item2 = Factory.create(:item, :data => "bar", :id => 2, :creator_id => 8) | |
21 | + end | |
22 | + | |
23 | + it "should create a new instance given valid attributes" do | |
24 | + Question.create!(@valid_attributes) | |
25 | + end | |
26 | + | |
27 | + it "should be creatable by a user" do | |
28 | + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) | |
29 | + end | |
30 | + | |
31 | + it "should create two default choices if none are provided" do | |
32 | + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) | |
33 | + q.choices(true).size.should == 2 | |
34 | + end | |
35 | + | |
36 | + it "should generate prompts after choices are added" do | |
37 | + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) | |
38 | + q.prompts(true).size.should == 2 | |
39 | + end | |
40 | + | |
41 | + #q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) | |
42 | +end | |
0 | 43 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe Skip do | |
4 | + it {should belong_to :prompt} | |
5 | + it {should belong_to :skipper} | |
6 | + before(:each) do | |
7 | + @valid_attributes = { | |
8 | + | |
9 | + } | |
10 | + end | |
11 | + | |
12 | + it "should create a new instance given valid attributes" do | |
13 | + Skip.create!(@valid_attributes) | |
14 | + end | |
15 | +end | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
1 | +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
2 | + | |
3 | +describe User do | |
4 | + it {should have_many :visitors} | |
5 | + | |
6 | + before(:each) do | |
7 | + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) | |
8 | + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) | |
9 | + @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor) | |
10 | + @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous') | |
11 | + @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous') | |
12 | + @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc) | |
13 | + end | |
14 | + | |
15 | + | |
16 | + it "should be able to create a question as a site" do | |
17 | + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) | |
18 | + q.should_not be_nil | |
19 | + q.site.should_not be_nil | |
20 | + q.site.should eql @aoi_clone | |
21 | + end | |
22 | + | |
23 | + it "should be able to create a choice for a question " do | |
24 | + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) #replace with a factory | |
25 | + c = @aoi_clone.create_choice("foobarbaz", q, {:data => 'foobarbaz'}) | |
26 | + q.should_not be_nil | |
27 | + q.choices.should_not be_empty | |
28 | + q.choices.size.should eql 3 | |
29 | + end | |
30 | + | |
31 | + it "should be able to record a visitor's vote" do | |
32 | + v = @aoi_clone.record_vote("johnnydoe", @prompt, 0) | |
33 | + prompt_votes = @prompt.votes(true) | |
34 | + prompt_votes.should_not be_empty | |
35 | + prompt_votes.size.should eql 1 | |
36 | + | |
37 | + choices = @prompt.choices | |
38 | + #@question.prompts(true).size.should == 2 | |
39 | + choices.should_not be_empty | |
40 | + | |
41 | + choice_votes = choices[0].votes(true) | |
42 | + choice_votes.should_not be_empty | |
43 | + choice_votes.size.should eql 1 | |
44 | + end | |
45 | + | |
46 | + it "should be able to record a visitor's skip" do | |
47 | + s = @aoi_clone.record_skip("johnnydoe", @prompt) | |
48 | + end | |
49 | + | |
50 | +end | |
0 | 51 | \ No newline at end of file | ... | ... |