From c68e03522509c8efa83c511fde2971391eccad77 Mon Sep 17 00:00:00 2001 From: Pius Uzamere Date: Thu, 3 Dec 2009 14:05:30 -0500 Subject: [PATCH] specified and implemented model functionality --- app/controllers/choices_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/controllers/clicks_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/controllers/items_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/controllers/prompts_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/controllers/questions_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/controllers/visitors_controller.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/helpers/choices_helper.rb | 2 ++ app/helpers/clicks_helper.rb | 2 ++ app/helpers/items_helper.rb | 2 ++ app/helpers/prompts_helper.rb | 2 ++ app/helpers/questions_helper.rb | 2 ++ app/helpers/visitors_helper.rb | 2 ++ app/models/choice.rb | 30 ++++++++++++++++++++++++++++++ app/models/click.rb | 4 ++++ app/models/item.rb | 16 ++++++++++++++++ app/models/prompt.rb | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/question.rb | 33 +++++++++++++++++++++++++++++++++ app/models/skip.rb | 4 ++++ app/models/user.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/visitor.rb | 23 +++++++++++++++++++++++ app/models/vote.rb | 4 ++++ app/views/choices/edit.html.erb | 12 ++++++++++++ app/views/choices/index.html.erb | 18 ++++++++++++++++++ app/views/choices/new.html.erb | 11 +++++++++++ app/views/choices/show.html.erb | 3 +++ app/views/clicks/edit.html.erb | 24 ++++++++++++++++++++++++ app/views/clicks/index.html.erb | 24 ++++++++++++++++++++++++ app/views/clicks/new.html.erb | 23 +++++++++++++++++++++++ app/views/clicks/show.html.erb | 18 ++++++++++++++++++ app/views/items/edit.html.erb | 12 ++++++++++++ app/views/items/index.html.erb | 18 ++++++++++++++++++ app/views/items/new.html.erb | 11 +++++++++++ app/views/items/show.html.erb | 3 +++ app/views/layouts/choices.html.erb | 17 +++++++++++++++++ app/views/layouts/clicks.html.erb | 17 +++++++++++++++++ app/views/layouts/items.html.erb | 17 +++++++++++++++++ app/views/layouts/prompts.html.erb | 17 +++++++++++++++++ app/views/layouts/questions.html.erb | 17 +++++++++++++++++ app/views/layouts/visitors.html.erb | 17 +++++++++++++++++ app/views/prompts/edit.html.erb | 12 ++++++++++++ app/views/prompts/index.html.erb | 18 ++++++++++++++++++ app/views/prompts/new.html.erb | 11 +++++++++++ app/views/prompts/show.html.erb | 3 +++ app/views/questions/edit.html.erb | 12 ++++++++++++ app/views/questions/index.html.erb | 18 ++++++++++++++++++ app/views/questions/new.html.erb | 11 +++++++++++ app/views/questions/show.html.erb | 3 +++ app/views/visitors/edit.html.erb | 24 ++++++++++++++++++++++++ app/views/visitors/index.html.erb | 24 ++++++++++++++++++++++++ app/views/visitors/new.html.erb | 23 +++++++++++++++++++++++ app/views/visitors/show.html.erb | 18 ++++++++++++++++++ config/routes.rb | 12 ++++++++++++ db/migrate/20091203161430_create_questions.rb | 23 +++++++++++++++++++++++ db/migrate/20091203163251_create_visitors.rb | 17 +++++++++++++++++ db/migrate/20091203164109_create_choices.rb | 24 ++++++++++++++++++++++++ db/migrate/20091203165033_create_items.rb | 19 +++++++++++++++++++ db/migrate/20091203170231_add_site_id_to_questions.rb | 9 +++++++++ db/migrate/20091203173153_create_prompts.rb | 20 ++++++++++++++++++++ db/migrate/20091203175954_create_votes.rb | 17 +++++++++++++++++ db/migrate/20091203185050_create_skips.rb | 16 ++++++++++++++++ db/migrate/20091203190244_create_clicks.rb | 15 +++++++++++++++ lib/tasks/rspec.rake | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/stylesheets/scaffold.css | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ script/autospec | 6 ++++++ script/spec | 10 ++++++++++ script/spec_server | 9 +++++++++ spec/controllers/choices_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/clicks_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/items_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/prompts_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/questions_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/visitors_controller_spec.rb | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/factories.rb | 19 +++++++++++++++++++ spec/fixtures/choices.yml | 0 spec/fixtures/clicks.yml | 0 spec/fixtures/items.yml | 0 spec/fixtures/prompts.yml | 0 spec/fixtures/questions.yml | 0 spec/fixtures/skips.yml | 0 spec/fixtures/visitors.yml | 0 spec/fixtures/votes.yml | 0 spec/helpers/choices_helper_spec.rb | 11 +++++++++++ spec/helpers/clicks_helper_spec.rb | 11 +++++++++++ spec/helpers/items_helper_spec.rb | 11 +++++++++++ spec/helpers/prompts_helper_spec.rb | 11 +++++++++++ spec/helpers/questions_helper_spec.rb | 11 +++++++++++ spec/helpers/visitors_helper_spec.rb | 11 +++++++++++ spec/integration/choices_spec.rb | 4 ++++ spec/integration/clicks_spec.rb | 4 ++++ spec/integration/items_spec.rb | 4 ++++ spec/integration/prompts_spec.rb | 4 ++++ spec/integration/questions_spec.rb | 4 ++++ spec/integration/visitors_spec.rb | 4 ++++ spec/models/choice_spec.rb | 29 +++++++++++++++++++++++++++++ spec/models/click_spec.rb | 19 +++++++++++++++++++ spec/models/item_spec.rb | 19 +++++++++++++++++++ spec/models/prompt_spec.rb | 26 ++++++++++++++++++++++++++ spec/models/question_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ spec/models/skip_spec.rb | 15 +++++++++++++++ spec/models/user_spec.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ spec/models/visitor_spec.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ spec/models/vote_spec.rb | 17 +++++++++++++++++ spec/rcov.opts | 2 ++ spec/routing/choices_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/routing/clicks_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/routing/items_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/routing/prompts_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/routing/questions_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/routing/visitors_routing_spec.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/spec.opts | 4 ++++ spec/spec_helper.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ spec/views/choices/edit.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/choices/index.html.erb_spec.rb | 16 ++++++++++++++++ spec/views/choices/new.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/choices/show.html.erb_spec.rb | 12 ++++++++++++ spec/views/clicks/edit.html.erb_spec.rb | 24 ++++++++++++++++++++++++ spec/views/clicks/index.html.erb_spec.rb | 27 +++++++++++++++++++++++++++ spec/views/clicks/new.html.erb_spec.rb | 24 ++++++++++++++++++++++++ spec/views/clicks/show.html.erb_spec.rb | 19 +++++++++++++++++++ spec/views/items/edit.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/items/index.html.erb_spec.rb | 16 ++++++++++++++++ spec/views/items/new.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/items/show.html.erb_spec.rb | 12 ++++++++++++ spec/views/prompts/edit.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/prompts/index.html.erb_spec.rb | 16 ++++++++++++++++ spec/views/prompts/new.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/prompts/show.html.erb_spec.rb | 12 ++++++++++++ spec/views/questions/edit.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/questions/index.html.erb_spec.rb | 16 ++++++++++++++++ spec/views/questions/new.html.erb_spec.rb | 18 ++++++++++++++++++ spec/views/questions/show.html.erb_spec.rb | 12 ++++++++++++ spec/views/visitors/edit.html.erb_spec.rb | 24 ++++++++++++++++++++++++ spec/views/visitors/index.html.erb_spec.rb | 27 +++++++++++++++++++++++++++ spec/views/visitors/new.html.erb_spec.rb | 24 ++++++++++++++++++++++++ spec/views/visitors/show.html.erb_spec.rb | 19 +++++++++++++++++++ vendor/plugins/blitz/generators/model/templates/fixtures.yml | 0 136 files changed, 3680 insertions(+), 0 deletions(-) create mode 100644 app/controllers/choices_controller.rb create mode 100644 app/controllers/clicks_controller.rb create mode 100644 app/controllers/items_controller.rb create mode 100644 app/controllers/prompts_controller.rb create mode 100644 app/controllers/questions_controller.rb create mode 100644 app/controllers/visitors_controller.rb create mode 100644 app/helpers/choices_helper.rb create mode 100644 app/helpers/clicks_helper.rb create mode 100644 app/helpers/items_helper.rb create mode 100644 app/helpers/prompts_helper.rb create mode 100644 app/helpers/questions_helper.rb create mode 100644 app/helpers/visitors_helper.rb create mode 100644 app/models/choice.rb create mode 100644 app/models/click.rb create mode 100644 app/models/item.rb create mode 100644 app/models/prompt.rb create mode 100644 app/models/question.rb create mode 100644 app/models/skip.rb create mode 100644 app/models/visitor.rb create mode 100644 app/models/vote.rb create mode 100644 app/views/choices/edit.html.erb create mode 100644 app/views/choices/index.html.erb create mode 100644 app/views/choices/new.html.erb create mode 100644 app/views/choices/show.html.erb create mode 100644 app/views/clicks/edit.html.erb create mode 100644 app/views/clicks/index.html.erb create mode 100644 app/views/clicks/new.html.erb create mode 100644 app/views/clicks/show.html.erb create mode 100644 app/views/items/edit.html.erb create mode 100644 app/views/items/index.html.erb create mode 100644 app/views/items/new.html.erb create mode 100644 app/views/items/show.html.erb create mode 100644 app/views/layouts/choices.html.erb create mode 100644 app/views/layouts/clicks.html.erb create mode 100644 app/views/layouts/items.html.erb create mode 100644 app/views/layouts/prompts.html.erb create mode 100644 app/views/layouts/questions.html.erb create mode 100644 app/views/layouts/visitors.html.erb create mode 100644 app/views/prompts/edit.html.erb create mode 100644 app/views/prompts/index.html.erb create mode 100644 app/views/prompts/new.html.erb create mode 100644 app/views/prompts/show.html.erb create mode 100644 app/views/questions/edit.html.erb create mode 100644 app/views/questions/index.html.erb create mode 100644 app/views/questions/new.html.erb create mode 100644 app/views/questions/show.html.erb create mode 100644 app/views/visitors/edit.html.erb create mode 100644 app/views/visitors/index.html.erb create mode 100644 app/views/visitors/new.html.erb create mode 100644 app/views/visitors/show.html.erb create mode 100644 db/migrate/20091203161430_create_questions.rb create mode 100644 db/migrate/20091203163251_create_visitors.rb create mode 100644 db/migrate/20091203164109_create_choices.rb create mode 100644 db/migrate/20091203165033_create_items.rb create mode 100644 db/migrate/20091203170231_add_site_id_to_questions.rb create mode 100644 db/migrate/20091203173153_create_prompts.rb create mode 100644 db/migrate/20091203175954_create_votes.rb create mode 100644 db/migrate/20091203185050_create_skips.rb create mode 100644 db/migrate/20091203190244_create_clicks.rb create mode 100644 lib/tasks/rspec.rake create mode 100644 public/stylesheets/scaffold.css create mode 100755 script/autospec create mode 100755 script/spec create mode 100755 script/spec_server create mode 100644 spec/controllers/choices_controller_spec.rb create mode 100644 spec/controllers/clicks_controller_spec.rb create mode 100644 spec/controllers/items_controller_spec.rb create mode 100644 spec/controllers/prompts_controller_spec.rb create mode 100644 spec/controllers/questions_controller_spec.rb create mode 100644 spec/controllers/visitors_controller_spec.rb create mode 100644 spec/factories.rb create mode 100644 spec/fixtures/choices.yml create mode 100644 spec/fixtures/clicks.yml create mode 100644 spec/fixtures/items.yml create mode 100644 spec/fixtures/prompts.yml create mode 100644 spec/fixtures/questions.yml create mode 100644 spec/fixtures/skips.yml create mode 100644 spec/fixtures/visitors.yml create mode 100644 spec/fixtures/votes.yml create mode 100644 spec/helpers/choices_helper_spec.rb create mode 100644 spec/helpers/clicks_helper_spec.rb create mode 100644 spec/helpers/items_helper_spec.rb create mode 100644 spec/helpers/prompts_helper_spec.rb create mode 100644 spec/helpers/questions_helper_spec.rb create mode 100644 spec/helpers/visitors_helper_spec.rb create mode 100644 spec/integration/choices_spec.rb create mode 100644 spec/integration/clicks_spec.rb create mode 100644 spec/integration/items_spec.rb create mode 100644 spec/integration/prompts_spec.rb create mode 100644 spec/integration/questions_spec.rb create mode 100644 spec/integration/visitors_spec.rb create mode 100644 spec/models/choice_spec.rb create mode 100644 spec/models/click_spec.rb create mode 100644 spec/models/item_spec.rb create mode 100644 spec/models/prompt_spec.rb create mode 100644 spec/models/question_spec.rb create mode 100644 spec/models/skip_spec.rb create mode 100644 spec/models/user_spec.rb create mode 100644 spec/models/visitor_spec.rb create mode 100644 spec/models/vote_spec.rb create mode 100644 spec/rcov.opts create mode 100644 spec/routing/choices_routing_spec.rb create mode 100644 spec/routing/clicks_routing_spec.rb create mode 100644 spec/routing/items_routing_spec.rb create mode 100644 spec/routing/prompts_routing_spec.rb create mode 100644 spec/routing/questions_routing_spec.rb create mode 100644 spec/routing/visitors_routing_spec.rb create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb create mode 100644 spec/views/choices/edit.html.erb_spec.rb create mode 100644 spec/views/choices/index.html.erb_spec.rb create mode 100644 spec/views/choices/new.html.erb_spec.rb create mode 100644 spec/views/choices/show.html.erb_spec.rb create mode 100644 spec/views/clicks/edit.html.erb_spec.rb create mode 100644 spec/views/clicks/index.html.erb_spec.rb create mode 100644 spec/views/clicks/new.html.erb_spec.rb create mode 100644 spec/views/clicks/show.html.erb_spec.rb create mode 100644 spec/views/items/edit.html.erb_spec.rb create mode 100644 spec/views/items/index.html.erb_spec.rb create mode 100644 spec/views/items/new.html.erb_spec.rb create mode 100644 spec/views/items/show.html.erb_spec.rb create mode 100644 spec/views/prompts/edit.html.erb_spec.rb create mode 100644 spec/views/prompts/index.html.erb_spec.rb create mode 100644 spec/views/prompts/new.html.erb_spec.rb create mode 100644 spec/views/prompts/show.html.erb_spec.rb create mode 100644 spec/views/questions/edit.html.erb_spec.rb create mode 100644 spec/views/questions/index.html.erb_spec.rb create mode 100644 spec/views/questions/new.html.erb_spec.rb create mode 100644 spec/views/questions/show.html.erb_spec.rb create mode 100644 spec/views/visitors/edit.html.erb_spec.rb create mode 100644 spec/views/visitors/index.html.erb_spec.rb create mode 100644 spec/views/visitors/new.html.erb_spec.rb create mode 100644 spec/views/visitors/show.html.erb_spec.rb create mode 100644 vendor/plugins/blitz/generators/model/templates/fixtures.yml diff --git a/app/controllers/choices_controller.rb b/app/controllers/choices_controller.rb new file mode 100644 index 0000000..3aab8ea --- /dev/null +++ b/app/controllers/choices_controller.rb @@ -0,0 +1,85 @@ +class ChoicesController < ApplicationController + # GET /choices + # GET /choices.xml + def index + @choices = Choice.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @choices } + end + end + + # GET /choices/1 + # GET /choices/1.xml + def show + @choice = Choice.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @choice } + end + end + + # GET /choices/new + # GET /choices/new.xml + def new + @choice = Choice.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @choice } + end + end + + # GET /choices/1/edit + def edit + @choice = Choice.find(params[:id]) + end + + # POST /choices + # POST /choices.xml + def create + @choice = Choice.new(params[:choice]) + + respond_to do |format| + if @choice.save + flash[:notice] = 'Choice was successfully created.' + format.html { redirect_to(@choice) } + format.xml { render :xml => @choice, :status => :created, :location => @choice } + else + format.html { render :action => "new" } + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /choices/1 + # PUT /choices/1.xml + def update + @choice = Choice.find(params[:id]) + + respond_to do |format| + if @choice.update_attributes(params[:choice]) + flash[:notice] = 'Choice was successfully updated.' + format.html { redirect_to(@choice) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /choices/1 + # DELETE /choices/1.xml + def destroy + @choice = Choice.find(params[:id]) + @choice.destroy + + respond_to do |format| + format.html { redirect_to(choices_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/clicks_controller.rb b/app/controllers/clicks_controller.rb new file mode 100644 index 0000000..9ddf4a6 --- /dev/null +++ b/app/controllers/clicks_controller.rb @@ -0,0 +1,85 @@ +class ClicksController < ApplicationController + # GET /clicks + # GET /clicks.xml + def index + @clicks = Click.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @clicks } + end + end + + # GET /clicks/1 + # GET /clicks/1.xml + def show + @click = Click.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @click } + end + end + + # GET /clicks/new + # GET /clicks/new.xml + def new + @click = Click.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @click } + end + end + + # GET /clicks/1/edit + def edit + @click = Click.find(params[:id]) + end + + # POST /clicks + # POST /clicks.xml + def create + @click = Click.new(params[:click]) + + respond_to do |format| + if @click.save + flash[:notice] = 'Click was successfully created.' + format.html { redirect_to(@click) } + format.xml { render :xml => @click, :status => :created, :location => @click } + else + format.html { render :action => "new" } + format.xml { render :xml => @click.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /clicks/1 + # PUT /clicks/1.xml + def update + @click = Click.find(params[:id]) + + respond_to do |format| + if @click.update_attributes(params[:click]) + flash[:notice] = 'Click was successfully updated.' + format.html { redirect_to(@click) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @click.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /clicks/1 + # DELETE /clicks/1.xml + def destroy + @click = Click.find(params[:id]) + @click.destroy + + respond_to do |format| + format.html { redirect_to(clicks_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb new file mode 100644 index 0000000..a87ecf0 --- /dev/null +++ b/app/controllers/items_controller.rb @@ -0,0 +1,85 @@ +class ItemsController < ApplicationController + # GET /items + # GET /items.xml + def index + @items = Item.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @items } + end + end + + # GET /items/1 + # GET /items/1.xml + def show + @item = Item.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @item } + end + end + + # GET /items/new + # GET /items/new.xml + def new + @item = Item.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @item } + end + end + + # GET /items/1/edit + def edit + @item = Item.find(params[:id]) + end + + # POST /items + # POST /items.xml + def create + @item = Item.new(params[:item]) + + respond_to do |format| + if @item.save + flash[:notice] = 'Item was successfully created.' + format.html { redirect_to(@item) } + format.xml { render :xml => @item, :status => :created, :location => @item } + else + format.html { render :action => "new" } + format.xml { render :xml => @item.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /items/1 + # PUT /items/1.xml + def update + @item = Item.find(params[:id]) + + respond_to do |format| + if @item.update_attributes(params[:item]) + flash[:notice] = 'Item was successfully updated.' + format.html { redirect_to(@item) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @item.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /items/1 + # DELETE /items/1.xml + def destroy + @item = Item.find(params[:id]) + @item.destroy + + respond_to do |format| + format.html { redirect_to(items_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/prompts_controller.rb b/app/controllers/prompts_controller.rb new file mode 100644 index 0000000..46ecfd5 --- /dev/null +++ b/app/controllers/prompts_controller.rb @@ -0,0 +1,85 @@ +class PromptsController < ApplicationController + # GET /prompts + # GET /prompts.xml + def index + @prompts = Prompt.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @prompts } + end + end + + # GET /prompts/1 + # GET /prompts/1.xml + def show + @prompt = Prompt.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @prompt } + end + end + + # GET /prompts/new + # GET /prompts/new.xml + def new + @prompt = Prompt.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @prompt } + end + end + + # GET /prompts/1/edit + def edit + @prompt = Prompt.find(params[:id]) + end + + # POST /prompts + # POST /prompts.xml + def create + @prompt = Prompt.new(params[:prompt]) + + respond_to do |format| + if @prompt.save + flash[:notice] = 'Prompt was successfully created.' + format.html { redirect_to(@prompt) } + format.xml { render :xml => @prompt, :status => :created, :location => @prompt } + else + format.html { render :action => "new" } + format.xml { render :xml => @prompt.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /prompts/1 + # PUT /prompts/1.xml + def update + @prompt = Prompt.find(params[:id]) + + respond_to do |format| + if @prompt.update_attributes(params[:prompt]) + flash[:notice] = 'Prompt was successfully updated.' + format.html { redirect_to(@prompt) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @prompt.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /prompts/1 + # DELETE /prompts/1.xml + def destroy + @prompt = Prompt.find(params[:id]) + @prompt.destroy + + respond_to do |format| + format.html { redirect_to(prompts_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb new file mode 100644 index 0000000..5a0f1a9 --- /dev/null +++ b/app/controllers/questions_controller.rb @@ -0,0 +1,85 @@ +class QuestionsController < ApplicationController + # GET /questions + # GET /questions.xml + def index + @questions = Question.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @questions } + end + end + + # GET /questions/1 + # GET /questions/1.xml + def show + @question = Question.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @question } + end + end + + # GET /questions/new + # GET /questions/new.xml + def new + @question = Question.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @question } + end + end + + # GET /questions/1/edit + def edit + @question = Question.find(params[:id]) + end + + # POST /questions + # POST /questions.xml + def create + @question = Question.new(params[:question]) + + respond_to do |format| + if @question.save + flash[:notice] = 'Question was successfully created.' + format.html { redirect_to(@question) } + format.xml { render :xml => @question, :status => :created, :location => @question } + else + format.html { render :action => "new" } + format.xml { render :xml => @question.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /questions/1 + # PUT /questions/1.xml + def update + @question = Question.find(params[:id]) + + respond_to do |format| + if @question.update_attributes(params[:question]) + flash[:notice] = 'Question was successfully updated.' + format.html { redirect_to(@question) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @question.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /questions/1 + # DELETE /questions/1.xml + def destroy + @question = Question.find(params[:id]) + @question.destroy + + respond_to do |format| + format.html { redirect_to(questions_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb new file mode 100644 index 0000000..40bb7f2 --- /dev/null +++ b/app/controllers/visitors_controller.rb @@ -0,0 +1,85 @@ +class VisitorsController < ApplicationController + # GET /visitors + # GET /visitors.xml + def index + @visitors = Visitor.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @visitors } + end + end + + # GET /visitors/1 + # GET /visitors/1.xml + def show + @visitor = Visitor.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @visitor } + end + end + + # GET /visitors/new + # GET /visitors/new.xml + def new + @visitor = Visitor.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @visitor } + end + end + + # GET /visitors/1/edit + def edit + @visitor = Visitor.find(params[:id]) + end + + # POST /visitors + # POST /visitors.xml + def create + @visitor = Visitor.new(params[:visitor]) + + respond_to do |format| + if @visitor.save + flash[:notice] = 'Visitor was successfully created.' + format.html { redirect_to(@visitor) } + format.xml { render :xml => @visitor, :status => :created, :location => @visitor } + else + format.html { render :action => "new" } + format.xml { render :xml => @visitor.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /visitors/1 + # PUT /visitors/1.xml + def update + @visitor = Visitor.find(params[:id]) + + respond_to do |format| + if @visitor.update_attributes(params[:visitor]) + flash[:notice] = 'Visitor was successfully updated.' + format.html { redirect_to(@visitor) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @visitor.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /visitors/1 + # DELETE /visitors/1.xml + def destroy + @visitor = Visitor.find(params[:id]) + @visitor.destroy + + respond_to do |format| + format.html { redirect_to(visitors_url) } + format.xml { head :ok } + end + end +end diff --git a/app/helpers/choices_helper.rb b/app/helpers/choices_helper.rb new file mode 100644 index 0000000..1864d12 --- /dev/null +++ b/app/helpers/choices_helper.rb @@ -0,0 +1,2 @@ +module ChoicesHelper +end diff --git a/app/helpers/clicks_helper.rb b/app/helpers/clicks_helper.rb new file mode 100644 index 0000000..96f77cf --- /dev/null +++ b/app/helpers/clicks_helper.rb @@ -0,0 +1,2 @@ +module ClicksHelper +end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb new file mode 100644 index 0000000..cff0c9f --- /dev/null +++ b/app/helpers/items_helper.rb @@ -0,0 +1,2 @@ +module ItemsHelper +end diff --git a/app/helpers/prompts_helper.rb b/app/helpers/prompts_helper.rb new file mode 100644 index 0000000..6ab8fce --- /dev/null +++ b/app/helpers/prompts_helper.rb @@ -0,0 +1,2 @@ +module PromptsHelper +end diff --git a/app/helpers/questions_helper.rb b/app/helpers/questions_helper.rb new file mode 100644 index 0000000..2eaab4a --- /dev/null +++ b/app/helpers/questions_helper.rb @@ -0,0 +1,2 @@ +module QuestionsHelper +end diff --git a/app/helpers/visitors_helper.rb b/app/helpers/visitors_helper.rb new file mode 100644 index 0000000..b64a7ae --- /dev/null +++ b/app/helpers/visitors_helper.rb @@ -0,0 +1,2 @@ +module VisitorsHelper +end diff --git a/app/models/choice.rb b/app/models/choice.rb new file mode 100644 index 0000000..fc2b281 --- /dev/null +++ b/app/models/choice.rb @@ -0,0 +1,30 @@ +class Choice < ActiveRecord::Base + belongs_to :question + belongs_to :item + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" + validates_presence_of :creator, :on => :create, :message => "can't be blank" + validates_presence_of :question, :on => :create, :message => "can't be blank" + has_many :votes, :as => :voteable + + attr_accessor :data + + + after_create :generate_prompts + def before_create + @item = Item.create!(:creator => creator, :data => data) + self.item = @item + end + + protected + + def generate_prompts + #once a choice is added, we need to generate the new prompts (possible combinations of choices) + #do this in a new process (via delayed jobs) + previous_choices = (self.question.choices - [self]) + return if previous_choices.empty? + for c in previous_choices + question.prompts.create!(:left_choice => c, :right_choice => self) + question.prompts.create!(:left_choice => self, :right_choice => c) + end + end +end diff --git a/app/models/click.rb b/app/models/click.rb new file mode 100644 index 0000000..0722777 --- /dev/null +++ b/app/models/click.rb @@ -0,0 +1,4 @@ +class Click < ActiveRecord::Base + belongs_to :site + belongs_to :visitor +end diff --git a/app/models/item.rb b/app/models/item.rb new file mode 100644 index 0000000..cc652c8 --- /dev/null +++ b/app/models/item.rb @@ -0,0 +1,16 @@ +class Item < ActiveRecord::Base + belongs_to :question, :counter_cache => true + belongs_to :site, :class_name => "User", :foreign_key => "site_id" + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" + + named_scope :active, :conditions => { :active => true } + + # has_many :items_questions, :dependent => :destroy + # has_many :questions, :through => :items_questions + # has_and_belongs_to_many :prompts + # + # has_and_belongs_to_many :votes + # has_and_belongs_to_many :prompt_requests + + validates_presence_of :creator_id +end diff --git a/app/models/prompt.rb b/app/models/prompt.rb new file mode 100644 index 0000000..720d96a --- /dev/null +++ b/app/models/prompt.rb @@ -0,0 +1,54 @@ +class Prompt < ActiveRecord::Base + #has_many :choices, :order => 'position DESC' + + has_many :skips + has_many :votes, :as => :voteable + + + belongs_to :question + belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id" + belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id" + + named_scope :with_left_choice, lambda { |*args| {:conditions => ["left_choice_id = ?", (args.first.id)]} } + named_scope :with_right_choice, lambda { |*args| {:conditions => ["right_choice_id = ?", (args.first.id)]} } + named_scope :with_choice, lambda { |*args| {:conditions => ["(right_choice_id = ?) OR (left_choice_id = ?)", (args.first.id)]} } + named_scope :with_choice_id, lambda { |*args| {:conditions => ["(right_choice_id = ?) OR (left_choice_id = ?)", (args.first)]} } + #named_scope :voted_on_by, :include => :choices, :conditions => + #named_scope :voted_on_by, proc {|u| { :conditions => { :methodology => methodology } } } + + def self.voted_on_by(u) + select {|z| z.voted_on_by_user?(u)} + end + + + named_scope :visible, :include => :category, :conditions => { 'categories.hidden' => false } + + validates_presence_of :left_choice, :on => :create, :message => "can't be blank" + validates_presence_of :right_choice, :on => :create, :message => "can't be blank" + + def choices + [left_choice, right_choice] + end + + def voted_on_by_user?(u) + u.voted_for?(left_choice) || u.voted_for?(right_choice) + end + + def left_choice_text(prompt = nil) + left_choice.item.data + end + + def left_choice_id + left_choice.id + end + + def right_choice_id + right_choice.id + end + + + def right_choice_text(prompt = nil) + right_choice.item.data + end + +end diff --git a/app/models/question.rb b/app/models/question.rb new file mode 100644 index 0000000..5e3cb0d --- /dev/null +++ b/app/models/question.rb @@ -0,0 +1,33 @@ +class Question < ActiveRecord::Base + belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" + belongs_to :site, :class_name => "User", :foreign_key => "site_id" + + has_many :choices + has_many :prompts do + def pick(algorithm = nil) + if algorithm + algorithm.pick_from(self) #todo + else + lambda {prompts[rand(prompts.size-1)]}.call + end + end + end + after_save :ensure_at_least_two_choices + + validates_presence_of :site, :on => :create, :message => "can't be blank" + validates_presence_of :creator, :on => :create, :message => "can't be blank" + + def ensure_at_least_two_choices + if self.choices.empty? + ["sample choice 1", "sample choice 2"].each { |choice_text| + item = Item.create!({:data => choice_text, :creator => creator}) + puts item.inspect + choice = choices.create!(:item => item, :creator => creator) + puts choice.inspect + } + end + end + +end +#@site = User.create!(:email => 'pius+7@alum.mit.edu', :password => 'password', :password_confirmation => 'password') +#@site.questions.create!(:name => 'what do you want?', :creator => @site.default_visitor) diff --git a/app/models/skip.rb b/app/models/skip.rb new file mode 100644 index 0000000..dcfc65d --- /dev/null +++ b/app/models/skip.rb @@ -0,0 +1,4 @@ +class Skip < ActiveRecord::Base + belongs_to :skipper, :class_name => "Visitor", :foreign_key => "skipper_id" + belongs_to :prompt, :class_name => "Prompt", :foreign_key => "prompt_id" +end diff --git a/app/models/user.rb b/app/models/user.rb index 6d077a1..2524583 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,67 @@ class User < ActiveRecord::Base include Clearance::User + has_many :visitors, :class_name => "Visitor", :foreign_key => "site_id" + has_many :questions, :class_name => "Question", :foreign_key => "site_id" + has_many :clicks, :class_name => "Click", :foreign_key => "site_id" + + def default_visitor + visitors.find(:first, :conditions => {:identifier => 'owner'}) + end + + def create_question(visitor_identifier, question_params) + visitor = visitors.find_or_create_by_identifier(visitor_identifier) + question = visitor.questions.create(question_params.merge(:site => self)) + end + + def create_choice(visitor_identifier, question, choice_params) + visitor = visitors.find_or_create_by_identifier(visitor_identifier) + raise "Question not found" if question.nil? + if visitor.owns?(question) + choice = question.choices.create(choice_params.merge(:active => true)) + else + choice = question.choices.create(choice_params.merge(:active => false)) + end + notify_question_owner_that_new_choice_has_been_added(choice) + end + + def record_vote(visitor_identifier, prompt, ordinality) + visitor = visitors.find_or_create_by_identifier(visitor_identifier) + visitor.vote_for!(prompt, ordinality) + end + + def record_skip(visitor_identifier, prompt) + visitor = visitors.find_or_create_by_identifier(visitor_identifier) + question = prompt.question + visitor.skip!(prompt) + end + + def activate_question(question_id, options) + question = questions.find(question_id) + question.activate! + end + + def activate_choice(choice_id, options) + choice = Choice.find(choice_id) + choice.activate! + end + + def deactivate_choice(choice_id, options) + choice = Choice.find(choice_id) + choice.deactivate! + end + + def deactivate_question(question_id, options) + question = questions.find(question_id) + question.deactivate! + end + + def after_create + visitors.create!(:site => self, :identifier => 'owner') + end + + private + + def notify_question_owner_that_new_choice_has_been_added(choice) + #ChoiceNotifier.deliver_notification(choice) #this may be the responsibility of the client + end end diff --git a/app/models/visitor.rb b/app/models/visitor.rb new file mode 100644 index 0000000..9fcd1f6 --- /dev/null +++ b/app/models/visitor.rb @@ -0,0 +1,23 @@ +class Visitor < ActiveRecord::Base + belongs_to :site, :class_name => "User", :foreign_key => "site_id" + has_many :questions, :class_name => "Question", :foreign_key => "creator_id" + has_many :votes, :class_name => "Vote", :foreign_key => "voter_id" + has_many :skips, :class_name => "Skip", :foreign_key => "skipper_id" + has_many :clicks + validates_presence_of :site, :on => :create, :message => "can't be blank" + validates_uniqueness_of :identifier, :on => :create, :message => "must be unique", :scope => :site_id + + def owns?(question) + questions.include? question + end + + def vote_for!(prompt, ordinality) + choice = prompt.choices[ordinality] #we need to guarantee that the choices are in the right order (by position) + prompt_vote = votes.create!(:voteable => prompt) + choice_vote = votes.create!(:voteable => choice) + end + + def skip!(prompt) + prompt_skip = skips.create!(:prompt => prompt) + end +end diff --git a/app/models/vote.rb b/app/models/vote.rb new file mode 100644 index 0000000..049c65d --- /dev/null +++ b/app/models/vote.rb @@ -0,0 +1,4 @@ +class Vote < ActiveRecord::Base + belongs_to :voteable, :polymorphic => true + belongs_to :voter, :class_name => "Visitor", :foreign_key => "voter_id" +end diff --git a/app/views/choices/edit.html.erb b/app/views/choices/edit.html.erb new file mode 100644 index 0000000..6a94a61 --- /dev/null +++ b/app/views/choices/edit.html.erb @@ -0,0 +1,12 @@ +

