From: Date: Wed, 12 Jul 2006 23:58:33 +0000 (-0400) Subject: Initital scaffolding of the website plus initial work on the adding and X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/1660465f3e072cbddc19b19f7f8869affb0694c5?hp=cc4532dee83d19baf79b35fadf7064b9b5c3948a Initital scaffolding of the website plus initial work on the adding and editing general information for votes and list of candidates. The first steps toward importing voters has also been added. --- diff --git a/.bzrignore b/.bzrignore index b5649dd..1ef4de8 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1 +1,2 @@ database.yml +log diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb new file mode 100644 index 0000000..2b1f282 --- /dev/null +++ b/app/controllers/elections_controller.rb @@ -0,0 +1,73 @@ +class ElectionsController < ApplicationController + def index + list + render :action => 'list' + end + + def list + @election_pages, @elections = paginate :elections, :per_page => 10 + end + + def show + @election = Election.find(params[:id]) + end + + def new + @election = Election.new + end + + def create_election + @election = Election.new(params[:election]) + if @election.save + flash[:notice] = 'Election was successfully created.' + redirect_to :action => 'new_candidates', :id => @election.id + else + render :action => 'new' + end + end + + def new_candidates + @election = Election.find( params[:id] ) + end + + def add_candidate + election = Election.find( params[:id] ) + @candidate = Candidate.new + @candidate.name = params[:newcandidate] + @candidate.save + election.candidates << @candidate + render :partial => 'candidate_line' + end + + def delete_candidate + candidate = Candidate.find( params[:id] ) + candidate.destroy + end + + def edit + @election = Election.find(params[:id]) + end + + def edit_candidates + @election = Election.find( params[:id] ) + end + + def edit_voters + @election = Election.find( params[:id] ) + end + + def update + @election = Election.find(params[:id]) + if @election.update_attributes(params[:election]) + flash[:notice] = 'Election was successfully updated.' + redirect_to :action => 'show', :id => @election + else + render :action => 'edit' + end + end + + def destroy + election = Election.find(params[:id]).destroy + redirect_to :action => 'list' + end +end diff --git a/app/helpers/elections_helper.rb b/app/helpers/elections_helper.rb new file mode 100644 index 0000000..09497b1 --- /dev/null +++ b/app/helpers/elections_helper.rb @@ -0,0 +1,2 @@ +module ElectionsHelper +end diff --git a/app/models/candidate.rb b/app/models/candidate.rb new file mode 100644 index 0000000..41d743b --- /dev/null +++ b/app/models/candidate.rb @@ -0,0 +1,2 @@ +class Candidate < ActiveRecord::Base +end diff --git a/app/models/election.rb b/app/models/election.rb new file mode 100644 index 0000000..be828d0 --- /dev/null +++ b/app/models/election.rb @@ -0,0 +1,12 @@ +class Election < ActiveRecord::Base + has_many :candidates + validates_presence_of :name, :description + + def destroy + self.candidates.each do |candidate| + candidate.destroy + end + super destroy + end + +end diff --git a/app/views/elections/_candidate_line.rhtml b/app/views/elections/_candidate_line.rhtml new file mode 100644 index 0000000..7f68e6f --- /dev/null +++ b/app/views/elections/_candidate_line.rhtml @@ -0,0 +1,11 @@ +
+
  • + <%= @candidate.name %> + <% if @edit %> + <%= link_to_remote "Delete", + :complete => "Element.remove('cand#{@candidate.id}')", + :url => { :action => :delete_candidate, :id => @candidate.id } %> + <% end %> + +
  • +
    diff --git a/app/views/elections/_candidates_form.rhtml b/app/views/elections/_candidates_form.rhtml new file mode 100644 index 0000000..d739dbf --- /dev/null +++ b/app/views/elections/_candidates_form.rhtml @@ -0,0 +1,18 @@ +

    Please enter candidates for <%= @election.name %>.

    + + + + <%= form_remote_tag(:update => "candidates_list", + :url => { :action => :add_candidate, :id => @election.id }, + :position => "top" ) %> + +

    New candidate name: + <%= text_field_tag :newcandidate %> + + <%= submit_tag "Add" %> + <%= end_form_tag %> diff --git a/app/views/elections/_overview_form.rhtml b/app/views/elections/_overview_form.rhtml new file mode 100644 index 0000000..b3715e1 --- /dev/null +++ b/app/views/elections/_overview_form.rhtml @@ -0,0 +1,13 @@ +<%= error_messages_for 'election' %> + + +


    +<%= text_field 'election', 'name' %>

    + +


    +<%= text_area 'election', 'description' %>

    + +

    +<%= check_box 'election', 'anonymous', {}, 1, 0 %>

    + + diff --git a/app/views/elections/edit.rhtml b/app/views/elections/edit.rhtml new file mode 100644 index 0000000..af0cb49 --- /dev/null +++ b/app/views/elections/edit.rhtml @@ -0,0 +1,6 @@ +

    <%= @election.name %>: Edit Overview

    + +<%= start_form_tag :action => 'update', :id => @election %> + <%= render :partial => 'overview_form' %> + <%= submit_tag 'Done!' %> +<%= end_form_tag %> diff --git a/app/views/elections/edit_candidates.rhtml b/app/views/elections/edit_candidates.rhtml new file mode 100644 index 0000000..2809d10 --- /dev/null +++ b/app/views/elections/edit_candidates.rhtml @@ -0,0 +1,5 @@ +<% @edit = true %> +

    <%= @election.name %>: Edit Candidates

    + +<%= render :partial => 'candidates_form' %> +<%= button_to "Done!", :action => 'show', :id => @election %> diff --git a/app/views/elections/edit_voters.rhtml b/app/views/elections/edit_voters.rhtml new file mode 100644 index 0000000..64ec446 --- /dev/null +++ b/app/views/elections/edit_voters.rhtml @@ -0,0 +1,4 @@ +<% @edit = true %> +

    <%= @election.name %>: Edit Voter Rolls

    + +<%= button_to "Done!", :action => 'show', :id => @election %> diff --git a/app/views/elections/list.rhtml b/app/views/elections/list.rhtml new file mode 100644 index 0000000..40e24b5 --- /dev/null +++ b/app/views/elections/list.rhtml @@ -0,0 +1,27 @@ +

    Listing elections

    + + + + <% for column in Election.content_columns %> + + <% end %> + + +<% for election in @elections %> + + <% for column in Election.content_columns %> + + <% end %> + + + + +<% end %> +
    <%= column.human_name %>
    <%=h election.send(column.name) %><%= link_to 'Show', :action => 'show', :id => election %><%= link_to 'Edit', :action => 'edit', :id => election %><%= link_to 'Destroy', { :action => 'destroy', :id => election }, :confirm => 'Are you sure?' %>
    + +<%= link_to 'Previous page', { :page => @election_pages.current.previous } if @election_pages.current.previous %> +<%= link_to 'Next page', { :page => @election_pages.current.next } if @election_pages.current.next %> + +
    + +<%= link_to 'New election', :action => 'new' %> diff --git a/app/views/elections/new.rhtml b/app/views/elections/new.rhtml new file mode 100644 index 0000000..5e6fa1f --- /dev/null +++ b/app/views/elections/new.rhtml @@ -0,0 +1,9 @@ +

    Create A New Election

    + +

    Step 1: Describe The Election

    + +<%= form_tag :action => 'create_election' %> + <%= render :partial => 'overview_form' %> + <%= submit_tag "Done!" %> +<%= end_form_tag %> + diff --git a/app/views/elections/new_candidates.rhtml b/app/views/elections/new_candidates.rhtml new file mode 100644 index 0000000..67525fd --- /dev/null +++ b/app/views/elections/new_candidates.rhtml @@ -0,0 +1,5 @@ +<% @edit = true %> +

    <%= @election.name %>: Enter Candidates

    + +<%= render :partial => 'candidates_form' %> +<%= button_to "Done!", :action => 'show', :id => @election %> diff --git a/app/views/elections/show.rhtml b/app/views/elections/show.rhtml new file mode 100644 index 0000000..0ef2fc5 --- /dev/null +++ b/app/views/elections/show.rhtml @@ -0,0 +1,23 @@ +

    Information On <%= @election.name %>

    + +

    Overview <%= link_to "edit", :action => 'edit', :id => @election.id %>

    + +

    Description

    + +
    +<%= @election.description %> +
    + +

    Candidates <%= link_to "edit", :action => 'edit_candidates', :id => @election.id %>

    + + +The following are valid options or candidates in this election: + + + +

    Voters <%= link_to "edit", :action => 'edit_voters', :id => @election.id %>

    diff --git a/app/views/layouts/elections.rhtml b/app/views/layouts/elections.rhtml new file mode 100644 index 0000000..fbac7a9 --- /dev/null +++ b/app/views/layouts/elections.rhtml @@ -0,0 +1,14 @@ + + + Elections: <%= controller.action_name %> + <%= javascript_include_tag "prototype", "effects" %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

    <%= flash[:notice] %>

    + +<%= @content_for_layout %> + + + diff --git a/log/development.log b/log/development.log deleted file mode 100644 index 607602c..0000000 --- a/log/development.log +++ /dev/null @@ -1 +0,0 @@ -nil diff --git a/log/production.log b/log/production.log deleted file mode 100644 index 607602c..0000000 --- a/log/production.log +++ /dev/null @@ -1 +0,0 @@ -nil diff --git a/log/server.log b/log/server.log deleted file mode 100644 index 607602c..0000000 --- a/log/server.log +++ /dev/null @@ -1 +0,0 @@ -nil diff --git a/log/test.log b/log/test.log deleted file mode 100644 index 607602c..0000000 --- a/log/test.log +++ /dev/null @@ -1 +0,0 @@ -nil diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css new file mode 100644 index 0000000..de2ccc5 --- /dev/null +++ b/public/stylesheets/scaffold.css @@ -0,0 +1,74 @@ +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; +} + +div.uploadStatus { + margin: 5px; +} + +div.progressBar { + margin: 5px; +} + +div.progressBar div.border { + background-color: #fff; + border: 1px solid grey; + width: 100%; +} + +div.progressBar div.background { + background-color: #333; + height: 18px; + width: 0%; +} + diff --git a/test/fixtures/elections.yml b/test/fixtures/elections.yml new file mode 100644 index 0000000..8794d28 --- /dev/null +++ b/test/fixtures/elections.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +first: + id: 1 +another: + id: 2 diff --git a/test/functional/elections_controller_test.rb b/test/functional/elections_controller_test.rb new file mode 100644 index 0000000..1873304 --- /dev/null +++ b/test/functional/elections_controller_test.rb @@ -0,0 +1,88 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'elections_controller' + +# Re-raise errors caught by the controller. +class ElectionsController; def rescue_action(e) raise e end; end + +class ElectionsControllerTest < Test::Unit::TestCase + fixtures :elections + + def setup + @controller = ElectionsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_index + get :index + assert_response :success + assert_template 'list' + end + + def test_list + get :list + + assert_response :success + assert_template 'list' + + assert_not_nil assigns(:elections) + end + + def test_show + get :show, :id => 1 + + assert_response :success + assert_template 'show' + + assert_not_nil assigns(:election) + assert assigns(:election).valid? + end + + def test_new + get :new + + assert_response :success + assert_template 'new' + + assert_not_nil assigns(:election) + end + + def test_create + num_elections = Election.count + + post :create, :election => {} + + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_equal num_elections + 1, Election.count + end + + def test_edit + get :edit, :id => 1 + + assert_response :success + assert_template 'edit' + + assert_not_nil assigns(:election) + assert assigns(:election).valid? + end + + def test_update + post :update, :id => 1 + assert_response :redirect + assert_redirected_to :action => 'show', :id => 1 + end + + def test_destroy + assert_not_nil Election.find(1) + + post :destroy, :id => 1 + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_raise(ActiveRecord::RecordNotFound) { + Election.find(1) + } + end +end diff --git a/test/unit/election_test.rb b/test/unit/election_test.rb new file mode 100644 index 0000000..60663cf --- /dev/null +++ b/test/unit/election_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ElectionTest < Test::Unit::TestCase + fixtures :elections + + # Replace this with your real tests. + def test_truth + assert_kind_of Election, elections(:first) + end +end