Editing choice

+ +<% form_for(@choice) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @choice %> | +<%= link_to 'Back', choices_path %> \ No newline at end of file diff --git a/app/views/choices/index.html.erb b/app/views/choices/index.html.erb new file mode 100644 index 0000000..99fffba --- /dev/null +++ b/app/views/choices/index.html.erb @@ -0,0 +1,18 @@ +

Listing choices

+ + + + + +<% @choices.each do |choice| %> + + + + + +<% end %> +
<%= link_to 'Show', choice %><%= link_to 'Edit', edit_choice_path(choice) %><%= link_to 'Destroy', choice, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New choice', new_choice_path %> \ No newline at end of file diff --git a/app/views/choices/new.html.erb b/app/views/choices/new.html.erb new file mode 100644 index 0000000..8e5b335 --- /dev/null +++ b/app/views/choices/new.html.erb @@ -0,0 +1,11 @@ +

New choice

+ +<% form_for(@choice) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', choices_path %> \ No newline at end of file diff --git a/app/views/choices/show.html.erb b/app/views/choices/show.html.erb new file mode 100644 index 0000000..4170c7e --- /dev/null +++ b/app/views/choices/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_choice_path(@choice) %> | +<%= link_to 'Back', choices_path %> \ No newline at end of file diff --git a/app/views/clicks/edit.html.erb b/app/views/clicks/edit.html.erb new file mode 100644 index 0000000..dbfb66b --- /dev/null +++ b/app/views/clicks/edit.html.erb @@ -0,0 +1,24 @@ +

Editing click

+ +<% form_for(@click) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :site_id %>
+ <%= f.text_field :site_id %> +

+

+ <%= f.label :visitor_id %>
+ <%= f.text_field :visitor_id %> +

+

+ <%= f.label :additional_info %>
+ <%= f.text_area :additional_info %> +

+

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @click %> | +<%= link_to 'Back', clicks_path %> \ No newline at end of file diff --git a/app/views/clicks/index.html.erb b/app/views/clicks/index.html.erb new file mode 100644 index 0000000..da9bfc2 --- /dev/null +++ b/app/views/clicks/index.html.erb @@ -0,0 +1,24 @@ +

Listing clicks

+ + + + + + + + +<% @clicks.each do |click| %> + + + + + + + + +<% end %> +
SiteVisitorAdditional info
<%=h click.site_id %><%=h click.visitor_id %><%=h click.additional_info %><%= link_to 'Show', click %><%= link_to 'Edit', edit_click_path(click) %><%= link_to 'Destroy', click, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New click', new_click_path %> \ No newline at end of file diff --git a/app/views/clicks/new.html.erb b/app/views/clicks/new.html.erb new file mode 100644 index 0000000..ba82731 --- /dev/null +++ b/app/views/clicks/new.html.erb @@ -0,0 +1,23 @@ +

New click

+ +<% form_for(@click) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :site_id %>
+ <%= f.text_field :site_id %> +

+

+ <%= f.label :visitor_id %>
+ <%= f.text_field :visitor_id %> +

+

+ <%= f.label :additional_info %>
+ <%= f.text_area :additional_info %> +

+

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', clicks_path %> \ No newline at end of file diff --git a/app/views/clicks/show.html.erb b/app/views/clicks/show.html.erb new file mode 100644 index 0000000..e829b24 --- /dev/null +++ b/app/views/clicks/show.html.erb @@ -0,0 +1,18 @@ +

+ Site: + <%=h @click.site_id %> +

+ +

+ Visitor: + <%=h @click.visitor_id %> +

+ +

+ Additional info: + <%=h @click.additional_info %> +

+ + +<%= link_to 'Edit', edit_click_path(@click) %> | +<%= link_to 'Back', clicks_path %> \ No newline at end of file diff --git a/app/views/items/edit.html.erb b/app/views/items/edit.html.erb new file mode 100644 index 0000000..0f96ad0 --- /dev/null +++ b/app/views/items/edit.html.erb @@ -0,0 +1,12 @@ +

Editing item

+ +<% form_for(@item) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @item %> | +<%= link_to 'Back', items_path %> \ No newline at end of file diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb new file mode 100644 index 0000000..61cf6ab --- /dev/null +++ b/app/views/items/index.html.erb @@ -0,0 +1,18 @@ +

Listing items

+ + + + + +<% @items.each do |item| %> + + + + + +<% end %> +
<%= link_to 'Show', item %><%= link_to 'Edit', edit_item_path(item) %><%= link_to 'Destroy', item, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New item', new_item_path %> \ No newline at end of file diff --git a/app/views/items/new.html.erb b/app/views/items/new.html.erb new file mode 100644 index 0000000..369564c --- /dev/null +++ b/app/views/items/new.html.erb @@ -0,0 +1,11 @@ +

New item

+ +<% form_for(@item) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', items_path %> \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb new file mode 100644 index 0000000..7305cd8 --- /dev/null +++ b/app/views/items/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_item_path(@item) %> | +<%= link_to 'Back', items_path %> \ No newline at end of file diff --git a/app/views/layouts/choices.html.erb b/app/views/layouts/choices.html.erb new file mode 100644 index 0000000..f741f53 --- /dev/null +++ b/app/views/layouts/choices.html.erb @@ -0,0 +1,17 @@ + + + + + + Choices: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/layouts/clicks.html.erb b/app/views/layouts/clicks.html.erb new file mode 100644 index 0000000..ca1ca3c --- /dev/null +++ b/app/views/layouts/clicks.html.erb @@ -0,0 +1,17 @@ + + + + + + Clicks: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/layouts/items.html.erb b/app/views/layouts/items.html.erb new file mode 100644 index 0000000..0624b95 --- /dev/null +++ b/app/views/layouts/items.html.erb @@ -0,0 +1,17 @@ + + + + + + Items: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/layouts/prompts.html.erb b/app/views/layouts/prompts.html.erb new file mode 100644 index 0000000..cf69d5e --- /dev/null +++ b/app/views/layouts/prompts.html.erb @@ -0,0 +1,17 @@ + + + + + + Prompts: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/layouts/questions.html.erb b/app/views/layouts/questions.html.erb new file mode 100644 index 0000000..4f12199 --- /dev/null +++ b/app/views/layouts/questions.html.erb @@ -0,0 +1,17 @@ + + + + + + Questions: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/layouts/visitors.html.erb b/app/views/layouts/visitors.html.erb new file mode 100644 index 0000000..db4881f --- /dev/null +++ b/app/views/layouts/visitors.html.erb @@ -0,0 +1,17 @@ + + + + + + Visitors: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/prompts/edit.html.erb b/app/views/prompts/edit.html.erb new file mode 100644 index 0000000..ea187f8 --- /dev/null +++ b/app/views/prompts/edit.html.erb @@ -0,0 +1,12 @@ +

Editing prompt

+ +<% form_for(@prompt) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @prompt %> | +<%= link_to 'Back', prompts_path %> \ No newline at end of file diff --git a/app/views/prompts/index.html.erb b/app/views/prompts/index.html.erb new file mode 100644 index 0000000..1aa0aba --- /dev/null +++ b/app/views/prompts/index.html.erb @@ -0,0 +1,18 @@ +

Listing prompts

+ + + + + +<% @prompts.each do |prompt| %> + + + + + +<% end %> +
<%= link_to 'Show', prompt %><%= link_to 'Edit', edit_prompt_path(prompt) %><%= link_to 'Destroy', prompt, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New prompt', new_prompt_path %> \ No newline at end of file diff --git a/app/views/prompts/new.html.erb b/app/views/prompts/new.html.erb new file mode 100644 index 0000000..ff32bdb --- /dev/null +++ b/app/views/prompts/new.html.erb @@ -0,0 +1,11 @@ +

New prompt

+ +<% form_for(@prompt) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', prompts_path %> \ No newline at end of file diff --git a/app/views/prompts/show.html.erb b/app/views/prompts/show.html.erb new file mode 100644 index 0000000..24309af --- /dev/null +++ b/app/views/prompts/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_prompt_path(@prompt) %> | +<%= link_to 'Back', prompts_path %> \ No newline at end of file diff --git a/app/views/questions/edit.html.erb b/app/views/questions/edit.html.erb new file mode 100644 index 0000000..5bababb --- /dev/null +++ b/app/views/questions/edit.html.erb @@ -0,0 +1,12 @@ +

Editing question

+ +<% form_for(@question) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @question %> | +<%= link_to 'Back', questions_path %> \ No newline at end of file diff --git a/app/views/questions/index.html.erb b/app/views/questions/index.html.erb new file mode 100644 index 0000000..6fdb828 --- /dev/null +++ b/app/views/questions/index.html.erb @@ -0,0 +1,18 @@ +

Listing questions

+ + + + + +<% @questions.each do |question| %> + + + + + +<% end %> +
<%= link_to 'Show', question %><%= link_to 'Edit', edit_question_path(question) %><%= link_to 'Destroy', question, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New question', new_question_path %> \ No newline at end of file diff --git a/app/views/questions/new.html.erb b/app/views/questions/new.html.erb new file mode 100644 index 0000000..f8d556e --- /dev/null +++ b/app/views/questions/new.html.erb @@ -0,0 +1,11 @@ +

New question

+ +<% form_for(@question) do |f| %> + <%= f.error_messages %> + +

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', questions_path %> \ No newline at end of file diff --git a/app/views/questions/show.html.erb b/app/views/questions/show.html.erb new file mode 100644 index 0000000..1c55293 --- /dev/null +++ b/app/views/questions/show.html.erb @@ -0,0 +1,3 @@ + +<%= link_to 'Edit', edit_question_path(@question) %> | +<%= link_to 'Back', questions_path %> \ No newline at end of file diff --git a/app/views/visitors/edit.html.erb b/app/views/visitors/edit.html.erb new file mode 100644 index 0000000..b7c9ca4 --- /dev/null +++ b/app/views/visitors/edit.html.erb @@ -0,0 +1,24 @@ +

Editing visitor

+ +<% form_for(@visitor) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :site_id %>
+ <%= f.text_field :site_id %> +

+

+ <%= f.label :identifier %>
+ <%= f.text_field :identifier %> +

+

+ <%= f.label :tracking %>
+ <%= f.text_area :tracking %> +

+

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @visitor %> | +<%= link_to 'Back', visitors_path %> \ No newline at end of file diff --git a/app/views/visitors/index.html.erb b/app/views/visitors/index.html.erb new file mode 100644 index 0000000..f194574 --- /dev/null +++ b/app/views/visitors/index.html.erb @@ -0,0 +1,24 @@ +

Listing visitors

+ + + + + + + + +<% @visitors.each do |visitor| %> + + + + + + + + +<% end %> +
SiteIdentifierTracking
<%=h visitor.site_id %><%=h visitor.identifier %><%=h visitor.tracking %><%= link_to 'Show', visitor %><%= link_to 'Edit', edit_visitor_path(visitor) %><%= link_to 'Destroy', visitor, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New visitor', new_visitor_path %> \ No newline at end of file diff --git a/app/views/visitors/new.html.erb b/app/views/visitors/new.html.erb new file mode 100644 index 0000000..6a0a7fc --- /dev/null +++ b/app/views/visitors/new.html.erb @@ -0,0 +1,23 @@ +

New visitor

+ +<% form_for(@visitor) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :site_id %>
+ <%= f.text_field :site_id %> +

+

+ <%= f.label :identifier %>
+ <%= f.text_field :identifier %> +

+

+ <%= f.label :tracking %>
+ <%= f.text_area :tracking %> +

+

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', visitors_path %> \ No newline at end of file diff --git a/app/views/visitors/show.html.erb b/app/views/visitors/show.html.erb new file mode 100644 index 0000000..6fbf37c --- /dev/null +++ b/app/views/visitors/show.html.erb @@ -0,0 +1,18 @@ +

+ Site: + <%=h @visitor.site_id %> +

+ +

+ Identifier: + <%=h @visitor.identifier %> +

+ +

+ Tracking: + <%=h @visitor.tracking %> +

+ + +<%= link_to 'Edit', edit_visitor_path(@visitor) %> | +<%= link_to 'Back', visitors_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2efd20e..ce351f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,16 @@ ActionController::Routing::Routes.draw do |map| + map.resources :clicks + + map.resources :prompts + + map.resources :items + + map.resources :choices + + map.resources :visitors + + map.resources :questions + map.root :controller => "clearance/sessions", :action => "new" # rake routes diff --git a/db/migrate/20091203161430_create_questions.rb b/db/migrate/20091203161430_create_questions.rb new file mode 100644 index 0000000..a944ec4 --- /dev/null +++ b/db/migrate/20091203161430_create_questions.rb @@ -0,0 +1,23 @@ +class CreateQuestions < ActiveRecord::Migration + def self.up + create_table "questions", :force => true do |t| + t.integer "creator_id" + t.string "name", :default => "" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "items_count", :default => 0 + t.integer "active_items_count", :default => 0 + t.integer "choices_count", :default => 0 + t.integer "prompts_count", :default => 0 + t.boolean "active", :default => false + t.text "tracking" + t.integer "first_prompt_algorithm_id" + t.text "information" + end + + end + + def self.down + drop_table :questions + end +end diff --git a/db/migrate/20091203163251_create_visitors.rb b/db/migrate/20091203163251_create_visitors.rb new file mode 100644 index 0000000..8410555 --- /dev/null +++ b/db/migrate/20091203163251_create_visitors.rb @@ -0,0 +1,17 @@ +class CreateVisitors < ActiveRecord::Migration + def self.up + create_table :visitors do |table| + table.integer :site_id + table.string :identifier, :default => "" + table.text :tracking + table.boolean :activated + table.integer :user_id + table.timestamps + end + + end + + def self.down + drop_table :visitors + end +end diff --git a/db/migrate/20091203164109_create_choices.rb b/db/migrate/20091203164109_create_choices.rb new file mode 100644 index 0000000..99bdf8b --- /dev/null +++ b/db/migrate/20091203164109_create_choices.rb @@ -0,0 +1,24 @@ +class CreateChoices < ActiveRecord::Migration + def self.up + create_table "choices", :force => true do |t| + t.integer "item_id" + t.integer "question_id" + t.integer "position" + t.integer "wins" + t.integer "ratings" + t.integer "losses" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "request_id" + t.integer "prompt_id" + t.boolean "active", :default => false + t.text "tracking" + t.float "score" + end + + end + + def self.down + drop_table :choices + end +end diff --git a/db/migrate/20091203165033_create_items.rb b/db/migrate/20091203165033_create_items.rb new file mode 100644 index 0000000..c8da2c7 --- /dev/null +++ b/db/migrate/20091203165033_create_items.rb @@ -0,0 +1,19 @@ +class CreateItems < ActiveRecord::Migration + def self.up + create_table "items", :force => true do |t| + t.text "data" + t.boolean "active" + t.text "tracking" + t.integer "creator_id" + t.integer "voter_id" + t.integer "site_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + end + + def self.down + drop_table :items + end +end diff --git a/db/migrate/20091203170231_add_site_id_to_questions.rb b/db/migrate/20091203170231_add_site_id_to_questions.rb new file mode 100644 index 0000000..14f0133 --- /dev/null +++ b/db/migrate/20091203170231_add_site_id_to_questions.rb @@ -0,0 +1,9 @@ +class AddSiteIdToQuestions < ActiveRecord::Migration + def self.up + add_column :questions, :site_id, :integer + end + + def self.down + remove_column :questions, :site_id + end +end diff --git a/db/migrate/20091203173153_create_prompts.rb b/db/migrate/20091203173153_create_prompts.rb new file mode 100644 index 0000000..b58b69f --- /dev/null +++ b/db/migrate/20091203173153_create_prompts.rb @@ -0,0 +1,20 @@ +class CreatePrompts < ActiveRecord::Migration + def self.up + create_table "prompts", :force => true do |t| + t.integer "algorithm_id" + t.integer "question_id" + t.integer "left_choice_id" + t.integer "right_choice_id" + t.integer "voter_id" + t.boolean "active" + t.datetime "created_at" + t.datetime "updated_at" + t.text "tracking" + end + + end + + def self.down + drop_table :prompts + end +end diff --git a/db/migrate/20091203175954_create_votes.rb b/db/migrate/20091203175954_create_votes.rb new file mode 100644 index 0000000..220af31 --- /dev/null +++ b/db/migrate/20091203175954_create_votes.rb @@ -0,0 +1,17 @@ +class CreateVotes < ActiveRecord::Migration + def self.up + create_table :votes do |table| + table.text :tracking + table.integer :site_id + table.integer :voter_id + table.integer :voteable_id + table.string :voteable_type, :default => "" + table.timestamps + end + + end + + def self.down + drop_table :votes + end +end diff --git a/db/migrate/20091203185050_create_skips.rb b/db/migrate/20091203185050_create_skips.rb new file mode 100644 index 0000000..fe2ed76 --- /dev/null +++ b/db/migrate/20091203185050_create_skips.rb @@ -0,0 +1,16 @@ +class CreateSkips < ActiveRecord::Migration + def self.up + create_table "skips", :force => true do |t| + t.integer "skipper_id" + t.integer "prompt_id" + t.text "tracking" + t.datetime "created_at" + t.datetime "updated_at" + end + + end + + def self.down + drop_table :skips + end +end diff --git a/db/migrate/20091203190244_create_clicks.rb b/db/migrate/20091203190244_create_clicks.rb new file mode 100644 index 0000000..72ee9c4 --- /dev/null +++ b/db/migrate/20091203190244_create_clicks.rb @@ -0,0 +1,15 @@ +class CreateClicks < ActiveRecord::Migration + def self.up + create_table :clicks do |table| + table.integer :site_id + table.integer :visitor_id + table.text :additional_info + table.timestamps + end + + end + + def self.down + drop_table :clicks + end +end diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake new file mode 100644 index 0000000..bcef18e --- /dev/null +++ b/lib/tasks/rspec.rake @@ -0,0 +1,182 @@ +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 +rspec_gem_dir = nil +Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| + rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") +end +rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') + +if rspec_gem_dir && (test ?d, rspec_plugin_dir) + 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" +end + +if rspec_gem_dir + $LOAD_PATH.unshift("#{rspec_gem_dir}/lib") +elsif File.exist?(rspec_plugin_dir) + $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") +end + +# Don't load rspec if running "rake gems:*" +unless ARGV.any? {|a| a =~ /^gems/} + +begin + require 'spec/rake/spectask' +rescue MissingSourceFile + module Spec + module Rake + class SpecTask + def initialize(name) + task name do + # if rspec-rails is a configured gem, this will output helpful material and exit ... + require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") + + # ... otherwise, do this: + raise <<-MSG + +#{"*" * 80} +* You are trying to run an rspec rake task defined in +* #{__FILE__}, +* but rspec can not be found in vendor/gems, vendor/plugins or system gems. +#{"*" * 80} +MSG + end + end + end + end + end +end + +Rake.application.instance_variable_get('@tasks').delete('default') + +spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop +task :noop do +end + +task :default => :spec +task :stats => "spec:statsetup" + +desc "Run all specs in spec directory (excluding plugin specs)" +Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] +end + +namespace :spec do + desc "Run all specs in spec directory with RCov (excluding plugin specs)" + Spec::Rake::SpecTask.new(:rcov) do |t| + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = lambda do + IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + end + end + + desc "Print Specdoc for all specs (excluding plugin specs)" + Spec::Rake::SpecTask.new(:doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end + + desc "Print Specdoc for all plugin examples" + Spec::Rake::SpecTask.new(:plugin_doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*') + end + + [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| + desc "Run the code examples in spec/#{sub}" + Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + end + end + + desc "Run the code examples in vendor/plugins (except RSpec's own)" + Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") + end + + namespace :plugins do + desc "Runs the examples for rspec_on_rails" + Spec::Rake::SpecTask.new(:rspec_on_rails) do |t| + t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb'] + end + end + + # Setup specs for stats + task :statsetup do + require 'code_statistics' + ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models') + ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views') + ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers') + ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') + ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib') + ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing') + ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration') + ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') + ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') + ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers') + ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') + ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib') + ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing') + ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration') + end + + namespace :db do + namespace :fixtures do + 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." + task :load => :environment do + ActiveRecord::Base.establish_connection(Rails.env) + base_dir = File.join(Rails.root, 'spec', 'fixtures') + fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir + + require 'active_record/fixtures' + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file| + Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) + end + end + end + end + + namespace :server do + daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid") + + desc "start spec_server." + task :start do + if File.exist?(daemonized_server_pid) + $stderr.puts "spec_server is already running." + else + $stderr.puts %Q{Starting up spec_server ...} + FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids' + system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid) + end + end + + desc "stop spec_server." + task :stop do + unless File.exist?(daemonized_server_pid) + $stderr.puts "No server running." + else + $stderr.puts "Shutting down spec_server ..." + system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) && + File.delete(daemonized_server_pid) + end + end + + desc "restart spec_server." + task :restart => [:stop, :start] + + desc "check if spec server is running" + task :status do + if File.exist?(daemonized_server_pid) + $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})} + else + $stderr.puts "No server running." + end + end + end +end + +end diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css new file mode 100644 index 0000000..093c209 --- /dev/null +++ b/public/stylesheets/scaffold.css @@ -0,0 +1,54 @@ +body { background-color: #fff; color: #333; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { color: #000; } +a:visited { color: #666; } +a:hover { color: #fff; background-color:#000; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + diff --git a/script/autospec b/script/autospec new file mode 100755 index 0000000..837bbd7 --- /dev/null +++ b/script/autospec @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 +ENV['RSPEC'] = 'true' # allows autotest to discover rspec +ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux +system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) || + $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH") diff --git a/script/spec b/script/spec new file mode 100755 index 0000000..46fdbe6 --- /dev/null +++ b/script/spec @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} + require 'rubygems' unless ENV['NO_RUBYGEMS'] +else + gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 + ENV["RAILS_ENV"] ||= 'test' + require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) +end +require 'spec/autorun' +exit ::Spec::Runner::CommandLine.run diff --git a/script/spec_server b/script/spec_server new file mode 100755 index 0000000..941fc9d --- /dev/null +++ b/script/spec_server @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 + +puts "Loading Rails environment" +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) + +require 'optparse' +require 'spec/rails/spec_server' diff --git a/spec/controllers/choices_controller_spec.rb b/spec/controllers/choices_controller_spec.rb new file mode 100644 index 0000000..135c310 --- /dev/null +++ b/spec/controllers/choices_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ChoicesController do + + def mock_choice(stubs={}) + @mock_choice ||= mock_model(Choice, stubs) + end + + describe "GET index" do + it "assigns all choices as @choices" do + Choice.stub!(:find).with(:all).and_return([mock_choice]) + get :index + assigns[:choices].should == [mock_choice] + end + end + + describe "GET show" do + it "assigns the requested choice as @choice" do + Choice.stub!(:find).with("37").and_return(mock_choice) + get :show, :id => "37" + assigns[:choice].should equal(mock_choice) + end + end + + describe "GET new" do + it "assigns a new choice as @choice" do + Choice.stub!(:new).and_return(mock_choice) + get :new + assigns[:choice].should equal(mock_choice) + end + end + + describe "GET edit" do + it "assigns the requested choice as @choice" do + Choice.stub!(:find).with("37").and_return(mock_choice) + get :edit, :id => "37" + assigns[:choice].should equal(mock_choice) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created choice as @choice" do + Choice.stub!(:new).with({'these' => 'params'}).and_return(mock_choice(:save => true)) + post :create, :choice => {:these => 'params'} + assigns[:choice].should equal(mock_choice) + end + + it "redirects to the created choice" do + Choice.stub!(:new).and_return(mock_choice(:save => true)) + post :create, :choice => {} + response.should redirect_to(choice_url(mock_choice)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved choice as @choice" do + Choice.stub!(:new).with({'these' => 'params'}).and_return(mock_choice(:save => false)) + post :create, :choice => {:these => 'params'} + assigns[:choice].should equal(mock_choice) + end + + it "re-renders the 'new' template" do + Choice.stub!(:new).and_return(mock_choice(:save => false)) + post :create, :choice => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested choice" do + Choice.should_receive(:find).with("37").and_return(mock_choice) + mock_choice.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :choice => {:these => 'params'} + end + + it "assigns the requested choice as @choice" do + Choice.stub!(:find).and_return(mock_choice(:update_attributes => true)) + put :update, :id => "1" + assigns[:choice].should equal(mock_choice) + end + + it "redirects to the choice" do + Choice.stub!(:find).and_return(mock_choice(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(choice_url(mock_choice)) + end + end + + describe "with invalid params" do + it "updates the requested choice" do + Choice.should_receive(:find).with("37").and_return(mock_choice) + mock_choice.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :choice => {:these => 'params'} + end + + it "assigns the choice as @choice" do + Choice.stub!(:find).and_return(mock_choice(:update_attributes => false)) + put :update, :id => "1" + assigns[:choice].should equal(mock_choice) + end + + it "re-renders the 'edit' template" do + Choice.stub!(:find).and_return(mock_choice(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested choice" do + Choice.should_receive(:find).with("37").and_return(mock_choice) + mock_choice.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the choices list" do + Choice.stub!(:find).and_return(mock_choice(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(choices_url) + end + end + +end diff --git a/spec/controllers/clicks_controller_spec.rb b/spec/controllers/clicks_controller_spec.rb new file mode 100644 index 0000000..48233b4 --- /dev/null +++ b/spec/controllers/clicks_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ClicksController do + + def mock_click(stubs={}) + @mock_click ||= mock_model(Click, stubs) + end + + describe "GET index" do + it "assigns all clicks as @clicks" do + Click.stub!(:find).with(:all).and_return([mock_click]) + get :index + assigns[:clicks].should == [mock_click] + end + end + + describe "GET show" do + it "assigns the requested click as @click" do + Click.stub!(:find).with("37").and_return(mock_click) + get :show, :id => "37" + assigns[:click].should equal(mock_click) + end + end + + describe "GET new" do + it "assigns a new click as @click" do + Click.stub!(:new).and_return(mock_click) + get :new + assigns[:click].should equal(mock_click) + end + end + + describe "GET edit" do + it "assigns the requested click as @click" do + Click.stub!(:find).with("37").and_return(mock_click) + get :edit, :id => "37" + assigns[:click].should equal(mock_click) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created click as @click" do + Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => true)) + post :create, :click => {:these => 'params'} + assigns[:click].should equal(mock_click) + end + + it "redirects to the created click" do + Click.stub!(:new).and_return(mock_click(:save => true)) + post :create, :click => {} + response.should redirect_to(click_url(mock_click)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved click as @click" do + Click.stub!(:new).with({'these' => 'params'}).and_return(mock_click(:save => false)) + post :create, :click => {:these => 'params'} + assigns[:click].should equal(mock_click) + end + + it "re-renders the 'new' template" do + Click.stub!(:new).and_return(mock_click(:save => false)) + post :create, :click => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested click" do + Click.should_receive(:find).with("37").and_return(mock_click) + mock_click.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :click => {:these => 'params'} + end + + it "assigns the requested click as @click" do + Click.stub!(:find).and_return(mock_click(:update_attributes => true)) + put :update, :id => "1" + assigns[:click].should equal(mock_click) + end + + it "redirects to the click" do + Click.stub!(:find).and_return(mock_click(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(click_url(mock_click)) + end + end + + describe "with invalid params" do + it "updates the requested click" do + Click.should_receive(:find).with("37").and_return(mock_click) + mock_click.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :click => {:these => 'params'} + end + + it "assigns the click as @click" do + Click.stub!(:find).and_return(mock_click(:update_attributes => false)) + put :update, :id => "1" + assigns[:click].should equal(mock_click) + end + + it "re-renders the 'edit' template" do + Click.stub!(:find).and_return(mock_click(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested click" do + Click.should_receive(:find).with("37").and_return(mock_click) + mock_click.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the clicks list" do + Click.stub!(:find).and_return(mock_click(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(clicks_url) + end + end + +end diff --git a/spec/controllers/items_controller_spec.rb b/spec/controllers/items_controller_spec.rb new file mode 100644 index 0000000..31096fe --- /dev/null +++ b/spec/controllers/items_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ItemsController do + + def mock_item(stubs={}) + @mock_item ||= mock_model(Item, stubs) + end + + describe "GET index" do + it "assigns all items as @items" do + Item.stub!(:find).with(:all).and_return([mock_item]) + get :index + assigns[:items].should == [mock_item] + end + end + + describe "GET show" do + it "assigns the requested item as @item" do + Item.stub!(:find).with("37").and_return(mock_item) + get :show, :id => "37" + assigns[:item].should equal(mock_item) + end + end + + describe "GET new" do + it "assigns a new item as @item" do + Item.stub!(:new).and_return(mock_item) + get :new + assigns[:item].should equal(mock_item) + end + end + + describe "GET edit" do + it "assigns the requested item as @item" do + Item.stub!(:find).with("37").and_return(mock_item) + get :edit, :id => "37" + assigns[:item].should equal(mock_item) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created item as @item" do + Item.stub!(:new).with({'these' => 'params'}).and_return(mock_item(:save => true)) + post :create, :item => {:these => 'params'} + assigns[:item].should equal(mock_item) + end + + it "redirects to the created item" do + Item.stub!(:new).and_return(mock_item(:save => true)) + post :create, :item => {} + response.should redirect_to(item_url(mock_item)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved item as @item" do + Item.stub!(:new).with({'these' => 'params'}).and_return(mock_item(:save => false)) + post :create, :item => {:these => 'params'} + assigns[:item].should equal(mock_item) + end + + it "re-renders the 'new' template" do + Item.stub!(:new).and_return(mock_item(:save => false)) + post :create, :item => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested item" do + Item.should_receive(:find).with("37").and_return(mock_item) + mock_item.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :item => {:these => 'params'} + end + + it "assigns the requested item as @item" do + Item.stub!(:find).and_return(mock_item(:update_attributes => true)) + put :update, :id => "1" + assigns[:item].should equal(mock_item) + end + + it "redirects to the item" do + Item.stub!(:find).and_return(mock_item(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(item_url(mock_item)) + end + end + + describe "with invalid params" do + it "updates the requested item" do + Item.should_receive(:find).with("37").and_return(mock_item) + mock_item.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :item => {:these => 'params'} + end + + it "assigns the item as @item" do + Item.stub!(:find).and_return(mock_item(:update_attributes => false)) + put :update, :id => "1" + assigns[:item].should equal(mock_item) + end + + it "re-renders the 'edit' template" do + Item.stub!(:find).and_return(mock_item(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested item" do + Item.should_receive(:find).with("37").and_return(mock_item) + mock_item.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the items list" do + Item.stub!(:find).and_return(mock_item(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(items_url) + end + end + +end diff --git a/spec/controllers/prompts_controller_spec.rb b/spec/controllers/prompts_controller_spec.rb new file mode 100644 index 0000000..6ef9834 --- /dev/null +++ b/spec/controllers/prompts_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe PromptsController do + + def mock_prompt(stubs={}) + @mock_prompt ||= mock_model(Prompt, stubs) + end + + describe "GET index" do + it "assigns all prompts as @prompts" do + Prompt.stub!(:find).with(:all).and_return([mock_prompt]) + get :index + assigns[:prompts].should == [mock_prompt] + end + end + + describe "GET show" do + it "assigns the requested prompt as @prompt" do + Prompt.stub!(:find).with("37").and_return(mock_prompt) + get :show, :id => "37" + assigns[:prompt].should equal(mock_prompt) + end + end + + describe "GET new" do + it "assigns a new prompt as @prompt" do + Prompt.stub!(:new).and_return(mock_prompt) + get :new + assigns[:prompt].should equal(mock_prompt) + end + end + + describe "GET edit" do + it "assigns the requested prompt as @prompt" do + Prompt.stub!(:find).with("37").and_return(mock_prompt) + get :edit, :id => "37" + assigns[:prompt].should equal(mock_prompt) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created prompt as @prompt" do + Prompt.stub!(:new).with({'these' => 'params'}).and_return(mock_prompt(:save => true)) + post :create, :prompt => {:these => 'params'} + assigns[:prompt].should equal(mock_prompt) + end + + it "redirects to the created prompt" do + Prompt.stub!(:new).and_return(mock_prompt(:save => true)) + post :create, :prompt => {} + response.should redirect_to(prompt_url(mock_prompt)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved prompt as @prompt" do + Prompt.stub!(:new).with({'these' => 'params'}).and_return(mock_prompt(:save => false)) + post :create, :prompt => {:these => 'params'} + assigns[:prompt].should equal(mock_prompt) + end + + it "re-renders the 'new' template" do + Prompt.stub!(:new).and_return(mock_prompt(:save => false)) + post :create, :prompt => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested prompt" do + Prompt.should_receive(:find).with("37").and_return(mock_prompt) + mock_prompt.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :prompt => {:these => 'params'} + end + + it "assigns the requested prompt as @prompt" do + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => true)) + put :update, :id => "1" + assigns[:prompt].should equal(mock_prompt) + end + + it "redirects to the prompt" do + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(prompt_url(mock_prompt)) + end + end + + describe "with invalid params" do + it "updates the requested prompt" do + Prompt.should_receive(:find).with("37").and_return(mock_prompt) + mock_prompt.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :prompt => {:these => 'params'} + end + + it "assigns the prompt as @prompt" do + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => false)) + put :update, :id => "1" + assigns[:prompt].should equal(mock_prompt) + end + + it "re-renders the 'edit' template" do + Prompt.stub!(:find).and_return(mock_prompt(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested prompt" do + Prompt.should_receive(:find).with("37").and_return(mock_prompt) + mock_prompt.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the prompts list" do + Prompt.stub!(:find).and_return(mock_prompt(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(prompts_url) + end + end + +end diff --git a/spec/controllers/questions_controller_spec.rb b/spec/controllers/questions_controller_spec.rb new file mode 100644 index 0000000..86c3ca1 --- /dev/null +++ b/spec/controllers/questions_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe QuestionsController do + + def mock_question(stubs={}) + @mock_question ||= mock_model(Question, stubs) + end + + describe "GET index" do + it "assigns all questions as @questions" do + Question.stub!(:find).with(:all).and_return([mock_question]) + get :index + assigns[:questions].should == [mock_question] + end + end + + describe "GET show" do + it "assigns the requested question as @question" do + Question.stub!(:find).with("37").and_return(mock_question) + get :show, :id => "37" + assigns[:question].should equal(mock_question) + end + end + + describe "GET new" do + it "assigns a new question as @question" do + Question.stub!(:new).and_return(mock_question) + get :new + assigns[:question].should equal(mock_question) + end + end + + describe "GET edit" do + it "assigns the requested question as @question" do + Question.stub!(:find).with("37").and_return(mock_question) + get :edit, :id => "37" + assigns[:question].should equal(mock_question) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created question as @question" do + Question.stub!(:new).with({'these' => 'params'}).and_return(mock_question(:save => true)) + post :create, :question => {:these => 'params'} + assigns[:question].should equal(mock_question) + end + + it "redirects to the created question" do + Question.stub!(:new).and_return(mock_question(:save => true)) + post :create, :question => {} + response.should redirect_to(question_url(mock_question)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved question as @question" do + Question.stub!(:new).with({'these' => 'params'}).and_return(mock_question(:save => false)) + post :create, :question => {:these => 'params'} + assigns[:question].should equal(mock_question) + end + + it "re-renders the 'new' template" do + Question.stub!(:new).and_return(mock_question(:save => false)) + post :create, :question => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested question" do + Question.should_receive(:find).with("37").and_return(mock_question) + mock_question.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :question => {:these => 'params'} + end + + it "assigns the requested question as @question" do + Question.stub!(:find).and_return(mock_question(:update_attributes => true)) + put :update, :id => "1" + assigns[:question].should equal(mock_question) + end + + it "redirects to the question" do + Question.stub!(:find).and_return(mock_question(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(question_url(mock_question)) + end + end + + describe "with invalid params" do + it "updates the requested question" do + Question.should_receive(:find).with("37").and_return(mock_question) + mock_question.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :question => {:these => 'params'} + end + + it "assigns the question as @question" do + Question.stub!(:find).and_return(mock_question(:update_attributes => false)) + put :update, :id => "1" + assigns[:question].should equal(mock_question) + end + + it "re-renders the 'edit' template" do + Question.stub!(:find).and_return(mock_question(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested question" do + Question.should_receive(:find).with("37").and_return(mock_question) + mock_question.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the questions list" do + Question.stub!(:find).and_return(mock_question(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(questions_url) + end + end + +end diff --git a/spec/controllers/visitors_controller_spec.rb b/spec/controllers/visitors_controller_spec.rb new file mode 100644 index 0000000..da0104b --- /dev/null +++ b/spec/controllers/visitors_controller_spec.rb @@ -0,0 +1,131 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe VisitorsController do + + def mock_visitor(stubs={}) + @mock_visitor ||= mock_model(Visitor, stubs) + end + + describe "GET index" do + it "assigns all visitors as @visitors" do + Visitor.stub!(:find).with(:all).and_return([mock_visitor]) + get :index + assigns[:visitors].should == [mock_visitor] + end + end + + describe "GET show" do + it "assigns the requested visitor as @visitor" do + Visitor.stub!(:find).with("37").and_return(mock_visitor) + get :show, :id => "37" + assigns[:visitor].should equal(mock_visitor) + end + end + + describe "GET new" do + it "assigns a new visitor as @visitor" do + Visitor.stub!(:new).and_return(mock_visitor) + get :new + assigns[:visitor].should equal(mock_visitor) + end + end + + describe "GET edit" do + it "assigns the requested visitor as @visitor" do + Visitor.stub!(:find).with("37").and_return(mock_visitor) + get :edit, :id => "37" + assigns[:visitor].should equal(mock_visitor) + end + end + + describe "POST create" do + + describe "with valid params" do + it "assigns a newly created visitor as @visitor" do + Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => true)) + post :create, :visitor => {:these => 'params'} + assigns[:visitor].should equal(mock_visitor) + end + + it "redirects to the created visitor" do + Visitor.stub!(:new).and_return(mock_visitor(:save => true)) + post :create, :visitor => {} + response.should redirect_to(visitor_url(mock_visitor)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved visitor as @visitor" do + Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => false)) + post :create, :visitor => {:these => 'params'} + assigns[:visitor].should equal(mock_visitor) + end + + it "re-renders the 'new' template" do + Visitor.stub!(:new).and_return(mock_visitor(:save => false)) + post :create, :visitor => {} + response.should render_template('new') + end + end + + end + + describe "PUT update" do + + describe "with valid params" do + it "updates the requested visitor" do + Visitor.should_receive(:find).with("37").and_return(mock_visitor) + mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :visitor => {:these => 'params'} + end + + it "assigns the requested visitor as @visitor" do + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => true)) + put :update, :id => "1" + assigns[:visitor].should equal(mock_visitor) + end + + it "redirects to the visitor" do + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => true)) + put :update, :id => "1" + response.should redirect_to(visitor_url(mock_visitor)) + end + end + + describe "with invalid params" do + it "updates the requested visitor" do + Visitor.should_receive(:find).with("37").and_return(mock_visitor) + mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => "37", :visitor => {:these => 'params'} + end + + it "assigns the visitor as @visitor" do + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => false)) + put :update, :id => "1" + assigns[:visitor].should equal(mock_visitor) + end + + it "re-renders the 'edit' template" do + Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => false)) + put :update, :id => "1" + response.should render_template('edit') + end + end + + end + + describe "DELETE destroy" do + it "destroys the requested visitor" do + Visitor.should_receive(:find).with("37").and_return(mock_visitor) + mock_visitor.should_receive(:destroy) + delete :destroy, :id => "37" + end + + it "redirects to the visitors list" do + Visitor.stub!(:find).and_return(mock_visitor(:destroy => true)) + delete :destroy, :id => "1" + response.should redirect_to(visitors_url) + end + end + +end diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 0000000..ebcea11 --- /dev/null +++ b/spec/factories.rb @@ -0,0 +1,19 @@ +Factory.define(:item) do |f| + f.sequence(:data) { |i| "Item #{i}" } +end + +Factory.define(:question) do |f| + f.sequence(:name) { |i| "Name #{i}" } +end + +Factory.define(:visitor) do |f| + f.sequence(:identifier) { |i| "Identifier #{i}" } +end + +Factory.define(:prompt) do |f| + f.sequence(:tracking) { |i| "Prompt we're calling #{i}" } +end + +Factory.define(:choice) do |f| + f.sequence(:data) { |i| "Choice: #{i}" } +end diff --git a/spec/fixtures/choices.yml b/spec/fixtures/choices.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/choices.yml diff --git a/spec/fixtures/clicks.yml b/spec/fixtures/clicks.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/clicks.yml diff --git a/spec/fixtures/items.yml b/spec/fixtures/items.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/items.yml diff --git a/spec/fixtures/prompts.yml b/spec/fixtures/prompts.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/prompts.yml diff --git a/spec/fixtures/questions.yml b/spec/fixtures/questions.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/questions.yml diff --git a/spec/fixtures/skips.yml b/spec/fixtures/skips.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/skips.yml diff --git a/spec/fixtures/visitors.yml b/spec/fixtures/visitors.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/visitors.yml diff --git a/spec/fixtures/votes.yml b/spec/fixtures/votes.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spec/fixtures/votes.yml diff --git a/spec/helpers/choices_helper_spec.rb b/spec/helpers/choices_helper_spec.rb new file mode 100644 index 0000000..a7d1edd --- /dev/null +++ b/spec/helpers/choices_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ChoicesHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(ChoicesHelper) + end + +end diff --git a/spec/helpers/clicks_helper_spec.rb b/spec/helpers/clicks_helper_spec.rb new file mode 100644 index 0000000..41eba9a --- /dev/null +++ b/spec/helpers/clicks_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ClicksHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(ClicksHelper) + end + +end diff --git a/spec/helpers/items_helper_spec.rb b/spec/helpers/items_helper_spec.rb new file mode 100644 index 0000000..db6c795 --- /dev/null +++ b/spec/helpers/items_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ItemsHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(ItemsHelper) + end + +end diff --git a/spec/helpers/prompts_helper_spec.rb b/spec/helpers/prompts_helper_spec.rb new file mode 100644 index 0000000..02096e0 --- /dev/null +++ b/spec/helpers/prompts_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe PromptsHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(PromptsHelper) + end + +end diff --git a/spec/helpers/questions_helper_spec.rb b/spec/helpers/questions_helper_spec.rb new file mode 100644 index 0000000..af0cf9d --- /dev/null +++ b/spec/helpers/questions_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe QuestionsHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(QuestionsHelper) + end + +end diff --git a/spec/helpers/visitors_helper_spec.rb b/spec/helpers/visitors_helper_spec.rb new file mode 100644 index 0000000..713e03f --- /dev/null +++ b/spec/helpers/visitors_helper_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe VisitorsHelper do + + #Delete this example and add some real ones or delete this file + it "is included in the helper object" do + included_modules = (class << helper; self; end).send :included_modules + included_modules.should include(VisitorsHelper) + end + +end diff --git a/spec/integration/choices_spec.rb b/spec/integration/choices_spec.rb new file mode 100644 index 0000000..e44943a --- /dev/null +++ b/spec/integration/choices_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Choices" do +end diff --git a/spec/integration/clicks_spec.rb b/spec/integration/clicks_spec.rb new file mode 100644 index 0000000..cb842e6 --- /dev/null +++ b/spec/integration/clicks_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Clicks" do +end diff --git a/spec/integration/items_spec.rb b/spec/integration/items_spec.rb new file mode 100644 index 0000000..1a3110f --- /dev/null +++ b/spec/integration/items_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Items" do +end diff --git a/spec/integration/prompts_spec.rb b/spec/integration/prompts_spec.rb new file mode 100644 index 0000000..7bd9389 --- /dev/null +++ b/spec/integration/prompts_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Prompts" do +end diff --git a/spec/integration/questions_spec.rb b/spec/integration/questions_spec.rb new file mode 100644 index 0000000..95bc4c0 --- /dev/null +++ b/spec/integration/questions_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Questions" do +end diff --git a/spec/integration/visitors_spec.rb b/spec/integration/visitors_spec.rb new file mode 100644 index 0000000..8b1911e --- /dev/null +++ b/spec/integration/visitors_spec.rb @@ -0,0 +1,4 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "Visitors" do +end diff --git a/spec/models/choice_spec.rb b/spec/models/choice_spec.rb new file mode 100644 index 0000000..ce456ae --- /dev/null +++ b/spec/models/choice_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Choice do + + it {should belong_to :question} + it {should belong_to :item} + it {should validate_presence_of :question} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) + @question = Question.create(:name => 'which do you like better?', :site => @aoi_clone, :creator => @johndoe) + + @valid_attributes = { + :creator => @johndoe, + :question => @question + } + end + + it "should create a new instance given valid attributes" do + Choice.create!(@valid_attributes) + end + + it "should generate prompts after creation" do + @question.prompts.should_not be_empty + choice1 = Choice.create!(@valid_attributes.merge(:data => '1234')) + @question.prompts.should_not be_empty + end +end diff --git a/spec/models/click_spec.rb b/spec/models/click_spec.rb new file mode 100644 index 0000000..3f50ee7 --- /dev/null +++ b/spec/models/click_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Click do + + it {should belong_to :visitor} + it {should belong_to :site} + + before(:each) do + @valid_attributes = { + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + } + end + + it "should create a new instance given valid attributes" do + Click.create!(@valid_attributes) + end +end diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb new file mode 100644 index 0000000..29b5243 --- /dev/null +++ b/spec/models/item_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Item do + it {should belong_to :creator} + it {should belong_to :site} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) + @valid_attributes = { + :site => @aoi_clone, + :creator => @johndoe + } + end + + it "should create a new instance given valid attributes" do + Item.create!(@valid_attributes) + end +end diff --git a/spec/models/prompt_spec.rb b/spec/models/prompt_spec.rb new file mode 100644 index 0000000..ed01735 --- /dev/null +++ b/spec/models/prompt_spec.rb @@ -0,0 +1,26 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Prompt do + it {should belong_to :question} + it {should belong_to :left_choice} + it {should belong_to :right_choice} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) + @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor) + @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous') + @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous') + @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc) + @valid_attributes = { + :left_choice => @lc, + :right_choice => @rc, + :question => @question + + } + end + + it "should create a new instance given valid attributes" do + Prompt.create!(@valid_attributes) + end +end diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb new file mode 100644 index 0000000..6d60885 --- /dev/null +++ b/spec/models/question_spec.rb @@ -0,0 +1,42 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Question do + + it {should belong_to :creator} + it {should belong_to :site} + it {should have_many :choices} + it {should have_many :prompts} + it {should validate_presence_of :site} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @valid_attributes = { + :site => @aoi_clone, + :creator => @aoi_clone.default_visitor + + } + + # @item1 = Factory.create(:item, :data => "foo", :id => 1, :creator_id => 8) + # @item2 = Factory.create(:item, :data => "bar", :id => 2, :creator_id => 8) + end + + it "should create a new instance given valid attributes" do + Question.create!(@valid_attributes) + end + + it "should be creatable by a user" do + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) + end + + it "should create two default choices if none are provided" do + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) + q.choices(true).size.should == 2 + end + + it "should generate prompts after choices are added" do + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) + q.prompts(true).size.should == 2 + end + + #q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) +end \ No newline at end of file diff --git a/spec/models/skip_spec.rb b/spec/models/skip_spec.rb new file mode 100644 index 0000000..024885a --- /dev/null +++ b/spec/models/skip_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Skip do + it {should belong_to :prompt} + it {should belong_to :skipper} + before(:each) do + @valid_attributes = { + + } + end + + it "should create a new instance given valid attributes" do + Skip.create!(@valid_attributes) + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..27019f6 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,50 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe User do + it {should have_many :visitors} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) + @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor) + @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous') + @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous') + @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc) + end + + + it "should be able to create a question as a site" do + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) + q.should_not be_nil + q.site.should_not be_nil + q.site.should eql @aoi_clone + end + + it "should be able to create a choice for a question " do + q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) #replace with a factory + c = @aoi_clone.create_choice("foobarbaz", q, {:data => 'foobarbaz'}) + q.should_not be_nil + q.choices.should_not be_empty + q.choices.size.should eql 3 + end + + it "should be able to record a visitor's vote" do + v = @aoi_clone.record_vote("johnnydoe", @prompt, 0) + prompt_votes = @prompt.votes(true) + prompt_votes.should_not be_empty + prompt_votes.size.should eql 1 + + choices = @prompt.choices + #@question.prompts(true).size.should == 2 + choices.should_not be_empty + + choice_votes = choices[0].votes(true) + choice_votes.should_not be_empty + choice_votes.size.should eql 1 + end + + it "should be able to record a visitor's skip" do + s = @aoi_clone.record_skip("johnnydoe", @prompt) + end + +end \ No newline at end of file diff --git a/spec/models/visitor_spec.rb b/spec/models/visitor_spec.rb new file mode 100644 index 0000000..6cb8ad4 --- /dev/null +++ b/spec/models/visitor_spec.rb @@ -0,0 +1,46 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Visitor do + + it {should belong_to :site} + it {should have_many :questions} + it {should have_many :votes} + it {should have_many :skips} + + before(:each) do + @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) + @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) + @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor) + @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous') + @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous') + @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc) + #my_instance.stub!(:msg).and_return(value) + @valid_attributes = { + :site => @aoi_clone, + :identifier => "value for identifier", + :tracking => "value for tracking" + } + @v = Visitor.create!(@valid_attributes) + end + + it "should create a new instance given valid attributes" do + + end + + it "should be able to determine ownership of a question" do + @v.owns?(Question.new).should be_false + end + + it "should be able to vote for a prompt" do + #@prompt = @question.prompts.first + @prompt.should_not be_nil + v = @v.vote_for! @prompt, 0 + end + + it "should be able to vote for a prompt" do + #@prompt = @question.prompts.first + @prompt.should_not be_nil + v = @v.skip! @prompt + end + +end diff --git a/spec/models/vote_spec.rb b/spec/models/vote_spec.rb new file mode 100644 index 0000000..70aaba0 --- /dev/null +++ b/spec/models/vote_spec.rb @@ -0,0 +1,17 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Vote do + before(:each) do + @valid_attributes = { + :tracking => "value for tracking", + :site_id => 1, + :voter_id => 1, + :voteable_id => 1, + :voteable_type => "value for voteable_type" + } + end + + it "should create a new instance given valid attributes" do + Vote.create!(@valid_attributes) + end +end diff --git a/spec/rcov.opts b/spec/rcov.opts new file mode 100644 index 0000000..274ed51 --- /dev/null +++ b/spec/rcov.opts @@ -0,0 +1,2 @@ +--exclude "spec/*,gems/*" +--rails \ No newline at end of file diff --git a/spec/routing/choices_routing_spec.rb b/spec/routing/choices_routing_spec.rb new file mode 100644 index 0000000..79fa601 --- /dev/null +++ b/spec/routing/choices_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ChoicesController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "choices", :action => "index").should == "/choices" + end + + it "maps #new" do + route_for(:controller => "choices", :action => "new").should == "/choices/new" + end + + it "maps #show" do + route_for(:controller => "choices", :action => "show", :id => "1").should == "/choices/1" + end + + it "maps #edit" do + route_for(:controller => "choices", :action => "edit", :id => "1").should == "/choices/1/edit" + end + + it "maps #create" do + route_for(:controller => "choices", :action => "create").should == {:path => "/choices", :method => :post} + end + + it "maps #update" do + route_for(:controller => "choices", :action => "update", :id => "1").should == {:path =>"/choices/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "choices", :action => "destroy", :id => "1").should == {:path =>"/choices/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/choices").should == {:controller => "choices", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/choices/new").should == {:controller => "choices", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/choices").should == {:controller => "choices", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/choices/1").should == {:controller => "choices", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/choices/1/edit").should == {:controller => "choices", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/choices/1").should == {:controller => "choices", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/choices/1").should == {:controller => "choices", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/routing/clicks_routing_spec.rb b/spec/routing/clicks_routing_spec.rb new file mode 100644 index 0000000..c9325ff --- /dev/null +++ b/spec/routing/clicks_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ClicksController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "clicks", :action => "index").should == "/clicks" + end + + it "maps #new" do + route_for(:controller => "clicks", :action => "new").should == "/clicks/new" + end + + it "maps #show" do + route_for(:controller => "clicks", :action => "show", :id => "1").should == "/clicks/1" + end + + it "maps #edit" do + route_for(:controller => "clicks", :action => "edit", :id => "1").should == "/clicks/1/edit" + end + + it "maps #create" do + route_for(:controller => "clicks", :action => "create").should == {:path => "/clicks", :method => :post} + end + + it "maps #update" do + route_for(:controller => "clicks", :action => "update", :id => "1").should == {:path =>"/clicks/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "clicks", :action => "destroy", :id => "1").should == {:path =>"/clicks/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/clicks").should == {:controller => "clicks", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/clicks/new").should == {:controller => "clicks", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/clicks").should == {:controller => "clicks", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/clicks/1").should == {:controller => "clicks", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/clicks/1/edit").should == {:controller => "clicks", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/clicks/1").should == {:controller => "clicks", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/clicks/1").should == {:controller => "clicks", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/routing/items_routing_spec.rb b/spec/routing/items_routing_spec.rb new file mode 100644 index 0000000..0f11aca --- /dev/null +++ b/spec/routing/items_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ItemsController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "items", :action => "index").should == "/items" + end + + it "maps #new" do + route_for(:controller => "items", :action => "new").should == "/items/new" + end + + it "maps #show" do + route_for(:controller => "items", :action => "show", :id => "1").should == "/items/1" + end + + it "maps #edit" do + route_for(:controller => "items", :action => "edit", :id => "1").should == "/items/1/edit" + end + + it "maps #create" do + route_for(:controller => "items", :action => "create").should == {:path => "/items", :method => :post} + end + + it "maps #update" do + route_for(:controller => "items", :action => "update", :id => "1").should == {:path =>"/items/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "items", :action => "destroy", :id => "1").should == {:path =>"/items/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/items").should == {:controller => "items", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/items/new").should == {:controller => "items", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/items").should == {:controller => "items", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/items/1").should == {:controller => "items", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/items/1/edit").should == {:controller => "items", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/items/1").should == {:controller => "items", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/items/1").should == {:controller => "items", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/routing/prompts_routing_spec.rb b/spec/routing/prompts_routing_spec.rb new file mode 100644 index 0000000..a3420a4 --- /dev/null +++ b/spec/routing/prompts_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe PromptsController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "prompts", :action => "index").should == "/prompts" + end + + it "maps #new" do + route_for(:controller => "prompts", :action => "new").should == "/prompts/new" + end + + it "maps #show" do + route_for(:controller => "prompts", :action => "show", :id => "1").should == "/prompts/1" + end + + it "maps #edit" do + route_for(:controller => "prompts", :action => "edit", :id => "1").should == "/prompts/1/edit" + end + + it "maps #create" do + route_for(:controller => "prompts", :action => "create").should == {:path => "/prompts", :method => :post} + end + + it "maps #update" do + route_for(:controller => "prompts", :action => "update", :id => "1").should == {:path =>"/prompts/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "prompts", :action => "destroy", :id => "1").should == {:path =>"/prompts/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/prompts").should == {:controller => "prompts", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/prompts/new").should == {:controller => "prompts", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/prompts").should == {:controller => "prompts", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/prompts/1").should == {:controller => "prompts", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/prompts/1/edit").should == {:controller => "prompts", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/prompts/1").should == {:controller => "prompts", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/prompts/1").should == {:controller => "prompts", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/routing/questions_routing_spec.rb b/spec/routing/questions_routing_spec.rb new file mode 100644 index 0000000..078df86 --- /dev/null +++ b/spec/routing/questions_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe QuestionsController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "questions", :action => "index").should == "/questions" + end + + it "maps #new" do + route_for(:controller => "questions", :action => "new").should == "/questions/new" + end + + it "maps #show" do + route_for(:controller => "questions", :action => "show", :id => "1").should == "/questions/1" + end + + it "maps #edit" do + route_for(:controller => "questions", :action => "edit", :id => "1").should == "/questions/1/edit" + end + + it "maps #create" do + route_for(:controller => "questions", :action => "create").should == {:path => "/questions", :method => :post} + end + + it "maps #update" do + route_for(:controller => "questions", :action => "update", :id => "1").should == {:path =>"/questions/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "questions", :action => "destroy", :id => "1").should == {:path =>"/questions/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/questions").should == {:controller => "questions", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/questions/new").should == {:controller => "questions", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/questions").should == {:controller => "questions", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/questions/1").should == {:controller => "questions", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/questions/1/edit").should == {:controller => "questions", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/questions/1").should == {:controller => "questions", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/questions/1").should == {:controller => "questions", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/routing/visitors_routing_spec.rb b/spec/routing/visitors_routing_spec.rb new file mode 100644 index 0000000..e1e04a9 --- /dev/null +++ b/spec/routing/visitors_routing_spec.rb @@ -0,0 +1,63 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe VisitorsController do + describe "route generation" do + it "maps #index" do + route_for(:controller => "visitors", :action => "index").should == "/visitors" + end + + it "maps #new" do + route_for(:controller => "visitors", :action => "new").should == "/visitors/new" + end + + it "maps #show" do + route_for(:controller => "visitors", :action => "show", :id => "1").should == "/visitors/1" + end + + it "maps #edit" do + route_for(:controller => "visitors", :action => "edit", :id => "1").should == "/visitors/1/edit" + end + + it "maps #create" do + route_for(:controller => "visitors", :action => "create").should == {:path => "/visitors", :method => :post} + end + + it "maps #update" do + route_for(:controller => "visitors", :action => "update", :id => "1").should == {:path =>"/visitors/1", :method => :put} + end + + it "maps #destroy" do + route_for(:controller => "visitors", :action => "destroy", :id => "1").should == {:path =>"/visitors/1", :method => :delete} + end + end + + describe "route recognition" do + it "generates params for #index" do + params_from(:get, "/visitors").should == {:controller => "visitors", :action => "index"} + end + + it "generates params for #new" do + params_from(:get, "/visitors/new").should == {:controller => "visitors", :action => "new"} + end + + it "generates params for #create" do + params_from(:post, "/visitors").should == {:controller => "visitors", :action => "create"} + end + + it "generates params for #show" do + params_from(:get, "/visitors/1").should == {:controller => "visitors", :action => "show", :id => "1"} + end + + it "generates params for #edit" do + params_from(:get, "/visitors/1/edit").should == {:controller => "visitors", :action => "edit", :id => "1"} + end + + it "generates params for #update" do + params_from(:put, "/visitors/1").should == {:controller => "visitors", :action => "update", :id => "1"} + end + + it "generates params for #destroy" do + params_from(:delete, "/visitors/1").should == {:controller => "visitors", :action => "destroy", :id => "1"} + end + end +end diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..391705b --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,4 @@ +--colour +--format progress +--loadby mtime +--reverse diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1836a87 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,51 @@ +# This file is copied to ~/spec when you run 'ruby script/generate rspec' +# from the project root directory. +ENV["RAILS_ENV"] ||= 'test' +require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) +require 'spec/autorun' +require 'spec/rails' + +# Requires supporting files with custom matchers and macros, etc, +# in ./support/ and its subdirectories. +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} + +Spec::Runner.configure do |config| + # If you're not using ActiveRecord you should remove these + # lines, delete config/database.yml and disable :active_record + # in your config/boot.rb + config.use_transactional_fixtures = true + config.use_instantiated_fixtures = false + config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + + # == Fixtures + # + # You can declare fixtures for each example_group like this: + # describe "...." do + # fixtures :table_a, :table_b + # + # Alternatively, if you prefer to declare them only once, you can + # do so right here. Just uncomment the next line and replace the fixture + # names with your fixtures. + # + # config.global_fixtures = :table_a, :table_b + # + # If you declare global fixtures, be aware that they will be declared + # for all of your examples, even those that don't use them. + # + # You can also declare which fixtures to use (for example fixtures for test/fixtures): + # + # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + # + # == Mock Framework + # + # RSpec uses it's own mocking framework by default. If you prefer to + # use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + # + # == Notes + # + # For more information take a look at Spec::Runner::Configuration and Spec::Runner +end diff --git a/spec/views/choices/edit.html.erb_spec.rb b/spec/views/choices/edit.html.erb_spec.rb new file mode 100644 index 0000000..2ca2caa --- /dev/null +++ b/spec/views/choices/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/choices/edit.html.erb" do + include ChoicesHelper + + before(:each) do + assigns[:choice] = @choice = stub_model(Choice, + :new_record? => false + ) + end + + it "renders the edit choice form" do + render + + response.should have_tag("form[action=#{choice_path(@choice)}][method=post]") do + end + end +end diff --git a/spec/views/choices/index.html.erb_spec.rb b/spec/views/choices/index.html.erb_spec.rb new file mode 100644 index 0000000..5c081ec --- /dev/null +++ b/spec/views/choices/index.html.erb_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/choices/index.html.erb" do + include ChoicesHelper + + before(:each) do + assigns[:choices] = [ + stub_model(Choice), + stub_model(Choice) + ] + end + + it "renders a list of choices" do + render + end +end diff --git a/spec/views/choices/new.html.erb_spec.rb b/spec/views/choices/new.html.erb_spec.rb new file mode 100644 index 0000000..ffcc2b5 --- /dev/null +++ b/spec/views/choices/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/choices/new.html.erb" do + include ChoicesHelper + + before(:each) do + assigns[:choice] = stub_model(Choice, + :new_record? => true + ) + end + + it "renders new choice form" do + render + + response.should have_tag("form[action=?][method=post]", choices_path) do + end + end +end diff --git a/spec/views/choices/show.html.erb_spec.rb b/spec/views/choices/show.html.erb_spec.rb new file mode 100644 index 0000000..6799e28 --- /dev/null +++ b/spec/views/choices/show.html.erb_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/choices/show.html.erb" do + include ChoicesHelper + before(:each) do + assigns[:choice] = @choice = stub_model(Choice) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/clicks/edit.html.erb_spec.rb b/spec/views/clicks/edit.html.erb_spec.rb new file mode 100644 index 0000000..f79ca6c --- /dev/null +++ b/spec/views/clicks/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/clicks/edit.html.erb" do + include ClicksHelper + + before(:each) do + assigns[:click] = @click = stub_model(Click, + :new_record? => false, + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + ) + end + + it "renders the edit click form" do + render + + response.should have_tag("form[action=#{click_path(@click)}][method=post]") do + with_tag('input#click_site_id[name=?]', "click[site_id]") + with_tag('input#click_visitor_id[name=?]', "click[visitor_id]") + with_tag('textarea#click_additional_info[name=?]', "click[additional_info]") + end + end +end diff --git a/spec/views/clicks/index.html.erb_spec.rb b/spec/views/clicks/index.html.erb_spec.rb new file mode 100644 index 0000000..9275a91 --- /dev/null +++ b/spec/views/clicks/index.html.erb_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/clicks/index.html.erb" do + include ClicksHelper + + before(:each) do + assigns[:clicks] = [ + stub_model(Click, + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + ), + stub_model(Click, + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + ) + ] + end + + it "renders a list of clicks" do + render + response.should have_tag("tr>td", 1.to_s, 2) + response.should have_tag("tr>td", 1.to_s, 2) + response.should have_tag("tr>td", "value for additional_info".to_s, 2) + end +end diff --git a/spec/views/clicks/new.html.erb_spec.rb b/spec/views/clicks/new.html.erb_spec.rb new file mode 100644 index 0000000..541c41f --- /dev/null +++ b/spec/views/clicks/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/clicks/new.html.erb" do + include ClicksHelper + + before(:each) do + assigns[:click] = stub_model(Click, + :new_record? => true, + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + ) + end + + it "renders new click form" do + render + + response.should have_tag("form[action=?][method=post]", clicks_path) do + with_tag("input#click_site_id[name=?]", "click[site_id]") + with_tag("input#click_visitor_id[name=?]", "click[visitor_id]") + with_tag("textarea#click_additional_info[name=?]", "click[additional_info]") + end + end +end diff --git a/spec/views/clicks/show.html.erb_spec.rb b/spec/views/clicks/show.html.erb_spec.rb new file mode 100644 index 0000000..2e24028 --- /dev/null +++ b/spec/views/clicks/show.html.erb_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/clicks/show.html.erb" do + include ClicksHelper + before(:each) do + assigns[:click] = @click = stub_model(Click, + :site_id => 1, + :visitor_id => 1, + :additional_info => "value for additional_info" + ) + end + + it "renders attributes in

" do + render + response.should have_text(/1/) + response.should have_text(/1/) + response.should have_text(/value\ for\ additional_info/) + end +end diff --git a/spec/views/items/edit.html.erb_spec.rb b/spec/views/items/edit.html.erb_spec.rb new file mode 100644 index 0000000..40e9ada --- /dev/null +++ b/spec/views/items/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/items/edit.html.erb" do + include ItemsHelper + + before(:each) do + assigns[:item] = @item = stub_model(Item, + :new_record? => false + ) + end + + it "renders the edit item form" do + render + + response.should have_tag("form[action=#{item_path(@item)}][method=post]") do + end + end +end diff --git a/spec/views/items/index.html.erb_spec.rb b/spec/views/items/index.html.erb_spec.rb new file mode 100644 index 0000000..28917ab --- /dev/null +++ b/spec/views/items/index.html.erb_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/items/index.html.erb" do + include ItemsHelper + + before(:each) do + assigns[:items] = [ + stub_model(Item), + stub_model(Item) + ] + end + + it "renders a list of items" do + render + end +end diff --git a/spec/views/items/new.html.erb_spec.rb b/spec/views/items/new.html.erb_spec.rb new file mode 100644 index 0000000..18718ae --- /dev/null +++ b/spec/views/items/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/items/new.html.erb" do + include ItemsHelper + + before(:each) do + assigns[:item] = stub_model(Item, + :new_record? => true + ) + end + + it "renders new item form" do + render + + response.should have_tag("form[action=?][method=post]", items_path) do + end + end +end diff --git a/spec/views/items/show.html.erb_spec.rb b/spec/views/items/show.html.erb_spec.rb new file mode 100644 index 0000000..4af815a --- /dev/null +++ b/spec/views/items/show.html.erb_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/items/show.html.erb" do + include ItemsHelper + before(:each) do + assigns[:item] = @item = stub_model(Item) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/prompts/edit.html.erb_spec.rb b/spec/views/prompts/edit.html.erb_spec.rb new file mode 100644 index 0000000..ade405c --- /dev/null +++ b/spec/views/prompts/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/prompts/edit.html.erb" do + include PromptsHelper + + before(:each) do + assigns[:prompt] = @prompt = stub_model(Prompt, + :new_record? => false + ) + end + + it "renders the edit prompt form" do + render + + response.should have_tag("form[action=#{prompt_path(@prompt)}][method=post]") do + end + end +end diff --git a/spec/views/prompts/index.html.erb_spec.rb b/spec/views/prompts/index.html.erb_spec.rb new file mode 100644 index 0000000..4dd8e4c --- /dev/null +++ b/spec/views/prompts/index.html.erb_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/prompts/index.html.erb" do + include PromptsHelper + + before(:each) do + assigns[:prompts] = [ + stub_model(Prompt), + stub_model(Prompt) + ] + end + + it "renders a list of prompts" do + render + end +end diff --git a/spec/views/prompts/new.html.erb_spec.rb b/spec/views/prompts/new.html.erb_spec.rb new file mode 100644 index 0000000..365f6a8 --- /dev/null +++ b/spec/views/prompts/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/prompts/new.html.erb" do + include PromptsHelper + + before(:each) do + assigns[:prompt] = stub_model(Prompt, + :new_record? => true + ) + end + + it "renders new prompt form" do + render + + response.should have_tag("form[action=?][method=post]", prompts_path) do + end + end +end diff --git a/spec/views/prompts/show.html.erb_spec.rb b/spec/views/prompts/show.html.erb_spec.rb new file mode 100644 index 0000000..36db01c --- /dev/null +++ b/spec/views/prompts/show.html.erb_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/prompts/show.html.erb" do + include PromptsHelper + before(:each) do + assigns[:prompt] = @prompt = stub_model(Prompt) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/questions/edit.html.erb_spec.rb b/spec/views/questions/edit.html.erb_spec.rb new file mode 100644 index 0000000..86feee0 --- /dev/null +++ b/spec/views/questions/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/questions/edit.html.erb" do + include QuestionsHelper + + before(:each) do + assigns[:question] = @question = stub_model(Question, + :new_record? => false + ) + end + + it "renders the edit question form" do + render + + response.should have_tag("form[action=#{question_path(@question)}][method=post]") do + end + end +end diff --git a/spec/views/questions/index.html.erb_spec.rb b/spec/views/questions/index.html.erb_spec.rb new file mode 100644 index 0000000..0d9cef8 --- /dev/null +++ b/spec/views/questions/index.html.erb_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/questions/index.html.erb" do + include QuestionsHelper + + before(:each) do + assigns[:questions] = [ + stub_model(Question), + stub_model(Question) + ] + end + + it "renders a list of questions" do + render + end +end diff --git a/spec/views/questions/new.html.erb_spec.rb b/spec/views/questions/new.html.erb_spec.rb new file mode 100644 index 0000000..18838ab --- /dev/null +++ b/spec/views/questions/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/questions/new.html.erb" do + include QuestionsHelper + + before(:each) do + assigns[:question] = stub_model(Question, + :new_record? => true + ) + end + + it "renders new question form" do + render + + response.should have_tag("form[action=?][method=post]", questions_path) do + end + end +end diff --git a/spec/views/questions/show.html.erb_spec.rb b/spec/views/questions/show.html.erb_spec.rb new file mode 100644 index 0000000..004ec96 --- /dev/null +++ b/spec/views/questions/show.html.erb_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/questions/show.html.erb" do + include QuestionsHelper + before(:each) do + assigns[:question] = @question = stub_model(Question) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/visitors/edit.html.erb_spec.rb b/spec/views/visitors/edit.html.erb_spec.rb new file mode 100644 index 0000000..77eb16c --- /dev/null +++ b/spec/views/visitors/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/visitors/edit.html.erb" do + include VisitorsHelper + + before(:each) do + assigns[:visitor] = @visitor = stub_model(Visitor, + :new_record? => false, + :site_id => 1, + :identifier => "value for identifier", + :tracking => "value for tracking" + ) + end + + it "renders the edit visitor form" do + render + + response.should have_tag("form[action=#{visitor_path(@visitor)}][method=post]") do + with_tag('input#visitor_site_id[name=?]', "visitor[site_id]") + with_tag('input#visitor_identifier[name=?]', "visitor[identifier]") + with_tag('textarea#visitor_tracking[name=?]', "visitor[tracking]") + end + end +end diff --git a/spec/views/visitors/index.html.erb_spec.rb b/spec/views/visitors/index.html.erb_spec.rb new file mode 100644 index 0000000..9c4960a --- /dev/null +++ b/spec/views/visitors/index.html.erb_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/visitors/index.html.erb" do + include VisitorsHelper + + before(:each) do + assigns[:visitors] = [ + stub_model(Visitor, + :site_id => 1, + :identifier => "value for identifier", + :tracking => "value for tracking" + ), + stub_model(Visitor, + :site_id => 1, + :identifier => "value for identifier", + :tracking => "value for tracking" + ) + ] + end + + it "renders a list of visitors" do + render + response.should have_tag("tr>td", 1.to_s, 2) + response.should have_tag("tr>td", "value for identifier".to_s, 2) + response.should have_tag("tr>td", "value for tracking".to_s, 2) + end +end diff --git a/spec/views/visitors/new.html.erb_spec.rb b/spec/views/visitors/new.html.erb_spec.rb new file mode 100644 index 0000000..5002925 --- /dev/null +++ b/spec/views/visitors/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/visitors/new.html.erb" do + include VisitorsHelper + + before(:each) do + assigns[:visitor] = stub_model(Visitor, + :new_record? => true, + :site_id => 1, + :identifier => "value for identifier", + :tracking => "value for tracking" + ) + end + + it "renders new visitor form" do + render + + response.should have_tag("form[action=?][method=post]", visitors_path) do + with_tag("input#visitor_site_id[name=?]", "visitor[site_id]") + with_tag("input#visitor_identifier[name=?]", "visitor[identifier]") + with_tag("textarea#visitor_tracking[name=?]", "visitor[tracking]") + end + end +end diff --git a/spec/views/visitors/show.html.erb_spec.rb b/spec/views/visitors/show.html.erb_spec.rb new file mode 100644 index 0000000..5d47b88 --- /dev/null +++ b/spec/views/visitors/show.html.erb_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "/visitors/show.html.erb" do + include VisitorsHelper + before(:each) do + assigns[:visitor] = @visitor = stub_model(Visitor, + :site_id => 1, + :identifier => "value for identifier", + :tracking => "value for tracking" + ) + end + + it "renders attributes in

" do + render + response.should have_text(/1/) + response.should have_text(/value\ for\ identifier/) + response.should have_text(/value\ for\ tracking/) + end +end diff --git a/vendor/plugins/blitz/generators/model/templates/fixtures.yml b/vendor/plugins/blitz/generators/model/templates/fixtures.yml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/plugins/blitz/generators/model/templates/fixtures.yml -- libgit2 0.21.2