+*~
+*.swp
database.yml
tmp
public/engine_files
public/skin_pictures
help
log/*
+*~
--- /dev/null
+===============================================
+=== Log =======================================
+===============================================
+
+07/31/07
+jlsharps: I've added a user authentication system known as
+"acts_as_authenticated" to the code. The plugin is the the vendor/plugins
+directory. The two most noticeable changes are the AccountController and a
+redone User model. I've left the UserController in place for now, but the
+AccountController works in a different manner, so am switching over to that
+gradually. I saved the 5 lines or so in the old User model, overwrote
+it with the authenticated generator and then recopied the old stuff back in:
+has_many :elections and the name() method. The generator also creates its own
+migration file, but since we are using a create.sql file I adopted the
+migration file into a new users table in the create.sql file. I have yet to
+delete the old table because I haven't fully combed through the code yet and
+determined how many of the old attributes (such as first_name, last_name) may
+need to be retained.
+http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated is the
+best site for documentation regarding acts_as_authenticaed. Also, currently
+it only stores the user_id in the session, but i just found a guide to help
+me make it store the entire user object, so I'll do that while my battery
+charges.
+
+08/03/07
+Handy trick: use the command 'gem_server' from a shell to create a server at
+http://localhost:8008 that is an easy to navigate locally-hosted website with
+all the documentation on local gems you have in a easy to read format.
+
+jlsharps: I added the Gruff plug-in today, which is viewable under the folder
+vender/plugins/gruff. I installed it directly using the Gruff plug-in and
+included controller generate utility. The version 0.1.2, which doesn't seem to
+be the latest version. I've looked into it and it see and it seems that the
+latest version is 0.2.8. However, I wasn't sure how including a gem w/o a plugin
+would function in end-game rails so I just what I used for now. If you guys
+(mako of john) know how to do it, it'd probably be better to upgrade, but it
+didn't seem like the best use of my time right now. I got the plug-in here:
+http://topfunky.net/svn/plugins/gruff. You can get the gruff gem v 0.2.8 by
+typing "sudo gem install gruff", I believe it's also hosted on RubyForge.
+
+I created the GraphsController for Gruff methods to use. In Pollarize I put them
+in the ApplicationContorller file, so they would be accessible to all. While
+that it also an option here, it would also mean there wouldn't be much room for
+playing around because everything in the Application file has to be perfect or
+it seems to throw Error Code 500 (basically everything breaks). The show()
+is a sample sample provided with Gruff.
+
+Documentation is here:http://gruff.rubyforge.org/ Alternately, if you have the
+gem installed, you can use the ri command, or the above mentioned gem_server.
+
+If you guys want more helpful stuff here, let me know.
+
+=
course, we'd sure like it if you would send fixes back to us and tell us
about cool stuff you do with our software!
-The best way to get Selectricity is just to download it from our source
+The best way to get Selectricity is just to download it from our
source repository. You'll need the Git version control system or
source control manager to check it. You can get it here:
git checkout -b live origin/live
+===============================================
+=== Getting Help and Contributing =============
+===============================================
+
+If you have a question, you can always email the core team at:
+
+ team@selectricity.org
+
+If you want to get involved in development, want to discuss
+selectricity, or want to participate, please subscribe to our mailing
+list here:
+
+ http://mailman.mit.edu/mailman/listinfo/selectricity
+
+
===============================================
=== Dependencies ==============================
===============================================
Our server configuration uses Mongrel (installed from gems) behind an
Apache2 load balancing proxy using mod_proxy.
+You'll also need to have a MTA installed. We use Postfix and have not
+tried it with any other system. Presumably though, anything that
+provides '/usr/bin/sendmail' should work.
+
===============================================
=== Contributors to Selectricity Include ======
* Benjamin Mako Hill <mako@atdot.cc>
* John Dong <jdong@ubuntu.com>
- * Justin Sharps <jlsharps@mit.edu>
-
-===============================================
-=== Log =======================================
-===============================================
-
-07/31/07
-jlsharps: I've added a user authentication system known as
-"acts_as_authenticated" to the code. The plugin is the the vendor/plugins
-directory. The two most noticeable changes are the AccountController and a
-redone User model. I've left the UserController in place for now, but the
-AccountController works in a different manner, so am switching over to that
-gradually. I saved the 5 lines or so in the old User model, overwrote
-it with the authenticated generator and then recopied the old stuff back in:
-has_many :elections and the name() method. The generator also creates its own
-migration file, but since we are using a create.sql file I adopted the
-migration file into a new users table in the create.sql file. I have yet to
-delete the old table because I haven't fully combed through the code yet and
-determined how many of the old attributes (such as first_name, last_name) may
-need to be retained.
-http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated is the
-best site for documentation regarding acts_as_authenticaed. Also, currently
-it only stores the user_id in the session, but i just found a guide to help
-me make it store the entire user object, so I'll do that while my battery
-charges.
-
-08/03/07
-Handy trick: use the command 'gem_server' from a shell to create a server at
-http://localhost:8008 that is an easy to navigate locally-hosted website with
-all the documentation on local gems you have in a easy to read format.
-
-jlsharps: I added the Gruff plug-in today, which is viewable under the folder
-vender/plugins/gruff. I installed it directly using the Gruff plug-in and
-included controller generate utility. The version 0.1.2, which doesn't seem to
-be the latest version. I've looked into it and it see and it seems that the
-latest version is 0.2.8. However, I wasn't sure how including a gem w/o a plugin
-would function in end-game rails so I just what I used for now. If you guys
-(mako of john) know how to do it, it'd probably be better to upgrade, but it
-didn't seem like the best use of my time right now. I got the plug-in here:
-http://topfunky.net/svn/plugins/gruff. You can get the gruff gem v 0.2.8 by
-typing "sudo gem install gruff", I believe it's also hosted on RubyForge.
-
-I created the GraphsController for Gruff methods to use. In Pollarize I put them
-in the ApplicationContorller file, so they would be accessible to all. While
-that it also an option here, it would also mean there wouldn't be much room for
-playing around because everything in the Application file has to be perfect or
-it seems to throw Error Code 500 (basically everything breaks). The show()
-is a sample sample provided with Gruff.
-
-Documentation is here:http://gruff.rubyforge.org/ Alternately, if you have the
-gem installed, you can use the ri command, or the above mentioned gem_server.
-
-If you guys want more helpful stuff here, let me know.
-
-======================================
-=== XML-RPC INFO ==
-======================================
-
-The XML-RPC API is still under development, but is somewhat functional already:
-
-To instantiate a client in Ruby, try something like:
-client=ActionWebService::Client::XmlRpc.new(SelectricityAPI,"http://localhost:3000/selectricity_service/vote")
-
-
-Getting the results of a quickvote is quite simple:
-?> client.get_quickvote_results("test")
-=> #<VoteResultStruct:0x336f92c @approval_winners=[1, 2], @borda_winners=[1], @plurality_winners=[1], @ssd_winners=[1], @errors=[], @condorcet_winners=[1]>
-
-Casting a quickvote:
-client.cast_quickvote("test",1,[[1,2]])
-
-To figure out what you're voting for:
->> client.get_quickvote_candidate_map("test")=> #<CandidateMap:0x335bbc0 @errors=[], @candidate_names=["test", "test2"], @candidate_ids=[1, 2]>
-
-
-
+ * Justin Sharps <jlsharps@alum.mit.edu>
helpful for auditing, too, as one could separately match names to the
correct list and match addresses to names.)
+Elections
+===================
+
+- a way to cancel the election creation process after one has been created, but not yet started
+
+- resume election creation process after starting one at an earlier time
+
QuickVotes
==============
- support for invisible results until over quickvotes (see create.rhtml)
- quickvotes should have automatically created urls
+
+User Accounts
+===============
+- support for changing associated e-mails
+- summary of elections run needs to fit inside box
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class AboutController < ApplicationController
layout 'main'
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class AccountController < ApplicationController
layout 'main'
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
# Filters added to this controller will be run for all controllers in
# the application. Likewise, all the methods added will be available
#both election_controller and quickvote_controller need this method
def sort_candidates
-
@vote = Vote.find(params[:id])
@vote.rankings.each do |ranking|
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class ElectionController < ApplicationController
require_dependency "raw_voter_list"
require_dependency "voter"
require_dependency "vote"
require_dependency "candidate"
+
+ helper :sparklines
layout 'main'
+
+ before_filter :verify_owner,
+ :except => [:new, :general_information, :create_election]
+ before_filter :verify_not_active,
+ :except => [:new, :general_information, :create_election,
+ :show, :results, :details, :pref_tables]
+
## methods for displaying, creating,
## and manipulating election overview data
####################################################################
end
end
- def create_theme_hash
- target = Hash.new
- params.each do |k,v|
- target[k] = v if k=="top_bar" or k=="default_image" or k=="bg1" \
- or k=="bg2" or k=="bottom_bar"
- end
- return target
- end
-
- # TODO add filter to verify that the person working on or looking at
- # something is the owner
def edit_general_information
+ @sidebar_content = render_to_string :partial => 'progress',
+ :locals => { :page => 'overview' }
@election = Election.find(params[:id])
end
flash[:notice] = 'Election was successfully updated.'
redirect_to :action => 'show', :id => @election
else
- render :action => 'edit'
+ render :action => 'edit_general_information'
end
end
def edit_candidates
@sidebar_content = render_to_string :partial => 'progress',
:locals => { :page => 'candidates' }
- @election = Election.find( params[:id] )
+ @election = Election.find(params[:id] )
end
def add_candidate
end
def delete_candidate
- candidate = Candidate.find( params[:id] )
+ candidate = Candidate.find(params[:candidate] )
candidate.destroy
end
def candidate_picture
- candidate = Candidate.find( params[:id] )
+ candidate = Candidate.find(params[:candidate])
send_data( candidate.picture.data,
:filename => candidate.picture.filename,
:type => candidate.picture.filetype,
@sidebar_content = render_to_string :partial => 'progress',
:locals => { :page => 'voters' }
- @election = Election.find( params[:id] )
+ @election = Election.find(params[:id])
+
if params.has_key?( :raw_voter_list )
process_incoming_voters( params[:raw_voter_list] )
end
end
def delete_voter
- voter = FullVoter.find( params[:id] )
+ voter = FullVoter.find(params[:voter])
voter.destroy
end
## methods for computing and printing results
####################################################################
def results
- @election = Election.find( params[:id] )
- votes = []
-
- @election.voters.each do |voter|
- if voter.vote and voter.vote.confirmed?
- votes << voter.vote.rankings.sort.collect {|vote| vote.candidate_id}
- end
+ @election = Election.find(params[:id])
+
+ if @election.early_results? \
+ or @election.enddate < Time.now
+
+ # render results
+ @sidebar_content = render_to_string(:partial => 'full_results_sidebar')
+ render :template => 'common/results'
+ else
+ redirect_to :action => 'index'
end
-
- @voteobj = CloneproofSSDVote.new(votes)
- @resultobj = @voteobj.result
- @winners = @resultobj.winners
-
- @candidates_by_id = {}
- @election.candidates.each {|cand| @candidates_by_id[cand.id] = cand}
-
end
- def detailed_results
-
- self.results
-
- @voter_list = []
- @vote_list = []
-
- @election.voters.each do |voter|
- if voter.vote and voter.vote.confirmed?
- @voter_list << voter.email
- @vote_list << voter.vote
- end
- end
+ def pref_tables
+ @election = Election.find(params[:id])
+ render :template => 'common/pref_tables_wrapper', :layout => 'basic'
+ end
- @vote_list.sort!
- @vote_list.sort! { |a,b| a.token <=> b.token }
+ def details
+ @election = Election.find(params[:id])
+ render :template => 'common/details'
end
## private methods
voter.save
end
end
+
+ def create_theme_hash
+ target = Hash.new
+ params.each do |k,v|
+ target[k] = v if k=="top_bar" or k=="default_image" or k=="bg1" \
+ or k=="bg2" or k=="bottom_bar"
+ end
+ return target
+ end
+
+ # verify that the person trying to edit the election is the owner
+ def verify_owner
+ election = Election.find(params[:id])
+ unless election.user == session[:user]
+ redirect_to :controller => 'front', :action => 'index'
+ end
+ end
+
+ # verify that the election is not active
+ def verify_not_active
+ election = Election.find(params[:id])
+ unless election.active == 0
+ redirect_to :controller => 'front', :action => 'index'
+ end
+ end
end
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class FrontController < ApplicationController
layout 'frontpage'
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
require 'date'
class GraphController < ApplicationController
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class QuickvoteController < ApplicationController
helper :sparklines
#Give registered users additional QuickVote functionality
@quickvote.user_id = session[:user][:id] if session[:user]
+ @quickvote.create_candidates
# try to save, if it fails, show the page again (the flash should
# still be intact
# if the person has specified an election, we show them the voting
# page. otherwise, we redirect back to main the page
if @election
+
+ # if the election is over, redirect to the the results page
+ unless @election.active?
+ redirect_to quickaction_url(:ident => params[:ident],
+ :action => 'results')
+ end
+
# look to see that the voter has been created and has voted in
# this election, and has confirmed their vote
@voter = QuickVoter.find(:all,
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class VoterController < ApplicationController
helper :sparklines
require_dependency "vote"
require_dependency "election"
+ before_filter :authenticate, :except => [:index, :login, :reminder,
+ :kiosk_ready, :sort_candidates]
+
def index
if params[:election_id]
@election = Election.find(params[:election_id])
@voter = OpenVoter.find(:all,
:conditions => ["session_id = ? and election_id = ?",
session.session_id, @election.id])[0]
-
-
+
@voter = OpenVoter.new unless @voter
@voter.election = @election
else
@sidebar_content = render_to_string(:partial => 'vote_sidebar')
if @election.embeddable? and params[:embed] == "true"
- #look for custom theme, and assign to instance variabels for widget use
+ # look for custom theme, and assign to instance variabels
+ # for widget use
if @election.embed_custom_string
@top_bar = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "top_bar.png"])
@default_image = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "default_image.png"])
@bg1 = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bg1.png"])
@bg2 = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bg2.png"])
@bottom_bar = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bottom_bar.png"])
end
render :template => 'embed/full_vote', :layout => 'embed'
else
def login
if params[:vote] and params[:vote][:password]
- redirect_to votepassword_url( :action => 'index', :urlpassword => params[:vote][:password])
+ redirect_to votepassword_url(:action => 'index',
+ :urlpassword => params[:vote][:password])
else
redirect_to :action => 'index'
end
end
- def pref_tables
- if authenticate
- @election = @voter.election
- @results = @election.results
- @candidates = {}
- @election.candidates.each {|c| @candidates[c.id] = c}
- @names = @election.names_by_id
- render :template => 'common/pref_tables', :layout => 'basic'
- else
- redirect_to :action => 'index'
- end
- end
-
- def details
- if authenticate
- @election = @voter.election
- @votes = @election.votes.select {|v| v.confirmed? }.shuffle
- @voters = @votes.collect {|v| v.voter}.shuffle
- render :action => 'details'
- else
- redirect_to :action => 'index'
- end
- end
-
def review
- if authenticate
- @voter.vote.time = Time.now
- @voter.vote.save
- @voter.reload
- else
- redirect_to :action => 'index'
- end
+ @voter.vote.time = Time.now
+ @voter.vote.save
+ @voter.reload
end
def confirm
- if authenticate
- if @voter.vote.confirm!
- if @voter.election.embeddable? and params[:embed] == "true" \
- and @voter.election.early_results?
- redirect_to :action => :results, :id => @password, :embed => 'true'
- else
- render :action => 'thanks'
- end
+ if @voter.vote.confirm!
+ if @voter.election.embeddable? and params[:embed] == "true" \
+ and @voter.election.early_results?
+ redirect_to :action => :results, :id => @password, :embed => 'true'
+ elsif not(@voter.election.verifiable) \
+ and @voter.election.kiosk and params[:kiosk] == "true"
+ redirect_to :action => "kiosk_ready", :id => @password, :kiosk => true
else
- redirect_to :action => 'index'
+ render :action => 'thanks'
end
else
- redirect_to :action => 'index'
+ redirect_to :action => 'index'
end
end
def reminder
if params[:email]
- voter_array= FullVoter.find(:all, :conditions => ["email = ?", params[:email]])
+ voter_array= FullVoter.find(:all,
+ :conditions => ["email = ?", params[:email]])
voter_array.delete_if {|voter| voter.election.active == 0}
unless voter_array.empty?
VoterNotify.deliver_reminder(voter_array)
or @voter.election.enddate < Time.now)
@election = @voter.election
- # compute and display results
-
- @results = @election.results
- @candidates = {}
- @election.candidates.each {|c| @candidates[c.id] = c}
- @names = @election.names_by_id
-
- @sidebar_content = render_to_string(:partial => 'results_sidebar')
- #look for custom theme, and assign to instance variabels for widget use
+ @sidebar_content = \
+ render_to_string(:partial => 'full_results_sidebar')
+
+ # look for custom theme, and assign to instance variabels for
+ # widget use
if @election.embed_custom_string
@top_bar = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "top_bar.png"])
@default_image = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "default_image.png"])
@bg1 = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bg1.png"])
@bg2 = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bg2.png"])
@bottom_bar = SkinPicture.find(:first,
- :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
+ :conditions => ["filename = ?",
+ @election.embed_custom_string + "bottom_bar.png"])
end
if @election.embeddable? and params[:embed] == "true"
render :template => 'embed/results', :layout => 'embed'
else
- render :action => 'results'
+ render :template => 'common/results'
end
else
redirect_to :action => 'index'
end
end
-
+
+ def pref_tables
+ @election = @voter.election
+ render :template => 'common/pref_tables_wrapper', :layout => 'basic'
+ end
+
+ def details
+ @election = @voter.election
+ render :template => 'common/details'
+ end
+
+ def kiosk_ready
+ reset_session
+
+ if not authenticate
+ redirect_to :action => 'index'
+ end
+ end
+
private
def authenticate
password = params[:id]
if password == "open"
election = Election.find(params[:format])
- # double check to make sure the election is not authenticated
- unless election.authenticated?
+ # if it's not actually open, lets redirect
+ if election.authenticated
+ redirect_to :action => 'index'
+
+ # otherwise, lets see if they've before
+ else
@voter = OpenVoter.find(:all,
:conditions => ["session_id = ? and election_id = ?",
session.session_id, election.id])[0]
- # if the election is over, proceed
- if (not @voter) and (election.enddate < Time.now)
- @voter = OpenVoter.new
- @voter.election = election
+ # when (a) there is no voter or (b) when there is a voter but
+ # it's kiosk mode on the right page, rewrite with a blank voter
+ if ((not @voter) and (election.enddate < Time.now)) \
+ or (params[:action] == 'kiosk_ready' and election.kiosk)
+ @voter = OpenVoter.new unless @voter
end
+ # now that we have a voter (one way or another), set things
+ # right
+ @voter.election = election
+ @voter.session_id = session.session_id
@password = "open." + election.id.to_s
end
else
@voter = FullVoter.find(:all,
:conditions => [ "password = ?", password ] )[0]
- @password = @voter.password
+
+ if @voter
+ @password = @voter.password
+ else
+ redirect_to :Action => 'index'
+ end
end
- @voter
end
end
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Candidate < ActiveRecord::Base
belongs_to :election
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Election < ActiveRecord::Base
has_many :candidates
has_many :votes
belongs_to :user
validates_presence_of :name, :description
-
+
+ # enforce constraints associated with dependencies (i.e., a kiosk
+ # election can't also be unauthenticated)
+ before_save :enforce_constraints
+
#validate that method is one of the listed election types
-
attr_reader :plurality_result
attr_reader :approval_result
attr_reader :condorcet_result
attr_reader :borda_result
require 'date'
-
+
def initialize(params={})
super
self.enddate = read_attribute( :enddate ) || \
def activate!
self.active = 1
- self.save!
+ self.save
end
def quickvote?
def authenticated?
authenticated
end
+
+ def kiosk?
+ kiosk
+ end
def shortdesc
shortdesc = description.split(/\n/)[0]
names
end
+
+ def candidate_hash
+ hash = {}
+ self.candidates.each {|c| hash[c.id] = c}
+ return hash
+ end
+
+
+ # TODO now that this code is in here, we should go ahead and remove
+ # date checking from other places in the code
+ def after_find
+ if self.active < 2 and self.enddate < Time.now
+ self.active = 2
+ self.save
+ end
+ end
+
+ private
+ def enforce_constraints
+ # kiosks can't be authenticated
+ self.authenticated = false if kiosk?
+ return true
+ end
+
end
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class FullVoter < Voter
validates_presence_of :email, :password
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class OpenVoter < Voter
end
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Picture < ActiveRecord::Base
belongs_to :candidate
class QuickVote < Election
before_validation :build_candidate_names
- after_validation :create_candidates
validates_uniqueness_of :name
attr_accessor :candidate_names
def build_candidate_names
@candidate_names ||= []
- if @candidate_names.empty? and not candidates.empty?
- @candidate_names = candidates.collect {|c| c.name}
+ if @candidate_names.empty? and not self.candidates.empty?
+ @candidate_names = self.candidates.collect {|c| c.name}
end
end
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class QuickVoter < Voter
validates_presence_of :session_id
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Ranking < ActiveRecord::Base
belongs_to :candidate
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class RawVoterList
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Token < ActiveRecord::Base
belongs_to :vote
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
require 'digest/sha1'
class User < ActiveRecord::Base
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Vote < ActiveRecord::Base
# relationships to other classes
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class Voter < ActiveRecord::Base
belongs_to :election
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class VoterNotify < ActionMailer::Base
<p>Your Elections:
<table class="voterbox" id="election">
<tr>
- <% Election.content_columns.each do |column| -%>
- <% dontPrint = ["viewable", "quickuser", "active", "anonymous", \
- "early_results", "embed_custom_string", "embeddable", \
- "notices"]%>
- <% next if dontPrint.include?(column.name)%>
- <th><%= column.human_name %></th>
+ <% ["Name", "Description", "Details"].each do |column| -%>
+ <th><%= column %></th>
<% end -%>
</tr>
<% @user.elections.select {|e| e.instance_of?(Election)}.each do |election| %>
<tr>
- <td>
- <% if election.active == 1 -%>
+ <td style="text-align: left;">
<%= link_to "#{election.name}", :controller => 'election',
:action => 'show', :id => election %>
- <% else -%>
- <%=h election.name %>
- <% end -%>
</td>
- <td><%=h election.description %></td>
- <td><%=h election.startdate.strftime("%x") %></td>
- <td><%=h election.enddate.strftime("%x") %></td>
- <td><%=h election.election_method %></td>
- <td>
- <% if election.authenticated? %>
- Yes
- <% else -%>
- No
- <% end -%>
+ <td style="text-align: left;"><%=h election.description %></td>
+ <td style="text-align: left;">
+ <strong>Start:</strong> <%=h election.startdate.strftime("%x") %><br />
+ <strong>End:</strong> <%=h election.enddate.strftime("%x") %><br />
+ <strong>Method:</strong> <%=h ELECTION_TYPES[election.election_method] %><br />
+ <strong>Open:</strong> <%= (not election.authenticated?).to_s.capitalize %>
</td>
</tr>
+<!-- first, process the results -->
+<% @election.results! %>
+
+<!-- create the necessary variables -->
<% candidates = @election.ssd_result.ranked_candidates.flatten -%>
<% voters = @election.voters.size %>
<% matrix = @election.ssd_result.matrix %>
<% victories = @election.ssd_result.victories_and_ties %>
+<% @names = @election.names_by_id %>
+
<p>Each number in the table below shows how many times the candidate on
the left beat the matching candidate on the top. The winner is on the
top of the left column.</p>
<div id="sortable_list">
<ol id="rankings-list">
- <% for ranking in @voter.vote.rankings %>
+ <% for ranking in @voter.vote.rankings.sort %>
<li class="moveable" id="ranking_<%= ranking.candidate.id %>">
<%= white_list(ranking.candidate.name.capitalize) %></li>
<% end %>
+<% @votes = @election.votes.select {|v| v.confirmed? }.shuffle %>
+<% @voters = @votes.collect {|v| v.voter}.shuffle %>
+
<div id="title-header">
<span class="header">Details</span>
<span class="subheader"><%= @election.name %></span>
<ol>
<%- @voters.each do |voter| -%>
-<li><%= voter.email %></li>
+<li><% if voter.email %>
+ <%= voter.email %>
+ <% elsif @election.kiosk? %>
+ Kiosk Voter
+ <% else %>
+ Unknown voter
+ <% end %></li>
<%- end -%>
</ol>
<p>The following table lists the votes cast in random order.</p>
-<p>The column marked <em>Verification Token</em> lists tokens that were
-given to voters at the time of voting. Voters can check to see that the
-vote that corresponds to their token was recorded correctly. The column
-marked <em>Vote</em> lists the candidates in order of the voter's
-preference. To read these votes, refer to the key below.</p>
+<p><% if @election.verifiable %>The column marked <em>Verification
+Token</em> lists tokens that were given to voters at the time of voting.
+Voters can check to see that the vote that corresponds to their token
+was recorded correctly.<% end %> The column marked <em>Vote</em> lists
+the candidates in order of the voter's preference. To read these votes,
+refer to the key below.</p>
<table class="preftable">
<tr>
<th></th>
-<th>Verification Token</th>
+<% if @election.verifiable %><th>Verification Token</th><% end %>
<th>Vote</th>
<%- @votes.each_with_index do |vote, i| -%>
<tr>
<td><%= i + 1 %></td>
-<td><%= vote.token %></td><td><%= vote.votestring%></td>
+<% if @election.verifiable %><td><%= vote.token %></td><% end %>
+<td><%= vote.votestring%></td>
</tr>
<%- end -%>
</table>
+<!-- create the default variables -->
+<% @results = @election.results %>
+<% @names = @election.names_by_id %>
+<% @candidates = @election.candidate_hash %>
+
<% require 'whois/whois' %>
<div id="title-header">
<%= link_to_remote "Delete",
:complete => "Element.remove('cand#{@current_candidate.id}')",
:url => { :action => :delete_candidate,
- :id => @current_candidate.id } %>
+ :id => @election.id, :candidate => @current_candidate.id } %>
</div>
<div class="clear-div"></div>
<%= render :partial => 'candidate_box_info' %>
--- /dev/null
+<!-- common data to all sidebars -->
+<%= render :partial => 'common/results_sidebar' %>
+
+<h2>Details</h2>
+
+<p><%= link_to "Auditing Information", { :action => 'details', :id => @election.id }, :popup => [] %></p>
<% type_hash = {}; ELECTION_TYPES.each {|k,v| type_hash[v] = k} %>
<%= select_tag 'election[election_method]', options_for_select(type_hash, @election.election_method) %></p>
-<!-- <p><label for="election_election_method">Enable Embeddable Elections?</label>
-<%= check_box :election, :embeddable %></p>
+<p><label for="election_verifiable">Enable voter verifiable
+elections?</label>
+<%= check_box :election, :verifiable%></p>
-<p><label for="election_election_method">Should results be visible before end of election?</label>
+<p><label for="election_early_results">Should results be visible before end of election?</label>
<%= check_box :election, :early_results%></p>
--->
+
+<p><label for="election_embeddable">Enable embeddable elections?</label>
+<%= check_box :election, :embeddable %></p>
+
+<p><label for="election_kiosk">Enable kiosk mode?</label>
+<em><strong>Warning:</strong> This will let users vote multiple times
+from the same computer!</em>
+<%= check_box :election, :kiosk%></p>
+
<!--[eoform:election]-->
<% if @edit %>
<%= link_to_remote "Delete",
:complete => "Element.remove('voter#{voter.id}')",
- :url => { :action => :delete_voter, :id => voter.id } %>
+ :url => { :action => :delete_voter, :id => @election.id,
+ :voter => voter.id } %>
<% end %>
</li>
</div>
+++ /dev/null
-<h2>Result</h2>
-
-<%= render :partial => 'winner' %>
-
-<h2>Result Details</h2>
-
-<%= render :partial => 'winner_details' %>
-
-<h2>Election Rolls for Voter Verification</h2>
-
-<p>The voting rolls -- displayed here in alphabetical order -- for the
-last election are are follows.</p>
-
-<p>Information is displayed here to help voters verifying that their own
-vote was recorded correctly and that the election was not tampered
-with.</p>
-
-<h3>Voters</h3>
-<table border="1">
-<th>Voters (A-Z)</th>
-<% for email in @voter_list %>
-<tr>
-<td><%= email %></td>
-</tr>
-<% end %>
-</table>
-
-<h3>Votes by Token</h3>
-
-<p>The votes, listed in alphabetical order by token.</p>
-
-<table border="1">
-<tr>
- <th rowspan="2">Token (0-9, A-Z)</th>
- <th colspan="<%= @election.candidates.length %>">Rank of Candidates</th>
-</tr>
-<tr>
-
-<% for candidate in @election.candidates.sort.reverse %>
- <th><%= candidate %></th>
-<% end %>
-
-</tr>
-<% for vote in @vote_list %>
- <tr>
- <td><%= vote.token %></td>
- <% for ranking in vote.rankings %>
- <td><%= ranking %></td>
- <% end %>
- </tr>
-<% end %>
-</table>
<div class="clear-div"></div>
+<% if @election.active == 0 %>
+
<div class="normal-header">
<span class="header">Enter New Candidate</span>
<span class="subheader"></span>
to proceed to the next step.</p>
<%= button_to "Proceed to Next Step", :action => 'new_voters', :id => @election %>
+
+<% else %>
+
+<p>You can not edit the list of candidates once the election has begun.
+please return to the <%= link_to "election overview page", :action =>
+'show', :id => @election.id %>.</p>
+
+<% end %>
<% form_tag( {:action => 'update_general_information', :id => @election},
:multipart => true ) do %>
<%= render :partial => 'overview_form' %>
- <%= render :partial => 'theme_upload' %>
+ <!-- <%= render :partial => 'theme_upload' %> -->
<%= submit_tag 'Done' %>
<% end %>
<span class="subheader"></span>
</div>
-<p id="unauth_notice" <%= 'style="display: none;"' if @election.authenticated %>>Anyone will be able to
-vote in this election.</p>
+<% if @election.active == 0 %>
+
+<p id="unauth_notice" <%= 'style="display: none;"' if @election.authenticated %>>
+<% if @election.kiosk? %>
+ <em>Because you have enabled kiosk mode, there will be no registration of voters.</em>
+<% end %>
+Anyone will be able to vote in this election.</p>
<div id="voter_info_box" <%= 'style="display: none;"' unless @election.authenticated %>>
<%= render :partial => 'voter_list' %>
<% end %>
</div>
-<%= check_box :election, :authenticated %> Only allow registered voters
+<% unless @election.kiosk? %>
+ <%= check_box :election, :authenticated %> Only allow registered voters
+<% end %>
<%= observe_field "election_authenticated",
:url => { :action => 'toggle_authenticated', :id => @election.id },
<p>When you are done entering voters, please click the button below
to proceed to the next step.</p>
-<%= button_to 'Proceed to Next Step!', :action => 'show', :id => @election.id %>
+<%= button_to 'Proceed to Next Step', :action => 'show', :id => @election.id %>
+
+<% else %>
+
+<p>You can not edit the list of voters once the election has begun.
+please return to the <%= link_to "election overview page", :action =>
+'show', :id => @election.id %>.</p>
+
+<% end %>
+
:election_id => @election.id %>.</div>
<% elsif (@election.active? && @election.early_results? ) %>
- <div id="status">The creator of this election has decided that the results
+ <div id="status">You have decided that the results
should be viewable while the election is in progress.
- <%if @election.voters.empty? %>
+ <%if @election.voters.select {|v| v.vote.confirmed?}.empty? %>
However, no one has voted yet.
<% else %>
- <%= link_to "View results", :controller => 'voter', :action => 'results',
- :id => "open" %>.
+ <%= link_to "View results", :controller => 'election', :action => 'results',
+ :id => @election.id %>.
<% end %>
</div>
<% elsif @election.active? %>
<li>Elections <strong>will be</strong> embeddable.</li>
<% end %>
+<% if @election.kiosk %>
+<li>Selectricity's kiosk mode <strong>will be</strong> available.</li>
+<% end %>
+
+<% if @election.verifiable%>
+<li>Voters <strong>will be</strong> given tokens to verify their votes.</li>
+<% else %>
+<li>Elections <strong>will not be</strong> voter verifiable.</li>
+<% end %>
+
</ul>
<% if @election.active? and not @election.authenticated? %>
-<p><strong>Link</strong></p>
-<%= (link_to ("Go Vote!",
- :controller => 'voter', :action => 'index', :election_id => @election.id)).to_s %>
+<p><strong>Link to election:</strong></p>
+<ul>
+<li><%= (link_to ("Vote in election",
+ :controller => 'voter', :action => 'index', :election_id => @election.id)).to_s %>
+ (<%= votepassword_url(:urlpassword => "open." + @election.id.to_s) %>)</li>
+
+<% if @election.kiosk %>
+<li><%= link_to("Kiosk mode",
+ kiosk_ready_url(:urlpassword => "open." + @election.id.to_s,
+ :kiosk => true)) %>
+ (<%= kiosk_ready_url(:urlpassword => "open." + @election.id.to_s, :kiosk => true) %>)
+ <% end %>
+</ul>
<% end -%>
<div class="normal-header">
<%= render :partial => 'basic_login' %>
- <p>Full elections creation is not yet public. <a
- href="mailto:team@selectricity.org">Contact us</a> for access.</p>
-
- <!-- <p>If you do not yet have an account, you should <%= link_to "create
- one", :controller => 'account', :action => 'signup' %>.</p> -->
+ <p>If you do not yet have an account, you should <%= link_to "create
+ one", :controller => 'account', :action => 'signup' %>.</p>
<% end %>
<% else %>
<%= link_to("login", :controller => "account", :action => "login")
%>
- <!-- <%= link_to "sign up", :controller => "account",
- :action => "signup" %> -->
+ <%= link_to "sign up", :controller => "account",
+ :action => "signup" %>
<% end -%>
<%= link_to "help/about", :controller => 'about' %>
</div>
<h2>Details</h2>
<p><%= link_to "Auditing Information", { :action => 'details', :id => @password }, :popup => [] %></p>
-
<%= render :partial => 'common/sortable_vote' %>
<div style="margin-left: 30pt;">
-<%= button_to "Submit Vote", :action => 'review', :id => @password %>
+<% if @voter.election.kiosk and params[:kiosk] == "true" %>
+ <%= button_to "Submit Vote", :action => 'review', :id => @password, :kiosk => true %>
+<% else %>
+ <%= button_to "Submit Vote", :action => 'review', :id => @password %>
+<% end %>
</div>
<p><strong>Description:</strong></p>
<p><%= @voter.election.description %></p>
+<% if @voter.election.authenticated? %>
<div class="normal-header">
<span class="header">Current Voter</span>
<span class="subheader"></span>
</div>
+<% end %>
<p><strong><%= @voter.email %></strong></p>
--- /dev/null
+<div id="title-header">
+ <span class="header"><%= @voter.election.name %></span>
+ <span class="subheader"></span>
+</div>
+
+<p>Selectricity is running in kiosk mode and is ready for the next
+voter. Press the button below to generate a new ballot.</p>
+
+<p align="center"><%= button_to "Vote!", :action => "index", :urlpassword => @password, :kiosk => true %></p>
<p>Please select from one of the following pages.</p>
<div style="text-align: center;">
- <p><%= button_to 'Confirm This Vote', :action => 'confirm', :id => @password %></p>
-
- <p>If you choose, you will be able to go back<br />and change it up until
- the end of the voting period.</p>
+ <p><% if @voter.election.kiosk? and params[:kiosk] == 'true' %>
+ <%= button_to 'Confirm This Vote', :action => 'confirm', :id => @password,
+ :kiosk => true %>
+ <% else %>
+ <%= button_to 'Confirm This Vote', :action => 'confirm', :id => @password %>
+ <% end %>
+ </p>
+
+ <% unless @voter.election.kiosk? %>
+ <p>If you choose, you will be able to go back<br />and change it up until
+ the end of the voting period.</p>
+ <% end %>
- <p><%= button_to 'Discard This Vote', votepassword_url(
- :action => 'index', :urlpassword => @password) %></p>
-
- <p>You will be returned to the voting page to vote<br /> again, if you choose.</p>
-
+ <p><% if @voter.election.kiosk? and params[:kiosk] == 'true' %>
+ <%= button_to 'Discard This Vote',
+ votepassword_url(:action => 'index', :urlpassword => @password,
+ :kiosk => true) %>
+ <% else %>
+ <%= button_to 'Discard This Vote',
+ votepassword_url(:action => 'index', :urlpassword => @password) %>
+ <% end %>
+ </p>
+
</tr>
</div>
end of the election, you will be able to use this token to verify that
your vote was used in the election and that your vote was recorded
correctly.</p>
+
+<% if @voter.election.kiosk? and params[:kiosk] == 'true' %>
+
+<p>Please click the done button below when finished to reset the system
+for the next voter.</p>
+
+<%= button_to "Done", :action => "kiosk_ready", :id => @password, :kiosk => true %>
+
+<% end %>
--- /dev/null
+development:
+ bucket_name: appname_development
+ access_key_id:
+ secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
+
+test:
+ bucket_name: appname_test
+ access_key_id:
+ secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
+
+production:
+ bucket_name: appname
+ access_key_id:
+ secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
--- /dev/null
+development:
+ container_name: appname_development
+ username:
+ api_key:
+
+test:
+ container_name: appname_test
+ username:
+ api_key:
+
+production:
+ container_name: appname_production
+ username:
+ api_key:
:controller => 'voter',
:action => 'index'
+ map.kiosk_ready 'voter/kiosk_ready/:urlpassword',
+ :controller => 'voter',
+ :action => 'kiosk_ready'
+
map.connect 'quickvote/:action/:id',
:controller => 'quickvote',
:requirements => { :action => /(create|add_candidate|sort_candidates|my_quickvotes)/ }
--- /dev/null
+class KioskMode < ActiveRecord::Migration
+ def self.up
+ add_column :elections, :kiosk, :boolean,
+ :null => false, :default => false
+ add_column :elections, :verifiable, :boolean,
+ :null => false, :default => true
+
+ Election.find(:all).select {|e| e.class == QuickVote }.each do |e|
+ e.verifiable = false
+ e.save
+ end
+ end
+
+ def self.down
+ remove_column :elections, :kiosk
+ remove_column :elections, :verifiable
+ end
+end
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 3)
+ActiveRecord::Schema.define(:version => 20090607094837) do
create_table "candidates", :force => true do |t|
t.integer "election_id", :null => false
end
create_table "elections", :force => true do |t|
- t.string "name", :limit => 100, :null => false
- t.text "description", :null => false
- t.integer "anonymous", :limit => 1, :default => 1, :null => false
+ t.string "name", :limit => 100, :null => false
+ t.text "description", :null => false
+ t.integer "anonymous", :limit => 1, :default => 1, :null => false
t.datetime "startdate"
- t.datetime "enddate", :null => false
- t.integer "active", :limit => 1, :default => 0, :null => false
- t.integer "viewable", :limit => 1, :default => 1, :null => false
- t.integer "notices", :limit => 1, :default => 0, :null => false
+ t.datetime "enddate", :null => false
+ t.integer "active", :limit => 1, :default => 0, :null => false
+ t.integer "viewable", :limit => 1, :default => 1, :null => false
+ t.integer "notices", :limit => 1, :default => 0, :null => false
t.integer "user_id"
t.string "quickuser"
- t.string "election_method", :limit => 100, :default => "ssd"
- t.string "type", :limit => 100, :null => false
- t.boolean "embeddable", :default => false, :null => false
- t.boolean "authenticated", :default => true, :null => false
- t.boolean "early_results", :default => false, :null => false
+ t.string "election_method", :limit => 100, :default => "ssd"
+ t.string "type", :limit => 100, :null => false
+ t.boolean "embeddable", :default => false, :null => false
+ t.boolean "authenticated", :default => true, :null => false
+ t.boolean "early_results", :default => false, :null => false
+ t.string "embed_custom_string"
+ t.boolean "kiosk", :default => false, :null => false
+ t.boolean "verifiable", :default => true, :null => false
end
add_index "elections", ["user_id"], :name => "fk_user_election"
create_table "pictures", :force => true do |t|
- t.string "filename", :limit => 200
- t.binary "data"
- t.string "filetype", :limit => 100
- t.integer "candidate_id"
+ t.string "filename"
+ t.string "content_type"
+ t.integer "size"
+ t.integer "width"
+ t.integer "height"
+ t.integer "parent_id"
+ t.string "thumbnail"
+ t.datetime "created_at"
+ t.integer "candidate_id"
end
- add_index "pictures", ["candidate_id"], :name => "fk_candidate_picture"
-
create_table "rankings", :force => true do |t|
t.integer "vote_id"
t.integer "candidate_id"
--- /dev/null
+#!/usr/bin/env ruby
+
+## bring in the rubyvote library
+require '/home/mako/bin/lib/rubyvote'
+
+# list of support election methods
+@voting_methods = { 'plurality' => PluralityVote,
+ 'approval' => ApprovalVote,
+ 'condorcet' => CondorcetVote,
+ 'ssd' => CloneproofSSDVote,
+ 'borda' => BordaVote,
+ 'runoff' => InstantRunoffVote }
+
+@default_method = 'ssd'
+
+# ruby mail handling
+require 'rmail'
+require 'net/smtp'
+@from = "Selectricity Anywhere <vote@selectricity.org>" # from address
+
+## create an active record connection to an SQLite3 database where we
+## will store all of the vote data
+require 'sqlite3'
+require '/usr/share/rails/activerecord/lib/active_record.rb'
+
+ActiveRecord::Base.establish_connection(
+ :adapter=> 'sqlite3',
+ :dbfile=> '/home/mako/.votemail.db')
+
+class Election < ActiveRecord::Base
+ has_many :votes
+end
+
+class Vote < ActiveRecord::Base
+ belongs_to :election
+end
+
+# expire old elections
+def cleanup
+ Election.find_all(["active = 1"]).each do |election|
+ if Time.now - election.startdate > 1.hour
+ election.active = 0
+ election.save
+ end
+ end
+end
+
+# create a new election object
+def new_election(name, candidate_string=nil, options={})
+
+ # check to see if the name is in use
+ if Election.find_all(["active = 1 and name = ?", name]).length > 0
+ reply "Vote name \"%s\" in use. Try later or with new name." % name
+ return false
+ end
+
+ # check to see if it is a verboten name
+ if name == 'new' or name == 'create' or name =~ /^res/
+ reply "Sorry. You can't create a vote with that name."
+ return false
+ end
+
+ # see if there are any repeat candidates
+ if candidate_string.split(//).any? {|i| candidate_string.split(//).grep(i).length > 1}
+ reply "The choice list cannot contain repeated characters."
+ return false
+ end
+
+ # make sure there is a candidate list
+ if candidate_string.split(//).length < 2
+ reply "A vote needs at least two candidates"
+ return false
+ end
+
+ # otherwise, we have what we need to create and populate the new
+ # election
+ election = Election.new
+ election.name = name
+ election.candidate_string = candidate_string.split(//).sort.join("")
+ election.startdate = Time.now
+ election.active = 1
+
+ # set the voting method
+ if options.has_key?('method')
+ if @voting_methods.has_key?(options['method'])
+ election.voting_method = options['method']
+ else
+ reply "Unsupported voting method. Vote not created."
+ return false
+ end
+ else
+ election.voting_method = @default_method
+ end
+
+ # save the info string on candidates if anything is provided
+ if options.has_key?('candidates')
+
+ # generate the info string
+ election.info = candidate_string.split(//).collect do |c|
+ if options['candidates'].has_key?(c)
+ description = options['candidates'][c]
+ else
+ description = 'unknown'
+ end
+ [c.upcase, description].join(":")
+ end.join(", ")
+ end
+
+ if election.save
+ reply ("Vote created. Vote like: \"%s %s\". " +
+ "Arrange capital letters in order of voter preference. " +
+ "Send \"res %s\" for results.") % \
+ [name, candidate_string.upcase, name]
+ return true
+ else
+ reply "Failure creating vote."
+ return false
+ end
+end
+
+def register_vote(name=nil, votestring=nil)
+
+ election = Election.find_all(["active = 1 and name = ?", name])[0]
+
+ # check that the vote string doesn't contain duplicates
+ if votestring.split(//).any? {|i| votestring.split(//).grep(i).length > 1}
+ reply "The choice list cannot contain repeated characters."
+ return false
+
+ # OR extras
+ elsif votestring.split(//).any? {|i| not election.candidate_string.split(//).include?(i)}
+ reply "The choice list must only include these characters: %s" % election.candidate_string
+ return false
+ end
+
+ unless election.voting_method == 'plurality' or election.voting_method == 'approval'
+ # OR doesn't list all of the necessary options
+ if votestring.length != election.candidate_string.length
+ reply "You must list ALL of these choices: \"%s\"" % election.candidate_string
+ return false
+ end
+ end
+
+ # if this person has voted already, blow away the vote
+ Vote.find_all(["election_id = ? and email = ?", election.id, @email]).each do |vote|
+ vote.destroy
+ end
+
+ # create the new vote and populate the string
+ vote = Vote.new
+ vote.votestring = votestring
+ vote.email = @email
+ vote.election = election
+
+ # attach the vote to the election
+ if vote.save
+ reply "Vote recorded successfully as: %s" % vote.votestring.upcase
+ return true
+ else
+ reply "Failed to register your vote."
+ return false
+ end
+end
+
+def results(name=nil)
+
+ # ensure that we can find a vote by the name
+ if Election.find_all(["active = 1 and name = ?", name]).length != 1
+ reply "Sorry! I cannot find active vote by that name."
+ return false
+ else
+ election = Election.find_all(["active = 1 and name = ?", name])[0]
+ end
+
+ if election.votes.length == 0
+ reply "I have recorded no votes for that election."
+ return false
+ end
+
+ # build the tally of the number of votes
+ tally = Array.new
+ election.votes.each do |vote|
+ tally << vote.votestring.split(//)
+ end
+
+ result = @voting_methods[election.voting_method].new(tally).result
+
+ if result.winner?
+ if result.winners.length == 1
+ message = "The winner is: %s" % result.winners[0].upcase
+ else
+ message = "The winners are: %s" % result.winners.join(", ")
+ end
+ else
+ message = "There was no winner."
+ end
+
+ message += (" (Total votes: %s)" % election.votes.length )
+ reply(message)
+ return true
+end
+
+def provide_info(name=nil)
+ if not name or Election.find_all(["active = 1 and name = ?", name]).length != 1
+ reply "Sorry! I cannot find an active vote by that name."
+ return false
+ else
+ election = Election.find_all(["active = 1 and name = ?", name])[0]
+ end
+
+ if election.info
+ info_string = election.info
+ else
+ info_string = election.candidate_string.upcase.split(//).join(", ")
+ end
+
+ reply ("Choices include %s. Please list ALL and reply with " +
+ "\"%s %s\" with %s being in the order of your preference.") \
+ % [ info_string, election.name,
+ election.candidate_string.upcase,
+ election.candidate_string.upcase ]
+ return true
+end
+
+## samller helper functions
+#############################
+
+def trim_body(body="")
+ body.strip!
+ body.sub!(/^(.*?)(-- |\n\n).*$/m, '\1')
+ body.gsub!(/\s+/, ' ')
+ body.strip!
+ return body
+end
+
+# this message takes a message and sends it back to the person who is
+# calling the script
+def reply(msg=nil)
+ # create a new blank message
+ outgoing = RMail::Message.new
+ header = outgoing.header
+
+ # fill the values in
+ header.to = @email
+ header.from = @from
+ header.subject = "vote"
+ outgoing.body = msg
+
+ # send the mail over SMTP
+ Net::SMTP.start('localhost', 25) do |smtp|
+ smtp.send_message outgoing.to_s, @from, @email
+ end
+end
+
+def build_options(args=[])
+ options = Hash.new
+ candidates = Hash.new
+
+ args.each do |item|
+ if item =~ /\w+:\w+/
+ key, value = *item.split(':')
+ if key.length == 1
+ candidates[key] = value
+ else
+ options[key] = value
+ end
+ end
+ end
+
+ if candidates.length > 0
+ options['candidates'] = candidates
+ end
+
+ options
+end
+
+
+## main logic of the program
+#######################################################
+
+
+# run this each time to turn off any old emails
+cleanup()
+
+# grab the command out of the email
+incoming_msg = RMail::Parser.read(STDIN)
+
+# record the address from the incoming mail
+@email = incoming_msg.header.from.first.address
+
+## try to extract the body of the mail
+# first test to see if its multipart
+if incoming_msg.multipart?
+ incoming_msg.body.each do |msg|
+ if msg.header.media_type == 'text' and msg.header.subtype == 'plain'
+ command = trim_body(incoming_msg.body)
+ break
+ end
+ end
+
+# if it's not multipart, just grab the contents
+else
+ command = trim_body(incoming_msg.body)
+end
+
+# parse the commands command
+args = command.split.collect {|s| s.downcase}
+
+# if the person is creating a new vote
+if args[0] == 'new' or args[0] == 'create'
+
+ # verify that we have been given the right number of arguments
+ if args[1] and args[2]
+
+ # attempt to create the new election
+ new_election(args[1], args[2], build_options(args[3..-1]))
+
+ else
+ # otherwise, provide feedback
+ reply "Command be of the form: \"new votename ABCD\" where ABCD is the list of candidates."
+ end
+
+# if the person is asking for help
+elsif args[0] == "help" or args[0] == '?'
+ reply "Commands: \"new yourvotename ABCD\"; \"yourvotename BDCA\" (in preferred order); \"res yourvotename\", "
+
+# if the person is trying to get results
+elsif args[0] =~ /^res/
+ results(args[1])
+
+elsif args[0] == 'info'
+ provide_info(args[1])
+
+elsif Election.find_all(["active = 1 and name = ?", args[0]]).length == 1 \
+ and not args[1]
+ provide_info(args[0])
+
+# otherwise, check to see if it's a vote prefixed by a votename
+elsif Election.find_all(["active = 1 and name = ?", args[0]]).length == 1
+ register_vote args[0], args[1]
+
+# otherwise, we don't know, give an error
+else
+ reply "I don't understand your command. Perhaps you have the wrong " +
+ "vote name? Reply \"help\" for more information."
+end
+
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class QuickVoteStruct < ActionWebService::Struct
member :name, :string
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
require 'action_controller/integration'
# Copyright (C) 2007, 2008 Benjamin Mako Hill <mako@atdot.cc>
# Copyright (C) 2007 Massachusetts Institute of Technology
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
+# This program is free software. Please see the COPYING file for
+# details.
class SelectricityServiceController < ApplicationController
web_service_dispatching_mode :delegated
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+<% i = 0 %>
-mika_normal:
- id: 1
- name: mika
- election_id: 1
-
-mako_normal:
- id: 2
- name: mako
- election_id: 1
-
-bettamax_normal:
- id: 3
- name: bettamax
- election_id: 1
-
-mika_badend:
- id: 4
- name: mika
- election_id: 2
-
-mako_badend:
- id: 5
- name: mako
- election_id: 2
-
-bettamax_badend:
- id: 6
- name: bettamax
- election_id: 2
+cand_<%= i += 1 %>:
+ name: "techno picnic"
+ election_id: "954"
+ id: "4666"
+
+cand_<%= i += 1 %>:
+ name: "History's Best Dictators"
+ election_id: "954"
+ id: "4667"
+
+cand_<%= i += 1 %>:
+ name: "Lolita"
+ election_id: "954"
+ id: "4668"
+
+cand_<%= i += 1 %>:
+ name: "Famous Murderers"
+ election_id: "954"
+ id: "4669"
+
+cand_<%= i += 1 %>:
+ name: "Eyes Wide Shut"
+ election_id: "954"
+ id: "4670"
+
+cand_<%= i += 1 %>:
+ name: "Famous Literature"
+ election_id: "954"
+ id: "4671"
+
+cand_<%= i += 1 %>:
+ name: "Solstice"
+ election_id: "954"
+ id: "4672"
+
+cand_<%= i += 1 %>:
+ name: "Rocky Horror"
+ election_id: "954"
+ id: "4673"
+
+cand_<%= i += 1 %>:
+ name: "Clothing Optional + Wine"
+ election_id: "954"
+ id: "4674"
+
+cand_<%= i += 1 %>:
+ name: "Kindergarden"
+ election_id: "954"
+ id: "4675"
+
+cand_<%= i += 1 %>:
+ name: "Antarctica"
+ election_id: "954"
+ id: "4676"
+
+cand_<%= i += 1 %>:
+ name: "Ender's Game"
+ election_id: "954"
+ id: "4677"
+
+cand_<%= i += 1 %>:
+ name: "Terry Pratchett's Discworld"
+ election_id: "954"
+ id: "4678"
+
+cand_<%= i += 1 %>:
+ name: "Soviet Russia"
+ election_id: "954"
+ id: "4679"
+
+cand_<%= i += 1 %>:
+ name: "Rejected Superheroes"
+ election_id: "954"
+ id: "4680"
+
+cand_<%= i += 1 %>:
+ name: "Steampunk"
+ election_id: "954"
+ id: "4681"
+
+cand_<%= i += 1 %>:
+ name: "In The Lab"
+ election_id: "954"
+ id: "4682"
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
quickvote_normal:
- id: 1
- name: acetarium
- description: who is the winner?
- anonymous: 1
- startdate: 2007-08-22 12:00:00
- enddate: 2007-09-21 11:59:59
- active: 1
- type: QuickVote
- election_method: ssd
+ id: 1
+ name: acetarium
+ description: who is the winner?
+ anonymous: 1
+ startdate: 2007-08-22 12:00:00
+ enddate: 2010-09-21 11:59:59
+ active: 1
+ type: QuickVote
+ election_method: ssd
+
+quickvote_bernie:
+ id: 954
+ kiosk: 0
+ election_method: ssd
+ name: geekdomain
+ quickuser: "089f1ed263b01c73843b690799eddebb"
+ enddate: 2009-04-22 00:00:00
+ verifiable: 0
+ embed_custom_string:
+ anonymous: 1
+ early_results: 0
+ authenticated: 1
+ type: QuickVote
+ user_id:
+ notices: 0
+ description: Dominio per la mailing-list geek@
+ embeddable: 0
+ viewable: 0
+ startdate: 2009-03-17 04:37:28
+ active: 2
-quickvote_invalid_endtime:
- id: 2
- name: acetarium2
- description: who is the winner?
- anonymous: 1
- startdate: 2007-08-22 12:00:00
- enddate: 2003-09-21 11:59:59
- active: 1
- type: QuickVote
- election_method: ssd
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-first:
- id: 1
-another:
- id: 2
+<% i = 0 %>
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4678"
+ id: "222081"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4666"
+ id: "222080"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4674"
+ id: "222079"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4676"
+ id: "222078"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4668"
+ id: "222077"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4677"
+ id: "222076"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4671"
+ id: "222075"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4670"
+ id: "222074"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4675"
+ id: "222073"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4673"
+ id: "222072"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4672"
+ id: "222071"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4679"
+ id: "222070"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4681"
+ id: "222069"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4669"
+ id: "222068"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4682"
+ id: "222067"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4667"
+ id: "222066"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4680"
+ id: "222065"
+ vote_id: "29482"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4668"
+ id: "222198"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4681"
+ id: "222199"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4679"
+ id: "222200"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4673"
+ id: "222201"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4676"
+ id: "222202"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4674"
+ id: "222203"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4672"
+ id: "222204"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4680"
+ id: "222205"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4669"
+ id: "222206"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4678"
+ id: "222207"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4682"
+ id: "222208"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4670"
+ id: "222209"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4666"
+ id: "222210"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4677"
+ id: "222211"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4675"
+ id: "222212"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4671"
+ id: "222213"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4667"
+ id: "222214"
+ vote_id: "29494"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4669"
+ id: "222253"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4678"
+ id: "222254"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4676"
+ id: "222255"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4679"
+ id: "222256"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4670"
+ id: "222257"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4674"
+ id: "222258"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4675"
+ id: "222259"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4668"
+ id: "222260"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4682"
+ id: "222261"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4672"
+ id: "222262"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4680"
+ id: "222263"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4677"
+ id: "222264"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4673"
+ id: "222265"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4667"
+ id: "222266"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4681"
+ id: "222267"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4671"
+ id: "222268"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4666"
+ id: "222269"
+ vote_id: "29499"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4677"
+ id: "222389"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4667"
+ id: "222388"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4673"
+ id: "222387"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4670"
+ id: "222386"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4675"
+ id: "222385"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4678"
+ id: "222384"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4669"
+ id: "222383"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4681"
+ id: "222382"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4672"
+ id: "222381"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4671"
+ id: "222380"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4682"
+ id: "222379"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4668"
+ id: "222378"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4666"
+ id: "222377"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4676"
+ id: "222376"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4679"
+ id: "222375"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4680"
+ id: "222374"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4674"
+ id: "222373"
+ vote_id: "29519"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4666"
+ id: "222395"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4682"
+ id: "222396"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4673"
+ id: "222397"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4675"
+ id: "222398"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4679"
+ id: "222399"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222400"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4677"
+ id: "222401"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4678"
+ id: "222402"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4672"
+ id: "222403"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4681"
+ id: "222404"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4668"
+ id: "222405"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4670"
+ id: "222406"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4674"
+ id: "222407"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4671"
+ id: "222408"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4667"
+ id: "222409"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4680"
+ id: "222410"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4669"
+ id: "222411"
+ vote_id: "29521"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4672"
+ id: "222453"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4670"
+ id: "222452"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4668"
+ id: "222451"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4682"
+ id: "222450"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4674"
+ id: "222449"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4671"
+ id: "222448"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4666"
+ id: "222447"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4678"
+ id: "222446"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4679"
+ id: "222445"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4676"
+ id: "222444"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4667"
+ id: "222443"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4669"
+ id: "222442"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4673"
+ id: "222441"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4675"
+ id: "222440"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4681"
+ id: "222439"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4680"
+ id: "222438"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4677"
+ id: "222437"
+ vote_id: "29522"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4667"
+ id: "222454"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4676"
+ id: "222455"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4670"
+ id: "222456"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4671"
+ id: "222457"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4677"
+ id: "222458"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4672"
+ id: "222459"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4679"
+ id: "222460"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4674"
+ id: "222461"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4675"
+ id: "222462"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4682"
+ id: "222463"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4681"
+ id: "222464"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4680"
+ id: "222465"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4673"
+ id: "222466"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4669"
+ id: "222467"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4666"
+ id: "222468"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4678"
+ id: "222469"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4668"
+ id: "222470"
+ vote_id: "29524"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "222506"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4673"
+ id: "222505"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4680"
+ id: "222504"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4666"
+ id: "222503"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4675"
+ id: "222502"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4669"
+ id: "222501"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4677"
+ id: "222500"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4678"
+ id: "222499"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4667"
+ id: "222498"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4679"
+ id: "222497"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4682"
+ id: "222496"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4671"
+ id: "222495"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4672"
+ id: "222494"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4670"
+ id: "222493"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4681"
+ id: "222492"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4676"
+ id: "222491"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4668"
+ id: "222490"
+ vote_id: "29526"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4673"
+ id: "222543"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4681"
+ id: "222542"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4678"
+ id: "222541"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4676"
+ id: "222540"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4670"
+ id: "222539"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4674"
+ id: "222538"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4668"
+ id: "222537"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4675"
+ id: "222536"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4672"
+ id: "222535"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4669"
+ id: "222534"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4677"
+ id: "222533"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4679"
+ id: "222532"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4680"
+ id: "222531"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4667"
+ id: "222530"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4682"
+ id: "222529"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4666"
+ id: "222528"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4671"
+ id: "222527"
+ vote_id: "29527"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4675"
+ id: "222544"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4674"
+ id: "222545"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4666"
+ id: "222546"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4672"
+ id: "222547"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4680"
+ id: "222548"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4677"
+ id: "222549"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4673"
+ id: "222550"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4670"
+ id: "222551"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4671"
+ id: "222552"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4669"
+ id: "222553"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4678"
+ id: "222554"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4681"
+ id: "222555"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4682"
+ id: "222556"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4668"
+ id: "222557"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4679"
+ id: "222558"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4676"
+ id: "222559"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4667"
+ id: "222560"
+ vote_id: "29529"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4675"
+ id: "222561"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4666"
+ id: "222562"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4669"
+ id: "222563"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4681"
+ id: "222564"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4668"
+ id: "222565"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4680"
+ id: "222566"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4674"
+ id: "222567"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4670"
+ id: "222568"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4667"
+ id: "222569"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4678"
+ id: "222570"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4676"
+ id: "222571"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4671"
+ id: "222572"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4677"
+ id: "222573"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4673"
+ id: "222574"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4672"
+ id: "222575"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4682"
+ id: "222576"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4679"
+ id: "222577"
+ vote_id: "29530"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4668"
+ id: "222584"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4682"
+ id: "222585"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4680"
+ id: "222586"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4669"
+ id: "222587"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4675"
+ id: "222588"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4671"
+ id: "222589"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4667"
+ id: "222590"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4676"
+ id: "222591"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4670"
+ id: "222592"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4666"
+ id: "222593"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4674"
+ id: "222594"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4672"
+ id: "222595"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4673"
+ id: "222596"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4681"
+ id: "222597"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4679"
+ id: "222598"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4678"
+ id: "222599"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4677"
+ id: "222600"
+ vote_id: "29533"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4678"
+ id: "222637"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4672"
+ id: "222636"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4669"
+ id: "222635"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4676"
+ id: "222634"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4675"
+ id: "222633"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4682"
+ id: "222632"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4679"
+ id: "222631"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4666"
+ id: "222630"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4673"
+ id: "222629"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4667"
+ id: "222628"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4668"
+ id: "222627"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4671"
+ id: "222626"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4681"
+ id: "222625"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4680"
+ id: "222624"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4677"
+ id: "222623"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4670"
+ id: "222622"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4674"
+ id: "222621"
+ vote_id: "29535"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4669"
+ id: "222673"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4672"
+ id: "222672"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4666"
+ id: "222671"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4673"
+ id: "222670"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4682"
+ id: "222669"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4674"
+ id: "222668"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4679"
+ id: "222667"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4678"
+ id: "222665"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4667"
+ id: "222664"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222663"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4668"
+ id: "222662"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4677"
+ id: "222661"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4671"
+ id: "222660"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4670"
+ id: "222658"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4681"
+ id: "222657"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4675"
+ id: "222674"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4680"
+ id: "222675"
+ vote_id: "29537"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4675"
+ id: "222743"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4668"
+ id: "222742"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4676"
+ id: "222741"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4678"
+ id: "222740"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4681"
+ id: "222739"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4677"
+ id: "222738"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4673"
+ id: "222737"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4672"
+ id: "222736"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4669"
+ id: "222735"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4682"
+ id: "222734"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4679"
+ id: "222733"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4667"
+ id: "222732"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4674"
+ id: "222731"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4671"
+ id: "222730"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4670"
+ id: "222729"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4680"
+ id: "222728"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4666"
+ id: "222727"
+ vote_id: "29539"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4675"
+ id: "222726"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4679"
+ id: "222725"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4677"
+ id: "222724"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4667"
+ id: "222723"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4674"
+ id: "222722"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4680"
+ id: "222721"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4672"
+ id: "222720"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4682"
+ id: "222719"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4676"
+ id: "222718"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4666"
+ id: "222717"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4669"
+ id: "222716"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4673"
+ id: "222715"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4671"
+ id: "222714"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4668"
+ id: "222713"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4670"
+ id: "222712"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4678"
+ id: "222711"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4681"
+ id: "222710"
+ vote_id: "29540"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4673"
+ id: "222777"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4674"
+ id: "222776"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4669"
+ id: "222775"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4678"
+ id: "222774"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4666"
+ id: "222773"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4668"
+ id: "222772"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4670"
+ id: "222771"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4681"
+ id: "222770"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4677"
+ id: "222769"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4682"
+ id: "222768"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4671"
+ id: "222767"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222766"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4672"
+ id: "222765"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4679"
+ id: "222764"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4675"
+ id: "222763"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4667"
+ id: "222762"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4680"
+ id: "222761"
+ vote_id: "29541"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4678"
+ id: "222811"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4681"
+ id: "222810"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4682"
+ id: "222809"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4677"
+ id: "222808"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4672"
+ id: "222807"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4670"
+ id: "222806"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4673"
+ id: "222805"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4666"
+ id: "222804"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4669"
+ id: "222803"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4667"
+ id: "222802"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4675"
+ id: "222801"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4671"
+ id: "222800"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4680"
+ id: "222799"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4676"
+ id: "222798"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4679"
+ id: "222797"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4674"
+ id: "222796"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4668"
+ id: "222795"
+ vote_id: "29542"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "222845"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4673"
+ id: "222844"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4667"
+ id: "222843"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4669"
+ id: "222842"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4679"
+ id: "222841"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4672"
+ id: "222840"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4676"
+ id: "222839"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4675"
+ id: "222838"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4678"
+ id: "222837"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4668"
+ id: "222836"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4670"
+ id: "222835"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4680"
+ id: "222834"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4677"
+ id: "222833"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4666"
+ id: "222832"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4681"
+ id: "222831"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4682"
+ id: "222830"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4671"
+ id: "222829"
+ vote_id: "29543"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4676"
+ id: "222846"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4674"
+ id: "222847"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4682"
+ id: "222848"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4677"
+ id: "222849"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4678"
+ id: "222850"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4672"
+ id: "222851"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4671"
+ id: "222852"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4670"
+ id: "222853"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4666"
+ id: "222854"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4679"
+ id: "222855"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4673"
+ id: "222856"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4669"
+ id: "222857"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4668"
+ id: "222858"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4680"
+ id: "222859"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4667"
+ id: "222860"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4681"
+ id: "222861"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4675"
+ id: "222862"
+ vote_id: "29544"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4675"
+ id: "222896"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4677"
+ id: "222895"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4667"
+ id: "222894"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4672"
+ id: "222893"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4679"
+ id: "222892"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4673"
+ id: "222891"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4678"
+ id: "222890"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4669"
+ id: "222889"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4668"
+ id: "222888"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4670"
+ id: "222887"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4680"
+ id: "222886"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222885"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4674"
+ id: "222884"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4682"
+ id: "222883"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4671"
+ id: "222882"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4681"
+ id: "222881"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4666"
+ id: "222880"
+ vote_id: "29545"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4678"
+ id: "222930"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4666"
+ id: "222929"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4675"
+ id: "222928"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4681"
+ id: "222927"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4672"
+ id: "222926"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4671"
+ id: "222925"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4670"
+ id: "222924"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4673"
+ id: "222923"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4668"
+ id: "222922"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4682"
+ id: "222921"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4680"
+ id: "222920"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222919"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4669"
+ id: "222918"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4667"
+ id: "222917"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4679"
+ id: "222916"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4674"
+ id: "222915"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4677"
+ id: "222914"
+ vote_id: "29546"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4667"
+ id: "222931"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4672"
+ id: "222932"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4669"
+ id: "222933"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4679"
+ id: "222934"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4673"
+ id: "222935"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4678"
+ id: "222936"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4680"
+ id: "222937"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4681"
+ id: "222938"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4675"
+ id: "222939"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4666"
+ id: "222940"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4668"
+ id: "222941"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4676"
+ id: "222942"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4670"
+ id: "222943"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4671"
+ id: "222944"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4682"
+ id: "222945"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4677"
+ id: "222946"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "222947"
+ vote_id: "29547"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4667"
+ id: "223057"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4674"
+ id: "223056"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4682"
+ id: "223055"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4679"
+ id: "223054"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4670"
+ id: "223053"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4678"
+ id: "223052"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4671"
+ id: "223051"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4675"
+ id: "223050"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4677"
+ id: "223049"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4669"
+ id: "223048"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4666"
+ id: "223047"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4680"
+ id: "223046"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4668"
+ id: "223045"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4673"
+ id: "223044"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4681"
+ id: "223043"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4672"
+ id: "223042"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4676"
+ id: "223041"
+ vote_id: "29552"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4667"
+ id: "222965"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4671"
+ id: "222966"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4666"
+ id: "222967"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4668"
+ id: "222968"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4680"
+ id: "222969"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "222970"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4674"
+ id: "222971"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4681"
+ id: "222972"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4682"
+ id: "222973"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4672"
+ id: "222974"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4678"
+ id: "222975"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4673"
+ id: "222976"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4679"
+ id: "222977"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4669"
+ id: "222978"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4670"
+ id: "222979"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4675"
+ id: "222980"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4677"
+ id: "222981"
+ vote_id: "29549"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4678"
+ id: "223023"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4675"
+ id: "223022"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4672"
+ id: "223021"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4666"
+ id: "223020"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4676"
+ id: "223019"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4667"
+ id: "223018"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4671"
+ id: "223017"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4677"
+ id: "223016"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4669"
+ id: "223015"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4680"
+ id: "223014"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4681"
+ id: "223013"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4682"
+ id: "223012"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4679"
+ id: "223011"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4674"
+ id: "223010"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4670"
+ id: "223009"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4668"
+ id: "223008"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4673"
+ id: "223007"
+ vote_id: "29551"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "223094"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4669"
+ id: "223093"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4667"
+ id: "223092"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4682"
+ id: "223091"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4672"
+ id: "223090"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4678"
+ id: "223089"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4670"
+ id: "223088"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4676"
+ id: "223087"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4679"
+ id: "223086"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4675"
+ id: "223085"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4677"
+ id: "223084"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4671"
+ id: "223083"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4666"
+ id: "223082"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4673"
+ id: "223081"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4680"
+ id: "223080"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4681"
+ id: "223079"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4668"
+ id: "223078"
+ vote_id: "29553"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4672"
+ id: "223095"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4673"
+ id: "223096"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4681"
+ id: "223097"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4667"
+ id: "223098"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4679"
+ id: "223099"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4677"
+ id: "223100"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4678"
+ id: "223101"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4669"
+ id: "223102"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4666"
+ id: "223103"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4675"
+ id: "223104"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4682"
+ id: "223105"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4674"
+ id: "223106"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4671"
+ id: "223107"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4676"
+ id: "223108"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4680"
+ id: "223109"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4668"
+ id: "223110"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4670"
+ id: "223111"
+ vote_id: "29555"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "223157"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4670"
+ id: "223156"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4668"
+ id: "223155"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4673"
+ id: "223154"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4671"
+ id: "223153"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4669"
+ id: "223152"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4676"
+ id: "223151"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4666"
+ id: "223150"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4672"
+ id: "223149"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4667"
+ id: "223148"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4679"
+ id: "223147"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4678"
+ id: "223146"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4682"
+ id: "223145"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4681"
+ id: "223144"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4677"
+ id: "223143"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4675"
+ id: "223142"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4680"
+ id: "223141"
+ vote_id: "29560"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4667"
+ id: "223236"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4671"
+ id: "223237"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4666"
+ id: "223238"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4682"
+ id: "223239"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4678"
+ id: "223240"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4670"
+ id: "223241"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4680"
+ id: "223242"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4681"
+ id: "223243"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4672"
+ id: "223244"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4677"
+ id: "223245"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4669"
+ id: "223246"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4668"
+ id: "223247"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4679"
+ id: "223248"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4673"
+ id: "223249"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4676"
+ id: "223250"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4675"
+ id: "223251"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "223252"
+ vote_id: "29580"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4674"
+ id: "223666"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4668"
+ id: "223665"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4677"
+ id: "223664"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4672"
+ id: "223663"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4678"
+ id: "223662"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4679"
+ id: "223661"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4669"
+ id: "223660"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4670"
+ id: "223659"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4673"
+ id: "223658"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4671"
+ id: "223657"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4667"
+ id: "223656"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4676"
+ id: "223655"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4681"
+ id: "223654"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4666"
+ id: "223653"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4675"
+ id: "223652"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4682"
+ id: "223651"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4680"
+ id: "223650"
+ vote_id: "29644"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4679"
+ id: "224576"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4676"
+ id: "224577"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4678"
+ id: "224578"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4667"
+ id: "224579"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4671"
+ id: "224580"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4669"
+ id: "224581"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4673"
+ id: "224582"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4672"
+ id: "224583"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4682"
+ id: "224584"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4677"
+ id: "224585"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4666"
+ id: "224586"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4668"
+ id: "224587"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4681"
+ id: "224588"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4674"
+ id: "224589"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4670"
+ id: "224590"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4675"
+ id: "224591"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4680"
+ id: "224592"
+ vote_id: "29792"
+
+ranking_<%= i += 1 %>:
+ rank: "1"
+ candidate_id: "4673"
+ id: "226664"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "2"
+ candidate_id: "4679"
+ id: "226665"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "3"
+ candidate_id: "4677"
+ id: "226666"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "4"
+ candidate_id: "4680"
+ id: "226667"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "5"
+ candidate_id: "4674"
+ id: "226668"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "6"
+ candidate_id: "4669"
+ id: "226669"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "7"
+ candidate_id: "4676"
+ id: "226670"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "8"
+ candidate_id: "4671"
+ id: "226671"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "9"
+ candidate_id: "4670"
+ id: "226672"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "10"
+ candidate_id: "4682"
+ id: "226673"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "11"
+ candidate_id: "4678"
+ id: "226674"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "12"
+ candidate_id: "4667"
+ id: "226675"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "13"
+ candidate_id: "4672"
+ id: "226676"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "14"
+ candidate_id: "4675"
+ id: "226677"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "15"
+ candidate_id: "4681"
+ id: "226678"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "16"
+ candidate_id: "4668"
+ id: "226679"
+ vote_id: "30188"
+
+ranking_<%= i += 1 %>:
+ rank: "17"
+ candidate_id: "4666"
+ id: "226680"
+ vote_id: "30188"
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-first:
- id: 1
-another:
- id: 2
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-first:
- id: 1
-another:
- id: 2
+voter_29695:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "041423d72227d3c1f8e3fd7ccddb1b55"
+ id: "29695"
+ type: QuickVoter
+
+voter_29705:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "d9e093e70c29f1c6ded0e3f29f6f9980"
+ id: "29705"
+ type: QuickVoter
+
+voter_29710:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "5e9cce6c013b12989c603ad5d83de02c"
+ id: "29710"
+ type: QuickVoter
+
+voter_29730:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "2dc792d3b13d68919d2ddd84b3749791"
+ id: "29730"
+ type: QuickVoter
+
+voter_29732:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "e96f1ec33c8b5acbd5d2295803bc422c"
+ id: "29732"
+ type: QuickVoter
+
+voter_29733:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "e375b4f9a39f53a18bb9283ac0a731d5"
+ id: "29733"
+ type: QuickVoter
+
+voter_29735:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "281a8d479a5e81af88abaaac1110b023"
+ id: "29735"
+ type: QuickVoter
+
+voter_29737:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "939c97e84825aabb8d0ae5e972f8809d"
+ id: "29737"
+ type: QuickVoter
+
+voter_29738:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "b0a3bc6837f86d3f07a25024e5220e41"
+ id: "29738"
+ type: QuickVoter
+
+voter_29740:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "6e2872cb332f06f5ca2c91d414f8e8c8"
+ id: "29740"
+ type: QuickVoter
+
+voter_29741:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "d113128343272b6a87e1fc06d6b34962"
+ id: "29741"
+ type: QuickVoter
+
+voter_29744:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "39a8b55ef384f17fc03988432cecd15d"
+ id: "29744"
+ type: QuickVoter
+
+voter_29746:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "dda7c0cbefde0ae8a0aebd3315fb1393"
+ id: "29746"
+ type: QuickVoter
+
+voter_29748:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "579b757b3b7749f9ba8e339b1cfd55fb"
+ id: "29748"
+ type: QuickVoter
+
+voter_29750:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "a2f8650c070fa02b4ca7ce9adfa4d930"
+ id: "29750"
+ type: QuickVoter
+
+voter_29751:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "6c517b4a8c4b81418893a6be196f7a7a"
+ id: "29751"
+ type: QuickVoter
+
+voter_29752:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "43b589f18c485a59f0f055854badd258"
+ id: "29752"
+ type: QuickVoter
+
+voter_29753:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "54437209bd8b5328eaf61e3b1f5bea6a"
+ id: "29753"
+ type: QuickVoter
+
+voter_29754:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "b324c244725192c82cc37e01ba1c07fa"
+ id: "29754"
+ type: QuickVoter
+
+voter_29755:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "f60ad9b7d5cd915733f0a58301ce30c5"
+ id: "29755"
+ type: QuickVoter
+
+voter_29756:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "ea40b2a8ea7c3dfb1647f871d6b0b4a6"
+ id: "29756"
+ type: QuickVoter
+
+voter_29757:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "47091f1cf0aace51271aa32eea9a88ff"
+ id: "29757"
+ type: QuickVoter
+
+voter_29758:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "915decad16ed54111139c53de074621b"
+ id: "29758"
+ type: QuickVoter
+
+voter_29763:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "6935e1eaf0e1956f33f95050690d587b"
+ id: "29763"
+ type: QuickVoter
+
+voter_29760:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "60d1e174f8860f0fb22999aab28c6e2d"
+ id: "29760"
+ type: QuickVoter
+
+voter_29762:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "16c51c17d042041f9f593c437001444b"
+ id: "29762"
+ type: QuickVoter
+
+voter_29764:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "ff39bdbb7c485a146f2cf33efd3f6302"
+ id: "29764"
+ type: QuickVoter
+
+voter_29766:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "8d386d68158d776d8010dceeeb13cb23"
+ id: "29766"
+ type: QuickVoter
+
+voter_29771:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "83c8dc25e93a6d931817d270973aa087"
+ id: "29771"
+ type: QuickVoter
+
+voter_29791:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "a5d0e46cd73b1e105fe6ff89cfbf4600"
+ id: "29791"
+ type: QuickVoter
+
+voter_29855:
+ contacted: "0"
+ ipaddress: 127.0.0.1
+ election_id: "954"
+ session_id: "79dd005a4e95f729c1fdf90fa03e5b18"
+ id: "29855"
+ type: QuickVoter
+
+voter_30003:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "2b2afa6f59bb0fbf967627561a596c38"
+ id: "30003"
+ type: QuickVoter
+
+voter_30399:
+ contacted: "0"
+ ipaddress:
+ election_id: "954"
+ session_id: "747262cccc21f46dfcc24d72425f053c"
+ id: "30399"
+ type: QuickVoter
+
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+vote_29482:
+ voter_id: "29695"
+ confirmed: "1"
+ time: 2009-05-30 13:37:27
+ id: "29482"
+
+vote_29494:
+ voter_id: "29705"
+ confirmed: "0"
+ time:
+ id: "29494"
+
+vote_29499:
+ voter_id: "29710"
+ confirmed: "0"
+ time:
+ id: "29499"
+
+vote_29519:
+ voter_id: "29730"
+ confirmed: "1"
+ time: 2009-05-31 12:35:06
+ id: "29519"
+
+vote_29521:
+ voter_id: "29732"
+ confirmed: "0"
+ time:
+ id: "29521"
+
+vote_29522:
+ voter_id: "29733"
+ confirmed: "1"
+ time: 2009-05-31 14:27:44
+ id: "29522"
+
+vote_29524:
+ voter_id: "29735"
+ confirmed: "0"
+ time:
+ id: "29524"
+
+vote_29526:
+ voter_id: "29737"
+ confirmed: "1"
+ time: 2009-05-31 14:33:20
+ id: "29526"
+
+vote_29527:
+ voter_id: "29738"
+ confirmed: "1"
+ time: 2009-05-31 14:37:09
+ id: "29527"
+
+vote_29529:
+ voter_id: "29740"
+ confirmed: "0"
+ time:
+ id: "29529"
+
+vote_29530:
+ voter_id: "29741"
+ confirmed: "0"
+ time:
+ id: "29530"
+
+vote_29533:
+ voter_id: "29744"
+ confirmed: "0"
+ time:
+ id: "29533"
+
+vote_29535:
+ voter_id: "29746"
+ confirmed: "1"
+ time: 2009-05-31 15:04:01
+ id: "29535"
+
+vote_29537:
+ voter_id: "29748"
+ confirmed: "1"
+ time: 2009-05-31 15:06:08
+ id: "29537"
+
+vote_29539:
+ voter_id: "29750"
+ confirmed: "1"
+ time: 2009-05-31 15:09:43
+ id: "29539"
+
+vote_29540:
+ voter_id: "29751"
+ confirmed: "1"
+ time: 2009-05-31 15:08:21
+ id: "29540"
+
+vote_29541:
+ voter_id: "29752"
+ confirmed: "1"
+ time: 2009-05-31 15:13:36
+ id: "29541"
+
+vote_29542:
+ voter_id: "29753"
+ confirmed: "1"
+ time: 2009-05-31 15:18:15
+ id: "29542"
+
+vote_29543:
+ voter_id: "29754"
+ confirmed: "1"
+ time: 2009-05-31 15:52:37
+ id: "29543"
+
+vote_29544:
+ voter_id: "29755"
+ confirmed: "0"
+ time:
+ id: "29544"
+
+vote_29545:
+ voter_id: "29756"
+ confirmed: "1"
+ time: 2009-05-31 16:11:51
+ id: "29545"
+
+vote_29546:
+ voter_id: "29757"
+ confirmed: "1"
+ time: 2009-05-31 16:50:38
+ id: "29546"
+
+vote_29547:
+ voter_id: "29758"
+ confirmed: "0"
+ time:
+ id: "29547"
+
+vote_29552:
+ voter_id: "29763"
+ confirmed: "1"
+ time: 2009-05-31 17:54:15
+ id: "29552"
+
+vote_29549:
+ voter_id: "29760"
+ confirmed: "0"
+ time:
+ id: "29549"
+
+vote_29551:
+ voter_id: "29762"
+ confirmed: "1"
+ time: 2009-05-31 17:46:23
+ id: "29551"
+
+vote_29553:
+ voter_id: "29764"
+ confirmed: "1"
+ time: 2009-05-31 18:16:57
+ id: "29553"
+
+vote_29555:
+ voter_id: "29766"
+ confirmed: "0"
+ time:
+ id: "29555"
+
+vote_29560:
+ voter_id: "29771"
+ confirmed: "1"
+ time: 2009-05-31 19:52:38
+ id: "29560"
+
+vote_29580:
+ voter_id: "29791"
+ confirmed: "0"
+ time:
+ id: "29580"
+
+vote_29644:
+ voter_id: "29855"
+ confirmed: "1"
+ time: 2009-06-01 21:41:20
+ id: "29644"
+
+vote_29792:
+ voter_id: "30003"
+ confirmed: "0"
+ time:
+ id: "29792"
+
+vote_30188:
+ voter_id: "30399"
+ confirmed: "0"
+ time:
+ id: "30188"
+
@response = ActionController::TestResponse.new
end
- # Replace this with your real tests.
def test_index
get :index
assert_response 302
end
def test_create_quickvote
- post(:create, {'commit' =>"Create Quickvote", 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}}, nil, {:candidate_names=>["foo", "bar", "foobar"]})
+ post(:create, {'commit' =>"Create Quickvote",
+ 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}},
+ nil, {:candidate_names=>["foo", "bar", "foobar"]})
assert_template "quickvote/success"
get :index, { 'ident' => "variable"}
assert_response :success
end
- def test_create_dupe_quickvote
- test_create_quickvote
- assert_raise(Test::Unit::AssertionFailedError) do
- test_create_quickvote
- end
- end
+ #def test_create_dupe_quickvote
+ # test_create_quickvote
+ # assert_raise(Test::Unit::AssertionFailedError) do
+ # test_create_quickvote
+ # end
+ #end
def test_create_quickvote_badname
- post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => ["foo", "bar", "foobar"]})
+ post(:create, {'commit' => "Create Quickvote",
+ 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}},
+ nil, {:candidate_names => ["foo", "bar", "foobar"]})
assert_template "quickvote/_create_sidebar"
end
def test_create_quickvote_dupe_candidate
- post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => ["foo", "bar", "bar", "foobar"]})
+ post(:create, {'commit' => "Create Quickvote",
+ 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}},
+ nil, {:candidate_names => ["foo", "bar", "bar", "foobar"]})
assert_template "quickvote/_create_sidebar"
end
-
+
+ # TODO these should be testing for something better than a non-method
+ # error!
def test_create_quickvote_nil_candidate
- post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => nil})
- assert_template "quickvote/_create_sidebar"
- post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => []})
- assert_template "quickvote/_create_sidebar"
+ assert_raise(NoMethodError) do
+ post(:create, {'commit' => "Create Quickvote",
+ 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}},
+ nil, {:candidate_names => nil})
+ end
+
+ assert_raise(NoMethodError) do
+ post(:create, {'commit' => "Create Quickvote",
+ 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}},
+ nil, {:candidate_names => []})
+ end
end
def test_get_quickvote_nonexistent
5.times do |time|
get :index, { 'ident' => 'variable' }, { 'test_session_id' => (time+1)*50 }
assert_response :success
- post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} }, { 'test_session_id' => (time+1)*50 }
+ post :confirm,
+ { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} },
+ { 'test_session_id' => (time+1)*50 }
assert_template 'quickvote/thanks'
end
get :results, { 'ident' => 'variable' }
fixtures :elections, :candidates
def setup
- @quickvote_normal = QuickVote.find(1)
- end
-
- def test_create_update_delete_quickvote_from_fixture
- assert_kind_of QuickVote, @quickvote_normal
- assert_equal 1, @quickvote_normal.id
- assert_equal 'acetarium', @quickvote_normal.name
- assert_equal 'who is the winner?', @quickvote_normal.description
- #assert_equal QuickVote, @quickvote_normal.type
- assert_equal 'ssd', @quickvote_normal.election_method
- assert_equal '2007-08-22 12:00:00', @quickvote_normal.startdate_before_type_cast
- assert_equal '2007-09-21 11:59:59', @quickvote_normal.enddate_before_type_cast
-
- # make sure that the each of the three andidates
- (1..3).each do |i|
- assert @quickvote_normal.candidates.include?(Candidate.find(i))
+ # create the quickvote
+ @qv = QuickVote.find(1)
+
+ # create candidates
+ @candidates = ['mako', 'mika', 'bettamax']
+ @candidates.each do |name|
+ @qv.candidates << Candidate.new({:name => name})
end
+ @qv.save
+ end
+
+ def test_add_remove_candidates
+ # make sure the names are right
+ assert_equal 3, @qv.candidates.length
+ assert_equal @candidates.sort,
+ @qv.candidates.collect {|c| c.name}.sort
+
+ # add one candidate
+ @qv.candidates << Candidate.new({:name => 'erik'})
+ assert @qv.save
+ assert @qv.reload
+ assert_equal 4, @qv.candidates.length
+ assert_equal (@candidates + ['erik']).sort,
+ @qv.candidates.collect {|c| c.name}.sort
+
+ # drop erik and try again
+ @qv.candidates = \
+ @qv.candidates.select {|c| c.name != 'erik'}
+ assert @qv.save
+ assert @qv.reload
+ assert_equal 3, @qv.candidates.length
+ assert_equal @candidates.sort,
+ @qv.candidates.collect {|c| c.name}.sort
+ end
+
+ def test_create_update_quickvote
+ assert_kind_of QuickVote, @qv
+ assert_equal 1, @qv.id
+ assert_equal 'acetarium', @qv.name
+ assert_equal 'who is the winner?', @qv.description
+ assert_equal 'ssd', @qv.election_method
+ assert_equal '2007-08-22 12:00:00', @qv.startdate_before_type_cast
+ assert_equal '2010-09-21 11:59:59', @qv.enddate_before_type_cast
+
+ # should be set by default default results
+ assert_equal false, @qv.early_results
+ assert_equal false, @qv.kiosk
+ assert_equal true, @qv.authenticated
+ assert_equal false, @qv.embeddable
+ assert_equal true, @qv.verifiable
# update and save
- @quickvote_normal.name = 'foobar'
- assert @quickvote_normal.save,
- @quickvote_normal.errors.full_messages.join("; ")
+ @qv.name = 'foobar'
+ assert @qv.save,
+ @qv.errors.full_messages.join("; ")
- @quickvote_normal.reload
- assert_equal 'foobar', @quickvote_normal.name
+ @qv.reload
+ assert_equal 'foobar', @qv.name
end
def test_create_invalid_enddate
- qv = QuickVote.find(2)
- assert_equal qv.save, false, "created vote with invalid enddate"
+ @qv.enddate = '2003-09-21 11:59:59 '
+ assert_equal @qv.save, false, "created vote with invalid enddate"
+ assert @qv.reload
+ end
+
+ def test_add_voters
+ 50.times do
+ voter = QuickVoter.new
+ voter.election = @qv
+ voter.session_id = UniqueTokenGenerator.new(20).token
+
+ voter.vote = Vote.new
+ assert voter.save
+ voter.vote.set_defaults!
+ assert_nil voter.vote.confirm!
+ assert voter.reload
+ end
+ assert @qv.save
+ assert_equal 50, @qv.voters.length
+ assert_equal 50, @qv.voters.collect {|v| v.vote}.length
+ assert_equal 50, @qv.voters.select {|v| v.vote.confirmed?}.length
+ end
+
+ def test_build_results
+ end
+
+ def test_bernie_qv
+ assert qvb = QuickVote.find(954)
+ assert_kind_of QuickVote, qvb
+ assert_equal 17, qvb.candidates.length
end
+
+ def test_for_reload_errors
+ qvb = QuickVote.find(954)
+ qvb.save
+ qvb.reload
+
+ assert_equal (4666..4682).to_a, qvb.candidates.collect {|c| c.id}.sort
+ end
+
end
# Replace this with your real tests.
def test_truth
- assert_kind_of Ranking, rankings(:first)
end
end
# Replace this with your real tests.
def test_truth
- assert_kind_of Voter, voters(:first)
end
end
--- /dev/null
+test/amazon_s3.yml
+test/rackspace_cloudfiles.yml
+test/debug.log
+* Apr 17 2008 *
+* amazon_s3.yml is now passed through ERB before being passed to AWS::S3 [François Beausoleil]
+
+* Mar 22 2008 *
+* Some tweaks to support Rails 2.0 and Rails 2.1 due to ActiveSupport::Callback changes.
+ Thanks to http://blog.methodmissing.com/2008/1/19/edge-callback-refactorings-attachment_fu/
+
+* Feb. 26, 2008 *
+* remove breakpoint from test_helper, makes test suite crazy (at least Rails 2+) [Rob Sanheim]
+* make S3 test really optional [Rob Sanheim]
+
* Nov 27, 2007 *
* Handle properly ImageScience thumbnails resized from a gif file [Matt Aimonetti]
* Save thumbnails file size properly when using ImageScience [Matt Aimonetti]
* make #current_data public with db_file and s3 backends [ebryn]
* oops, actually svn add the files for s3 backend. [Jeffrey Hardy]
* experimental s3 support, egad, no tests.... [Jeffrey Hardy]
-* doh, fix a few bad references to ActsAsAttachment [sixty4bit]
\ No newline at end of file
+* doh, fix a few bad references to ActsAsAttachment [sixty4bit]
--- /dev/null
+Copyright (c) 2009 rick olson
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
attachment_fu facilitates file uploads in Ruby on Rails. There are a few storage options for the actual file data, but the plugin always at a minimum stores metadata for each file in the database.
-There are three storage options for files uploaded through attachment_fu:
+There are four storage options for files uploaded through attachment_fu:
File system
Database file
Amazon S3
+ Rackspace (Mosso) Cloud Files
-Each method of storage many options associated with it that will be covered in the following section. Something to note, however, is that the Amazon S3 storage requires you to modify config/amazon_s3.yml and the Database file storage requires an extra table.
+Each method of storage many options associated with it that will be covered in the following section. Something to note, however, is that the Amazon S3 storage requires you to modify config/amazon_s3.yml, the Rackspace Cloud Files storage requires you to modify config/rackspace_cloudfiles.yml, and the Database file storage requires an extra table.
attachment_fu models
# This option need only be included if you want thumbnailing.
:thumbnail_class # Set which model class to use for thumbnails.
# This current attachment class is used by default.
- :path_prefix # path to store the uploaded files.
- # Uses public/#{table_name} by default for the filesystem, and just #{table_name} for the S3 backend.
+ :path_prefix # Path to store the uploaded files in.
+ # Uses public/#{table_name} by default for the filesystem, and just #{table_name} for the S3 and Cloud Files backend.
# Setting this sets the :storage to :file_system.
+ :partition # Whether to partiton files in directories like /0000/0001/image.jpg. Default is true. Only applicable to the :file_system backend.
:storage # Specifies the storage system to use..
- # Defaults to :db_file. Options are :file_system, :db_file, and :s3.
+ # Defaults to :db_file. Options are :file_system, :db_file, :s3, and :cloud_files.
+ :cloudfront # If using S3 for storage, this option allows for serving the files via Amazon CloudFront.
+ # Defaults to false.
:processor # Sets the image processor to use for resizing of the attached image.
# Options include ImageScience, Rmagick, and MiniMagick. Default is whatever is installed.
+ :uuid_primary_key # If your model's primary key is a 128-bit UUID in hexadecimal format, then set this to true.
+ :association_options # attachment_fu automatically defines associations with thumbnails with has_many and belongs_to. If there are any additional options that you want to pass to these methods, then specify them here.
Examples:
has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
has_attachment :storage => :file_system, :path_prefix => 'public/files'
has_attachment :storage => :file_system, :path_prefix => 'public/files',
- :content_type => :image, :resize_to => [50,50]
+ :content_type => :image, :resize_to => [50,50], :partition => false
has_attachment :storage => :file_system, :path_prefix => 'public/files',
:thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
has_attachment :storage => :s3
+ has_attachment :store => :s3, :cloudfront => true
+ has_attachment :storage => :cloud_files
validates_as_attachment
This method prevents files outside of the valid range (:min_size to :max_size, or the :size range) from being saved. It does not however, halt the upload of such files. They will be uploaded into memory regardless of size before validation.
Example:
<%= form.file_field :uploaded_data %>
-Displaying uploaded images is made easy by the public_filename method of the ActiveRecord attachment objects using file system and s3 storage.
+Displaying uploaded images is made easy by the public_filename method of the ActiveRecord attachment objects using file system, s3, and Cloud Files storage.
public_filename(thumbnail = nil)
Returns the public path to the file. If a thumbnail prefix is specified it will return the public file path to the corresponding thumbnail.
render :action => :new
end
end
+
+attachement_fu scripting
+====================================
+
+You may wish to import a large number of images or attachments.
+The following example shows how to upload a file from a script.
+
+#!/usr/bin/env ./script/runner
+
+# required to use ActionController::TestUploadedFile
+require 'action_controller'
+require 'action_controller/test_process.rb'
+
+path = "./public/images/x.jpg"
+
+# mimetype is a string like "image/jpeg". One way to get the mimetype for a given file on a UNIX system
+# mimetype = `file -ib #{path}`.gsub(/\n/,"")
+
+mimetype = "image/jpeg"
+
+# This will "upload" the file at path and create the new model.
+@attachable = AttachmentMetadataModel.new(:uploaded_data => ActionController::TestUploadedFile.new(path, mimetype))
+@attachable.save
bucket_name: appname_development
access_key_id:
secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
test:
bucket_name: appname_test
access_key_id:
secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
production:
bucket_name: appname
access_key_id:
secret_access_key:
+ distribution_domain: XXXX.cloudfront.net
require 'geometry'
ActiveRecord::Base.send(:extend, Technoweenie::AttachmentFu::ActMethods)
Technoweenie::AttachmentFu.tempfile_path = ATTACHMENT_FU_TEMPFILE_PATH if Object.const_defined?(:ATTACHMENT_FU_TEMPFILE_PATH)
-FileUtils.mkdir_p Technoweenie::AttachmentFu.tempfile_path
\ No newline at end of file
+FileUtils.mkdir_p Technoweenie::AttachmentFu.tempfile_path
+
+$:.unshift(File.dirname(__FILE__) + '/vendor')
s3_config = File.dirname(__FILE__) + '/../../../config/amazon_s3.yml'
FileUtils.cp File.dirname(__FILE__) + '/amazon_s3.yml.tpl', s3_config unless File.exist?(s3_config)
+cloudfiles_config = File.dirname(__FILE__) + '/../../../config/rackspace_cloudfiles.yml'
+FileUtils.cp File.dirname(__FILE__) + '/rackspace_cloudfiles.yml.tpl', cloudfiles_config unless File.exist?(cloudfiles_config)
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
\ No newline at end of file
end
# Construct an object from a geometry string
- RE = /\A(\d*)(?:x(\d+))?([-+]\d+)?([-+]\d+)?([%!<>@]?)\Z/
+ RE = /\A(\d*)(?:x(\d+)?)?([-+]\d+)?([-+]\d+)?([%!<>@]?)\Z/
def self.from_s(str)
raise(ArgumentError, "no geometry string specified") unless str
new_height = orig_height if @flag && orig_height.send(@flag, new_height)
end
- [new_width, new_height].collect! { |v| v.round }
+ [new_width, new_height].collect! { |v| [v.round, 1].max }
end
end
geometry = Geometry.from_s(geometry) if geometry.is_a?(String)
geometry.new_dimensions_for first, last
end
-end
\ No newline at end of file
+end
module Technoweenie # :nodoc:
module AttachmentFu # :nodoc:
- @@default_processors = %w(ImageScience Rmagick MiniMagick)
+ @@default_processors = %w(ImageScience Rmagick MiniMagick Gd2 CoreImage)
@@tempfile_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
- @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
+ @@content_types = [
+ 'image/jpeg',
+ 'image/pjpeg',
+ 'image/jpg',
+ 'image/gif',
+ 'image/png',
+ 'image/x-png',
+ 'image/jpg',
+ 'image/x-ms-bmp',
+ 'image/bmp',
+ 'image/x-bmp',
+ 'image/x-bitmap',
+ 'image/x-xbitmap',
+ 'image/x-win-bitmap',
+ 'image/x-windows-bmp',
+ 'image/ms-bmp',
+ 'application/bmp',
+ 'application/x-bmp',
+ 'application/x-win-bitmap',
+ 'application/preview',
+ 'image/jp_',
+ 'application/jpg',
+ 'application/x-jpg',
+ 'image/pipeg',
+ 'image/vnd.swiftview-jpeg',
+ 'image/x-xbitmap',
+ 'application/png',
+ 'application/x-png',
+ 'image/gi_',
+ 'image/x-citrix-pjpeg'
+ ]
mattr_reader :content_types, :tempfile_path, :default_processors
mattr_writer :tempfile_path
class AttachmentError < StandardError; end
module ActMethods
- # Options:
+ # Options:
# * <tt>:content_type</tt> - Allowed content types. Allows all by default. Use :image to allow all standard image types.
# * <tt>:min_size</tt> - Minimum size allowed. 1 byte is the default.
# * <tt>:max_size</tt> - Maximum size allowed. 1.megabyte is the default.
# * <tt>:thumbnail_class</tt> - Set what class to use for thumbnails. This attachment class is used by default.
# * <tt>:path_prefix</tt> - path to store the uploaded files. Uses public/#{table_name} by default for the filesystem, and just #{table_name}
# for the S3 backend. Setting this sets the :storage to :file_system.
+
# * <tt>:storage</tt> - Use :file_system to specify the attachment data is stored with the file system. Defaults to :db_system.
+ # * <tt>:cloundfront</tt> - Set to true if you are using S3 storage and want to serve the files through CloudFront. You will need to
+ # set a distribution domain in the amazon_s3.yml config file. Defaults to false
+ # * <tt>:bucket_key</tt> - Use this to specify a different bucket key other than :bucket_name in the amazon_s3.yml file. This allows you to use
+ # different buckets for different models. An example setting would be :image_bucket and the you would need to define the name of the corresponding
+ # bucket in the amazon_s3.yml file.
+
+ # * <tt>:keep_profile</tt> By default image EXIF data will be stripped to minimize image size. For small thumbnails this proivides important savings. Picture quality is not affected. Set to false if you want to keep the image profile as is. ImageScience will allways keep EXIF data.
#
# Examples:
# has_attachment :max_size => 1.kilobyte
# has_attachment :content_type => ['application/pdf', :image], :resize_to => 'x50'
# has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
# has_attachment :storage => :file_system, :path_prefix => 'public/files'
- # has_attachment :storage => :file_system, :path_prefix => 'public/files',
+ # has_attachment :storage => :file_system, :path_prefix => 'public/files',
# :content_type => :image, :resize_to => [50,50]
# has_attachment :storage => :file_system, :path_prefix => 'public/files',
# :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
options[:thumbnails] ||= {}
options[:thumbnail_class] ||= self
options[:s3_access] ||= :public_read
+ options[:cloudfront] ||= false
options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
-
+
unless options[:thumbnails].is_a?(Hash)
raise ArgumentError, ":thumbnails option should be a hash: e.g. :thumbnails => { :foo => '50x50' }"
end
-
+
+ extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods)
+ include InstanceMethods unless included_modules.include?(InstanceMethods)
+
+ parent_options = attachment_options || {}
# doing these shenanigans so that #attachment_options is available to processors and backends
- class_inheritable_accessor :attachment_options
self.attachment_options = options
- # only need to define these once on a class
- unless included_modules.include?(InstanceMethods)
- attr_accessor :thumbnail_resize_options
+ attr_accessor :thumbnail_resize_options
- attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
- attachment_options[:path_prefix] ||= attachment_options[:file_system_path]
- if attachment_options[:path_prefix].nil?
- attachment_options[:path_prefix] = attachment_options[:storage] == :s3 ? table_name : File.join("public", table_name)
+ attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
+ attachment_options[:storage] ||= parent_options[:storage]
+ attachment_options[:path_prefix] ||= attachment_options[:file_system_path]
+ if attachment_options[:path_prefix].nil?
+ attachment_options[:path_prefix] = case attachment_options[:storage]
+ when :s3 then table_name
+ when :cloud_files then table_name
+ else File.join("public", table_name)
end
- attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
+ end
+ attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
- with_options :foreign_key => 'parent_id' do |m|
- m.has_many :thumbnails, :class_name => attachment_options[:thumbnail_class].to_s
- m.belongs_to :parent, :class_name => base_class.to_s
+ association_options = { :foreign_key => 'parent_id' }
+ if attachment_options[:association_options]
+ association_options.merge!(attachment_options[:association_options])
+ end
+ with_options(association_options) do |m|
+ m.has_many :thumbnails, :class_name => "::#{attachment_options[:thumbnail_class]}"
+ m.belongs_to :parent, :class_name => "::#{base_class}" unless options[:thumbnails].empty?
+ end
+
+ storage_mod = Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
+ include storage_mod unless included_modules.include?(storage_mod)
+
+ case attachment_options[:processor]
+ when :none, nil
+ processors = Technoweenie::AttachmentFu.default_processors.dup
+ begin
+ if processors.any?
+ attachment_options[:processor] = processors.first
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
+ include processor_mod unless included_modules.include?(processor_mod)
+ end
+ rescue Object, Exception
+ raise unless load_related_exception?($!)
+
+ processors.shift
+ retry
end
- before_destroy :destroy_thumbnails
-
- before_validation :set_size_from_temp_path
- after_save :after_process_attachment
- after_destroy :destroy_file
- extend ClassMethods
- include InstanceMethods
- include Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
- case attachment_options[:processor]
- when :none
- when nil
- processors = Technoweenie::AttachmentFu.default_processors.dup
- begin
- if processors.any?
- attachment_options[:processor] = "#{processors.first}Processor"
- include Technoweenie::AttachmentFu::Processors.const_get(attachment_options[:processor])
- end
- rescue LoadError, MissingSourceFile
- processors.shift
- retry
- end
- else
- begin
- include Technoweenie::AttachmentFu::Processors.const_get("#{options[:processor].to_s.classify}Processor")
- rescue LoadError, MissingSourceFile
- puts "Problems loading #{options[:processor]}Processor: #{$!}"
- end
+ else
+ begin
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
+ include processor_mod unless included_modules.include?(processor_mod)
+ rescue Object, Exception
+ raise unless load_related_exception?($!)
+
+ puts "Problems loading #{options[:processor]}Processor: #{$!}"
end
- after_validation :process_attachment
+ end unless parent_options[:processor] # Don't let child override processor
+ end
+
+ def load_related_exception?(e) #:nodoc: implementation specific
+ case
+ when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError"
+ # We can't rescue CompilationError directly, as it is part of the RubyInline library.
+ # We must instead rescue RuntimeError, and check the class' name.
+ true
+ else
+ false
end
end
+ private :load_related_exception?
end
module ClassMethods
content_types.include?(content_type)
end
- # Callback after an image has been resized.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # after_resize do |record, img|
- # record.aspect_ratio = img.columns.to_f / img.rows.to_f
- # end
- # end
- def after_resize(&block)
- write_inheritable_array(:after_resize, [block])
+ def self.extended(base)
+ base.class_inheritable_accessor :attachment_options
+ base.before_destroy :destroy_thumbnails
+ base.before_validation :set_size_from_temp_path
+ base.after_save :after_process_attachment
+ base.after_destroy :destroy_file
+ base.after_validation :process_attachment
+ if defined?(::ActiveSupport::Callbacks)
+ base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
+ end
end
- # Callback after an attachment has been saved either to the file system or the DB.
- # Only called if the file has been changed, not necessarily if the record is updated.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # after_attachment_saved do |record|
- # ...
- # end
- # end
- def after_attachment_saved(&block)
- write_inheritable_array(:after_attachment_saved, [block])
- end
+ unless defined?(::ActiveSupport::Callbacks)
+ # Callback after an image has been resized.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # after_resize do |record, img|
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
+ # end
+ # end
+ def after_resize(&block)
+ write_inheritable_array(:after_resize, [block])
+ end
- # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # before_thumbnail_saved do |record, thumbnail|
- # ...
- # end
- # end
- def before_thumbnail_saved(&block)
- write_inheritable_array(:before_thumbnail_saved, [block])
+ # Callback after an attachment has been saved either to the file system or the DB.
+ # Only called if the file has been changed, not necessarily if the record is updated.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # after_attachment_saved do |record|
+ # ...
+ # end
+ # end
+ def after_attachment_saved(&block)
+ write_inheritable_array(:after_attachment_saved, [block])
+ end
+
+ # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # before_thumbnail_saved do |thumbnail|
+ # record = thumbnail.parent
+ # ...
+ # end
+ # end
+ def before_thumbnail_saved(&block)
+ write_inheritable_array(:before_thumbnail_saved, [block])
+ end
end
# Get the thumbnail class, which is the current attachment class by default.
FileUtils.cp file, tmp.path
end
end
-
+
# Writes the given data to a new tempfile, returning the closed tempfile.
def write_to_temp_file(data, temp_base_name)
returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
end
module InstanceMethods
+ def self.included(base)
+ base.define_callbacks *[:after_resize, :after_attachment_saved, :before_thumbnail_saved] if base.respond_to?(:define_callbacks)
+ end
+
# Checks whether the attachment's content type is an image content type
def image?
self.class.image?(content_type)
end
-
+
# Returns true/false if an attachment is thumbnailable. A thumbnailable attachment has an image content type and the parent_id attribute.
def thumbnailable?
image? && respond_to?(:parent_id) && parent_id.nil?
ext = s; ''
end
# ImageScience doesn't create gif thumbnails, only pngs
- ext.sub!(/gif$/, 'png') if attachment_options[:processor] == "ImageScienceProcessor"
+ ext.sub!(/gif$/, 'png') if attachment_options[:processor] == "ImageScience"
"#{basename}_#{thumbnail}#{ext}"
end
def create_or_update_thumbnail(temp_file, file_name_suffix, *size)
thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
returning find_or_initialize_thumbnail(file_name_suffix) do |thumb|
- thumb.attributes = {
- :content_type => content_type,
- :filename => thumbnail_name_for(file_name_suffix),
- :temp_path => temp_file,
+ thumb.temp_paths.unshift temp_file
+ thumb.send(:'attributes=', {
+ :content_type => content_type,
+ :filename => thumbnail_name_for(file_name_suffix),
:thumbnail_resize_options => size
- }
+ }, false)
callback_with_args :before_thumbnail_saved, thumb
thumb.save!
end
def content_type=(new_type)
write_attribute :content_type, new_type.to_s.strip
end
-
+
# Sanitizes a filename.
def filename=(new_name)
write_attribute :filename, sanitize_filename(new_name)
#
# TODO: Allow it to work with Merb tempfiles too.
def uploaded_data=(file_data)
- return nil if file_data.nil? || file_data.size == 0
- self.content_type = file_data.content_type
- self.filename = file_data.original_filename if respond_to?(:filename)
+ if file_data.respond_to?(:content_type)
+ return nil if file_data.size == 0
+ self.content_type = file_data.content_type
+ self.filename = file_data.original_filename if respond_to?(:filename)
+ else
+ return nil if file_data.blank? || file_data['size'] == 0
+ self.content_type = file_data['content_type']
+ self.filename = file_data['filename']
+ file_data = file_data['tempfile']
+ end
if file_data.is_a?(StringIO)
file_data.rewind
- self.temp_data = file_data.read
+ set_temp_data file_data.read
else
- self.temp_path = file_data.path
+ self.temp_paths.unshift file_data
end
end
p = temp_paths.first
p.respond_to?(:path) ? p.path : p.to_s
end
-
+
# Gets an array of the currently used temp paths. Defaults to a copy of #full_filename.
def temp_paths
- @temp_paths ||= (new_record? || !File.exist?(full_filename)) ? [] : [copy_to_temp_file(full_filename)]
- end
-
- # Adds a new temp_path to the array. This should take a string or a Tempfile. This class makes no
- # attempt to remove the files, so Tempfiles should be used. Tempfiles remove themselves when they go out of scope.
- # You can also use string paths for temporary files, such as those used for uploaded files in a web server.
- def temp_path=(value)
- temp_paths.unshift value
- temp_path
+ @temp_paths ||= (new_record? || !respond_to?(:full_filename) || !File.exist?(full_filename) ?
+ [] : [copy_to_temp_file(full_filename)])
end
# Gets the data from the latest temp file. This will read the file into memory.
def temp_data
save_attachment? ? File.read(temp_path) : nil
end
-
+
# Writes the given data to a Tempfile and adds it to the collection of temp files.
- def temp_data=(data)
- self.temp_path = write_to_temp_file data unless data.nil?
+ def set_temp_data(data)
+ temp_paths.unshift write_to_temp_file data unless data.nil?
end
-
+
# Copies the given file to a randomly named Tempfile.
def copy_to_temp_file(file)
self.class.copy_to_temp_file file, random_tempfile_filename
end
-
+
# Writes the given file to a randomly named Tempfile.
def write_to_temp_file(data)
self.class.write_to_temp_file data, random_tempfile_filename
end
-
+
# Stub for creating a temp file from the attachment data. This should be defined in the backend module.
def create_temp_file() end
end
protected
- # Generates a unique filename for a Tempfile.
+ # Generates a unique filename for a Tempfile.
def random_tempfile_filename
"#{rand Time.now.to_i}#{filename || 'attachment'}"
end
def sanitize_filename(filename)
+ return unless filename
returning filename.strip do |name|
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
name.gsub! /^.*(\\|\/)/, ''
-
+
# Finally, replace all non alphanumeric, underscore or periods with underscore
- name.gsub! /[^\w\.\-]/, '_'
+ name.gsub! /[^A-Za-z0-9\.\-]/, '_'
end
end
def attachment_attributes_valid?
[:size, :content_type].each do |attr_name|
enum = attachment_options[attr_name]
- errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
+ if Object.const_defined?(:I18n) # Rails >= 2.2
+ errors.add attr_name, I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) unless enum.nil? || enum.include?(send(attr_name))
+ else
+ errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
+ end
end
end
if (!respond_to?(:parent_id) || parent_id.nil?) && attachment_options[:resize_to] # parent image
resize_image(img, attachment_options[:resize_to])
elsif thumbnail_resize_options # thumbnail
- resize_image(img, thumbnail_resize_options)
+ resize_image(img, thumbnail_resize_options)
end
end
# Yanked from ActiveRecord::Callbacks, modified so I can pass args to the callbacks besides self.
# Only accept blocks, however
- def callback_with_args(method, arg = self)
- notify(method)
+ if ActiveSupport.const_defined?(:Callbacks)
+ # Rails 2.1 and beyond!
+ def callback_with_args(method, arg = self)
+ notify(method)
+
+ result = run_callbacks(method, { :object => arg }) { |result, object| result == false }
- result = nil
- callbacks_for(method).each do |callback|
- result = callback.call(self, arg)
- return false if result == false
+ if result != false && respond_to_without_attributes?(method)
+ result = send(method)
+ end
+
+ result
end
- return result
+ def run_callbacks(kind, options = {}, &block)
+ options.reverse_merge!( :object => self )
+ self.class.send("#{kind}_callback_chain").run(options[:object], options, &block)
+ end
+ else
+ # Rails 2.0
+ def callback_with_args(method, arg = self)
+ notify(method)
+
+ result = nil
+ callbacks_for(method).each do |callback|
+ result = callback.call(self, arg)
+ return false if result == false
+ end
+ result
+ end
end
-
+
# Removes the thumbnails for the attachment, if it has any
def destroy_thumbnails
self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
--- /dev/null
+module Technoweenie # :nodoc:
+ module AttachmentFu # :nodoc:
+ module Backends
+ # = CloudFiles Storage Backend
+ #
+ # Enables use of {Rackspace Cloud Files}[http://www.mosso.com/cloudfiles.jsp] as a storage mechanism
+ #
+ # Based heavily on the Amazon S3 backend.
+ #
+ # == Requirements
+ #
+ # Requires the {Cloud Files Gem}[http://www.mosso.com/cloudfiles.jsp] by Rackspace
+ #
+ # == Configuration
+ #
+ # Configuration is done via <tt>RAILS_ROOT/config/rackspace_cloudfiles.yml</tt> and is loaded according to the <tt>RAILS_ENV</tt>.
+ # The minimum connection options that you must specify are a container name, your Mosso login name and your Mosso API key.
+ # You can sign up for Cloud Files and get access keys by visiting https://www.mosso.com/buy.htm
+ #
+ # Example configuration (RAILS_ROOT/config/rackspace_cloudfiles.yml)
+ #
+ # development:
+ # container_name: appname_development
+ # username: <your key>
+ # api_key: <your key>
+ #
+ # test:
+ # container_name: appname_test
+ # username: <your key>
+ # api_key: <your key>
+ #
+ # production:
+ # container_name: appname
+ # username: <your key>
+ # apik_key: <your key>
+ #
+ # You can change the location of the config path by passing a full path to the :cloudfiles_config_path option.
+ #
+ # has_attachment :storage => :cloud_files, :cloudfiles_config_path => (RAILS_ROOT + '/config/mosso.yml')
+ #
+ # === Required configuration parameters
+ #
+ # * <tt>:username</tt> - The username for your Rackspace Cloud (Mosso) account. Provided by Rackspace.
+ # * <tt>:secret_access_key</tt> - The api key for your Rackspace Cloud account. Provided by Rackspace.
+ # * <tt>:container_name</tt> - The name of a container in your Cloud Files account.
+ #
+ # If any of these required arguments is missing, a AuthenticationException will be raised from CloudFiles::Connection.
+ #
+ # == Usage
+ #
+ # To specify Cloud Files as the storage mechanism for a model, set the acts_as_attachment <tt>:storage</tt> option to <tt>:cloud_files/tt>.
+ #
+ # class Photo < ActiveRecord::Base
+ # has_attachment :storage => :cloud_files
+ # end
+ #
+ # === Customizing the path
+ #
+ # By default, files are prefixed using a pseudo hierarchy in the form of <tt>:table_name/:id</tt>, which results
+ # in Cloud Files object names (and urls) that look like: http://:server/:container_name/:table_name/:id/:filename with :table_name
+ # representing the customizable portion of the path. You can customize this prefix using the <tt>:path_prefix</tt>
+ # option:
+ #
+ # class Photo < ActiveRecord::Base
+ # has_attachment :storage => :cloud_files, :path_prefix => 'my/custom/path'
+ # end
+ #
+ # Which would result in public URLs like <tt>http(s)://:server/:container_name/my/custom/path/:id/:filename.</tt>
+ #
+ # === Permissions
+ #
+ # File permisisons are determined by the permissions of the container. At present, the options are public (and distributed
+ # by the Limelight CDN), and private (only available to your login)
+ #
+ # === Other options
+ #
+ # Of course, all the usual configuration options apply, such as content_type and thumbnails:
+ #
+ # class Photo < ActiveRecord::Base
+ # has_attachment :storage => :cloud_files, :content_type => ['application/pdf', :image], :resize_to => 'x50'
+ # has_attachment :storage => :cloud_files, :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
+ # end
+ #
+ # === Accessing Cloud Files URLs
+ #
+ # You can get an object's public URL using the cloudfiles_url accessor. For example, assuming that for your postcard app
+ # you had a container name like 'postcard_world_development', and an attachment model called Photo:
+ #
+ # @postcard.cloudfiles_url # => http://cdn.cloudfiles.mosso.com/c45182/uploaded_files/20/london.jpg
+ #
+ # The resulting url is in the form: http://:server/:container_name/:table_name/:id/:file.
+ # The optional thumbnail argument will output the thumbnail's filename (if any).
+ #
+ # Additionally, you can get an object's base path relative to the container root using
+ # <tt>base_path</tt>:
+ #
+ # @photo.file_base_path # => uploaded_files/20
+ #
+ # And the full path (including the filename) using <tt>full_filename</tt>:
+ #
+ # @photo.full_filename # => uploaded_files/20/london.jpg
+ #
+ # Niether <tt>base_path</tt> or <tt>full_filename</tt> include the container name as part of the path.
+ # You can retrieve the container name using the <tt>container_name</tt> method.
+ module CloudFileBackend
+ class RequiredLibraryNotFoundError < StandardError; end
+ class ConfigFileNotFoundError < StandardError; end
+
+ def self.included(base) #:nodoc:
+ mattr_reader :container_name, :cloudfiles_config
+
+ begin
+ require 'cloudfiles'
+ rescue LoadError
+ raise RequiredLibraryNotFoundError.new('CloudFiles could not be loaded')
+ end
+
+ begin
+ @@cloudfiles_config_path = base.attachment_options[:cloudfiles_config_path] || (RAILS_ROOT + '/config/rackspace_cloudfiles.yml')
+ @@cloudfiles_config = @@cloudfiles_config = YAML.load(ERB.new(File.read(@@cloudfiles_config_path)).result)[RAILS_ENV].symbolize_keys
+ rescue
+ #raise ConfigFileNotFoundError.new('File %s not found' % @@cloudfiles_config_path)
+ end
+
+ @@container_name = @@cloudfiles_config[:container_name]
+ @@cf = CloudFiles::Connection.new(@@cloudfiles_config[:username], @@cloudfiles_config[:api_key])
+ @@container = @@cf.container(@@container_name)
+
+ base.before_update :rename_file
+ end
+
+ # Overwrites the base filename writer in order to store the old filename
+ def filename=(value)
+ @old_filename = filename unless filename.nil? || @old_filename
+ write_attribute :filename, sanitize_filename(value)
+ end
+
+ # The attachment ID used in the full path of a file
+ def attachment_path_id
+ ((respond_to?(:parent_id) && parent_id) || id).to_s
+ end
+
+ # The pseudo hierarchy containing the file relative to the container name
+ # Example: <tt>:table_name/:id</tt>
+ def base_path
+ File.join(attachment_options[:path_prefix], attachment_path_id)
+ end
+
+ # The full path to the file relative to the container name
+ # Example: <tt>:table_name/:id/:filename</tt>
+ def full_filename(thumbnail = nil)
+ File.join(base_path, thumbnail_name_for(thumbnail))
+ end
+
+ # All public objects are accessible via a GET request to the Cloud Files servers. You can generate a
+ # url for an object using the cloudfiles_url method.
+ #
+ # @photo.cloudfiles_url
+ #
+ # The resulting url is in the CDN URL for the object
+ #
+ # The optional thumbnail argument will output the thumbnail's filename (if any).
+ #
+ # If you are trying to get the URL for a nonpublic container, nil will be returned.
+ def cloudfiles_url(thumbnail = nil)
+ if @@container.public?
+ File.join(@@container.cdn_url, full_filename(thumbnail))
+ else
+ nil
+ end
+ end
+ alias :public_filename :cloudfiles_url
+
+ def create_temp_file
+ write_to_temp_file current_data
+ end
+
+ def current_data
+ @@container.get_object(full_filename).data
+ end
+
+ protected
+ # Called in the after_destroy callback
+ def destroy_file
+ @@container.delete_object(full_filename)
+ end
+
+ def rename_file
+ # Cloud Files doesn't rename right now, so we'll just nuke.
+ return unless @old_filename && @old_filename != filename
+
+ old_full_filename = File.join(base_path, @old_filename)
+ @@container.delete_object(old_full_filename)
+
+ @old_filename = nil
+ true
+ end
+
+ def save_to_storage
+ if save_attachment?
+ @object = @@container.create_object(full_filename)
+ @object.write((temp_path ? File.open(temp_path) : temp_data))
+ end
+
+ @old_filename = nil
+ true
+ end
+ end
+ end
+ end
+end
-require 'ftools'
+require 'fileutils'
+require 'digest/sha2'
+
module Technoweenie # :nodoc:
module AttachmentFu # :nodoc:
module Backends
# The attachment ID used in the full path of a file
def attachment_path_id
- ((respond_to?(:parent_id) && parent_id) || id).to_i
+ ((respond_to?(:parent_id) && parent_id) || id) || 0
end
- # overrwrite this to do your own app-specific partitioning.
- # you can thank Jamis Buck for this: http://www.37signals.com/svn/archives2/id_partitioning.php
+ # Partitions the given path into an array of path components.
+ #
+ # For example, given an <tt>*args</tt> of ["foo", "bar"], it will return
+ # <tt>["0000", "0001", "foo", "bar"]</tt> (assuming that that id returns 1).
+ #
+ # If the id is not an integer, then path partitioning will be performed by
+ # hashing the string value of the id with SHA-512, and splitting the result
+ # into 4 components. If the id a 128-bit UUID (as set by :uuid_primary_key => true)
+ # then it will be split into 2 components.
+ #
+ # To turn this off entirely, set :partition => false.
def partitioned_path(*args)
- ("%08d" % attachment_path_id).scan(/..../) + args
+ if respond_to?(:attachment_options) && attachment_options[:partition] == false
+ args
+ elsif attachment_options[:uuid_primary_key]
+ # Primary key is a 128-bit UUID in hex format. Split it into 2 components.
+ path_id = attachment_path_id.to_s
+ component1 = path_id[0..15] || "-"
+ component2 = path_id[16..-1] || "-"
+ [component1, component2] + args
+ else
+ path_id = attachment_path_id
+ if path_id.is_a?(Integer)
+ # Primary key is an integer. Split it after padding it with 0.
+ ("%08d" % path_id).scan(/..../) + args
+ else
+ # Primary key is a String. Hash it, then split it into 4 components.
+ hash = Digest::SHA512.hexdigest(path_id.to_s)
+ [hash[0..31], hash[32..63], hash[64..95], hash[96..127]] + args
+ end
+ end
end
# Gets the public path to the file
if save_attachment?
# TODO: This overwrites the file if it exists, maybe have an allow_overwrite option?
FileUtils.mkdir_p(File.dirname(full_filename))
- File.cp(temp_path, full_filename)
- File.chmod(attachment_options[:chmod] || 0644, full_filename)
+ FileUtils.cp(temp_path, full_filename)
+ FileUtils.chmod(attachment_options[:chmod] || 0644, full_filename)
end
@old_filename = nil
true
end
end
end
-end
\ No newline at end of file
+end
# If you don't already have your access keys, all you need to sign up for the S3 service is an account at Amazon.
# You can sign up for S3 and get access keys by visiting http://aws.amazon.com/s3.
#
+ # If you wish to use Amazon CloudFront to serve the files, you can also specify a distibution domain for the bucket.
+ # To read more about CloudFront, visit http://aws.amazon.com/cloudfront
+ #
# Example configuration (RAILS_ROOT/config/amazon_s3.yml)
- #
+ #
# development:
# bucket_name: appname_development
# access_key_id: <your key>
# secret_access_key: <your key>
- #
+ # distribution_domain: XXXX.cloudfront.net
+ #
# test:
# bucket_name: appname_test
# access_key_id: <your key>
# secret_access_key: <your key>
- #
+ # distribution_domain: XXXX.cloudfront.net
+ #
# production:
# bucket_name: appname
# access_key_id: <your key>
# secret_access_key: <your key>
+ # distribution_domain: XXXX.cloudfront.net
#
# You can change the location of the config path by passing a full path to the :s3_config_path option.
#
# * <tt>:server</tt> - The server to make requests to. Defaults to <tt>s3.amazonaws.com</tt>.
# * <tt>:port</tt> - The port to the requests should be made on. Defaults to 80 or 443 if <tt>:use_ssl</tt> is set.
# * <tt>:use_ssl</tt> - If set to true, <tt>:port</tt> will be implicitly set to 443, unless specified otherwise. Defaults to false.
+ # * <tt>:distribution_domain</tt> - The CloudFront distribution domain for the bucket. This can either be the assigned
+ # distribution domain (ie. XXX.cloudfront.net) or a chosen domain using a CNAME. See CloudFront for more details.
#
# == Usage
#
#
# Which would result in URLs like <tt>http(s)://:server/:bucket_name/my/custom/path/:id/:filename.</tt>
#
+ # === Using different bucket names on different models
+ #
+ # By default the bucket name that the file will be stored to is the one specified by the
+ # <tt>:bucket_name</tt> key in the amazon_s3.yml file. You can use the <tt>:bucket_key</tt> option
+ # to overide this behavior on a per model basis. For instance if you want a bucket that will hold
+ # only Photos you can do this:
+ #
+ # class Photo < ActiveRecord::Base
+ # has_attachment :storage => :s3, :bucket_key => :photo_bucket_name
+ # end
+ #
+ # And then your amazon_s3.yml file needs to look like this.
+ #
+ # development:
+ # bucket_name: appname_development
+ # access_key_id: <your key>
+ # secret_access_key: <your key>
+ #
+ # test:
+ # bucket_name: appname_test
+ # access_key_id: <your key>
+ # secret_access_key: <your key>
+ #
+ # production:
+ # bucket_name: appname
+ # photo_bucket_name: appname_photos
+ # access_key_id: <your key>
+ # secret_access_key: <your key>
+ #
+ # If the bucket_key you specify is not there in a certain environment then attachment_fu will
+ # default to the <tt>bucket_name</tt> key. This way you only have to create special buckets
+ # this can be helpful if you only need special buckets in certain environments.
+ #
# === Permissions
#
# By default, files are stored on S3 with public access permissions. You can customize this using
- # the <tt>:s3_access</tt> option to <tt>has_attachment</tt>. Available values are
+ # the <tt>:s3_access</tt> option to <tt>has_attachment</tt>. Available values are
# <tt>:private</tt>, <tt>:public_read_write</tt>, and <tt>:authenticated_read</tt>.
#
# === Other options
#
# Niether <tt>base_path</tt> or <tt>full_filename</tt> include the bucket name as part of the path.
# You can retrieve the bucket name using the <tt>bucket_name</tt> method.
+ #
+ # === Accessing CloudFront URLs
+ #
+ # You can get an object's CloudFront URL using the cloudfront_url accessor. Using the example from above:
+ # @postcard.cloudfront_url # => http://XXXX.cloudfront.net/photos/1/mexico.jpg
+ #
+ # The resulting url is in the form: http://:distribution_domain/:table_name/:id/:file
+ #
+ # If you set :cloudfront to true in your model, the public_filename will be the CloudFront
+ # URL, not the S3 URL.
module S3Backend
class RequiredLibraryNotFoundError < StandardError; end
class ConfigFileNotFoundError < StandardError; end
def self.included(base) #:nodoc:
mattr_reader :bucket_name, :s3_config
-
+
begin
require 'aws/s3'
include AWS::S3
begin
@@s3_config_path = base.attachment_options[:s3_config_path] || (RAILS_ROOT + '/config/amazon_s3.yml')
- @@s3_config = @@s3_config = YAML.load_file(@@s3_config_path)[RAILS_ENV].symbolize_keys
+ @@s3_config = @@s3_config = YAML.load(ERB.new(File.read(@@s3_config_path)).result)[RAILS_ENV].symbolize_keys
#rescue
# raise ConfigFileNotFoundError.new('File %s not found' % @@s3_config_path)
end
- @@bucket_name = s3_config[:bucket_name]
+ bucket_key = base.attachment_options[:bucket_key]
+
+ if bucket_key and s3_config[bucket_key.to_sym]
+ eval_string = "def bucket_name()\n \"#{s3_config[bucket_key.to_sym]}\"\nend"
+ else
+ eval_string = "def bucket_name()\n \"#{s3_config[:bucket_name]}\"\nend"
+ end
+ base.class_eval(eval_string, __FILE__, __LINE__)
- Base.establish_connection!(
- :access_key_id => s3_config[:access_key_id],
- :secret_access_key => s3_config[:secret_access_key],
- :server => s3_config[:server],
- :port => s3_config[:port],
- :use_ssl => s3_config[:use_ssl]
- )
+ Base.establish_connection!(s3_config.slice(:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy))
# Bucket.create(@@bucket_name)
def self.protocol
@protocol ||= s3_config[:use_ssl] ? 'https://' : 'http://'
end
-
+
def self.hostname
@hostname ||= s3_config[:server] || AWS::S3::DEFAULT_HOST
end
-
+
def self.port_string
- @port_string ||= s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80) ? '' : ":#{s3_config[:port]}"
+ @port_string ||= (s3_config[:port].nil? || s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80)) ? '' : ":#{s3_config[:port]}"
+ end
+
+ def self.distribution_domain
+ @distribution_domain = s3_config[:distribution_domain]
end
module ClassMethods
def s3_protocol
Technoweenie::AttachmentFu::Backends::S3Backend.protocol
end
-
+
def s3_hostname
Technoweenie::AttachmentFu::Backends::S3Backend.hostname
end
-
+
def s3_port_string
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
end
+
+ def cloudfront_distribution_domain
+ Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
+ end
end
# Overwrites the base filename writer in order to store the old filename
File.join(base_path, thumbnail_name_for(thumbnail))
end
- # All public objects are accessible via a GET request to the S3 servers. You can generate a
+ # All public objects are accessible via a GET request to the S3 servers. You can generate a
# url for an object using the s3_url method.
#
# @photo.s3_url
def s3_url(thumbnail = nil)
File.join(s3_protocol + s3_hostname + s3_port_string, bucket_name, full_filename(thumbnail))
end
- alias :public_filename :s3_url
+
+ # All public objects are accessible via a GET request to CloudFront. You can generate a
+ # url for an object using the cloudfront_url method.
+ #
+ # @photo.cloudfront_url
+ #
+ # The resulting url is in the form: <tt>http://:distribution_domain/:table_name/:id/:file</tt> using
+ # the <tt>:distribution_domain</tt> variable set in the configuration parameters in <tt>RAILS_ROOT/config/amazon_s3.yml</tt>.
+ #
+ # The optional thumbnail argument will output the thumbnail's filename (if any).
+ def cloudfront_url(thumbnail = nil)
+ "http://" + cloudfront_distribution_domain + "/" + full_filename(thumbnail)
+ end
+
+ def public_filename(*args)
+ if attachment_options[:cloudfront]
+ cloudfront_url(args)
+ else
+ s3_url(args)
+ end
+ end
- # All private objects are accessible via an authenticated GET request to the S3 servers. You can generate an
+ # All private objects are accessible via an authenticated GET request to the S3 servers. You can generate an
# authenticated url for an object like this:
#
# @photo.authenticated_s3_url
#
# # Absolute expiration date (October 13th, 2025)
# @photo.authenticated_s3_url(:expires => Time.mktime(2025,10,13).to_i)
- #
+ #
# # Expiration in five hours from now
# @photo.authenticated_s3_url(:expires_in => 5.hours)
#
#
# @photo.authenticated_s3_url('thumbnail', :expires_in => 5.hours, :use_ssl => true)
def authenticated_s3_url(*args)
- thumbnail = args.first.is_a?(String) ? args.first : nil
- options = args.last.is_a?(Hash) ? args.last : {}
+ options = args.extract_options!
+ options[:expires_in] = options[:expires_in].to_i if options[:expires_in]
+ thumbnail = args.shift
S3Object.url_for(full_filename(thumbnail), bucket_name, options)
end
def s3_protocol
Technoweenie::AttachmentFu::Backends::S3Backend.protocol
end
-
+
def s3_hostname
Technoweenie::AttachmentFu::Backends::S3Backend.hostname
end
-
+
def s3_port_string
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
end
+
+ def cloudfront_distribution_domain
+ Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
+ end
protected
# Called in the after_destroy callback
def rename_file
return unless @old_filename && @old_filename != filename
-
+
old_full_filename = File.join(base_path, @old_filename)
S3Object.rename(
end
end
end
-end
\ No newline at end of file
+end
--- /dev/null
+require 'red_artisan/core_image/processor'
+
+module Technoweenie # :nodoc:
+ module AttachmentFu # :nodoc:
+ module Processors
+ module CoreImageProcessor
+ def self.included(base)
+ base.send :extend, ClassMethods
+ base.alias_method_chain :process_attachment, :processing
+ end
+
+ module ClassMethods
+ def with_image(file, &block)
+ block.call OSX::CIImage.from(file)
+ end
+ end
+
+ protected
+ def process_attachment_with_processing
+ return unless process_attachment_without_processing
+ with_image do |img|
+ self.width = img.extent.size.width if respond_to?(:width)
+ self.height = img.extent.size.height if respond_to?(:height)
+ resize_image_or_thumbnail! img
+ callback_with_args :after_resize, img
+ end if image?
+ end
+
+ # Performs the actual resizing operation for a thumbnail
+ def resize_image(img, size)
+ processor = ::RedArtisan::CoreImage::Processor.new(img)
+ size = size.first if size.is_a?(Array) && size.length == 1
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
+ if size.is_a?(Fixnum)
+ processor.fit(size)
+ else
+ processor.resize(size[0], size[1])
+ end
+ else
+ new_size = [img.extent.size.width, img.extent.size.height] / size.to_s
+ processor.resize(new_size[0], new_size[1])
+ end
+
+ processor.render do |result|
+ self.width = result.extent.size.width if respond_to?(:width)
+ self.height = result.extent.size.height if respond_to?(:height)
+
+ # Get a new temp_path for the image before saving
+ temp_paths.unshift Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
+ result.save self.temp_path, OSX::NSJPEGFileType
+ self.size = File.size(self.temp_path)
+ end
+ end
+ end
+ end
+ end
+end
+
+
--- /dev/null
+require 'rubygems'
+require 'gd2'
+module Technoweenie # :nodoc:
+ module AttachmentFu # :nodoc:
+ module Processors
+ module Gd2Processor
+ def self.included(base)
+ base.send :extend, ClassMethods
+ base.alias_method_chain :process_attachment, :processing
+ end
+
+ module ClassMethods
+ # Yields a block containing a GD2 Image for the given binary data.
+ def with_image(file, &block)
+ im = GD2::Image.import(file)
+ block.call(im)
+ end
+ end
+
+ protected
+ def process_attachment_with_processing
+ return unless process_attachment_without_processing && image?
+ with_image do |img|
+ resize_image_or_thumbnail! img
+ self.width = img.width
+ self.height = img.height
+ callback_with_args :after_resize, img
+ end
+ end
+
+ # Performs the actual resizing operation for a thumbnail
+ def resize_image(img, size)
+ size = size.first if size.is_a?(Array) && size.length == 1
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
+ if size.is_a?(Fixnum)
+ # Borrowed from image science's #thumbnail method and adapted
+ # for this.
+ scale = size.to_f / (img.width > img.height ? img.width.to_f : img.height.to_f)
+ img.resize!((img.width * scale).round(1), (img.height * scale).round(1), false)
+ else
+ img.resize!(size.first, size.last, false)
+ end
+ else
+ w, h = [img.width, img.height] / size.to_s
+ img.resize!(w, h, false)
+ end
+ temp_paths.unshift random_tempfile_filename
+ self.size = img.export(self.temp_path)
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
end
module ClassMethods
- # Yields a block containing an RMagick Image for the given binary data.
+ # Yields a block containing an Image Science image for the given binary data.
def with_image(file, &block)
::ImageScience.with_image file, &block
end
# supports.
filename.sub! /gif$/, 'png'
content_type.sub!(/gif$/, 'png')
- self.temp_path = write_to_temp_file(filename)
+ temp_paths.unshift write_to_temp_file(filename)
grab_dimensions = lambda do |img|
self.width = img.width if respond_to?(:width)
self.height = img.height if respond_to?(:height)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end
-
+
module ClassMethods
# Yields a block containing an MiniMagick Image for the given binary data.
def with_image(file, &block)
!binary_data.nil?
end
end
-
+
protected
def process_attachment_with_processing
return unless process_attachment_without_processing
with_image do |img|
resize_image_or_thumbnail! img
- self.width = img[:width] if respond_to?(:width)
- self.height = img[:height] if respond_to?(:height)
+ self.width = img[:width] if respond_to?(:width)
+ self.height = img[:height] if respond_to?(:height)
callback_with_args :after_resize, img
end if image?
end
-
+
# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1
- if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
- if size.is_a?(Fixnum)
- size = [size, size]
- img.resize(size.join('x'))
+ img.combine_options do |commands|
+ commands.strip unless attachment_options[:keep_profile]
+
+ # gif are not handled correct, this is a hack, but it seems to work.
+ if img.output =~ / GIF /
+ img.format("png")
+ end
+
+ if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
+ if size.is_a?(Fixnum)
+ size = [size, size]
+ commands.resize(size.join('x'))
+ else
+ commands.resize(size.join('x') + '!')
+ end
+ # extend to thumbnail size
+ elsif size.is_a?(String) and size =~ /e$/
+ size = size.gsub(/e/, '')
+ commands.resize(size.to_s + '>')
+ commands.background('#ffffff')
+ commands.gravity('center')
+ commands.extent(size)
+ # crop thumbnail, the smart way
+ elsif size.is_a?(String) and size =~ /c$/
+ size = size.gsub(/c/, '')
+
+ # calculate sizes and aspect ratio
+ thumb_width, thumb_height = size.split("x")
+ thumb_width = thumb_width.to_f
+ thumb_height = thumb_height.to_f
+
+ thumb_aspect = thumb_width.to_f / thumb_height.to_f
+ image_width, image_height = img[:width].to_f, img[:height].to_f
+ image_aspect = image_width / image_height
+
+ # only crop if image is not smaller in both dimensions
+ unless image_width < thumb_width and image_height < thumb_height
+ command = calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
+
+ # crop image
+ commands.extract(command)
+ end
+
+ # don not resize if image is not as height or width then thumbnail
+ if image_width < thumb_width or image_height < thumb_height
+ commands.background('#ffffff')
+ commands.gravity('center')
+ commands.extent(size)
+ # resize image
+ else
+ commands.resize("#{size.to_s}")
+ end
+ # crop end
else
- img.resize(size.join('x') + '!')
+ commands.resize(size.to_s)
end
+ end
+ temp_paths.unshift img
+ end
+
+ def calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
+ # only crop if image is not smaller in both dimensions
+
+ # special cases, image smaller in one dimension then thumbsize
+ if image_width < thumb_width
+ offset = (image_height / 2) - (thumb_height / 2)
+ command = "#{image_width}x#{thumb_height}+0+#{offset}"
+ elsif image_height < thumb_height
+ offset = (image_width / 2) - (thumb_width / 2)
+ command = "#{thumb_width}x#{image_height}+#{offset}+0"
+
+ # normal thumbnail generation
+ # calculate height and offset y, width is fixed
+ elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
+ height = image_width / thumb_aspect
+ offset = (image_height / 2) - (height / 2)
+ command = "#{image_width}x#{height}+0+#{offset}"
+ # calculate width and offset x, height is fixed
else
- img.resize(size.to_s)
+ width = image_height * thumb_aspect
+ offset = (image_width / 2) - (width / 2)
+ command = "#{width}x#{image_height}+#{offset}+0"
end
- self.temp_path = img
+ # crop image
+ command
end
+
+
end
end
end
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end
-
+
module ClassMethods
# Yields a block containing an RMagick Image for the given binary data.
def with_image(file, &block)
callback_with_args :after_resize, img
end if image?
end
-
+
# Performs the actual resizing operation for a thumbnail
def resize_image(img, size)
size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
size = [size, size] if size.is_a?(Fixnum)
img.thumbnail!(*size)
+ elsif size.is_a?(String) && size =~ /^c.*$/ # Image cropping - example geometry string: c75x75
+ dimensions = size[1..size.size].split("x")
+ img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
else
- img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols, rows) }
+ img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
end
- self.temp_path = write_to_temp_file(img.to_blob)
+ img.strip! unless attachment_options[:keep_profile]
+ temp_paths.unshift write_to_temp_file(img.to_blob)
end
end
end
end
-end
\ No newline at end of file
+end
--- /dev/null
+development:
+ container_name: appname_development
+ username:
+ api_key:
+
+test:
+ container_name: appname_test
+ username:
+ api_key:
+
+production:
+ container_name: appname_production
+ username:
+ api_key:
+++ /dev/null
-test:
- bucket_name: afu
- access_key_id: YOURACCESSKEY
- secret_access_key: YOURSECRETACCESSKEY
- server: 127.0.0.1
- port: 3002
\ No newline at end of file
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
+require 'digest/sha2'
class FileSystemTest < Test::Unit::TestCase
include BaseAttachmentTests
assert_not_created do
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
- attachment.temp_path = File.join(fixture_path, file)
+ attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
end
test_against_subclass :test_should_delete_old_file_when_renaming, FileAttachment
-end
\ No newline at end of file
+
+ def test_path_partitioning_works_on_integer_id(klass = FileAttachment)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = 1
+
+ begin
+ assert_equal ["0000", "0001", "bar.txt"], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partitioning_works_on_integer_id, FileAttachment
+
+ def test_path_partitioning_with_string_id_works_by_generating_hash(klass = FileAttachmentWithStringId)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = "hello world some long string"
+ hash = Digest::SHA512.hexdigest("hello world some long string")
+
+ begin
+ assert_equal [
+ hash[0..31],
+ hash[32..63],
+ hash[64..95],
+ hash[96..127],
+ "bar.txt"
+ ], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partitioning_with_string_id_works_by_generating_hash, FileAttachmentWithStringId
+
+ def test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid(klass = FileAttachmentWithUuid)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = "0c0743b698483569dc65909a8cdb3bf9"
+
+ begin
+ assert_equal [
+ "0c0743b698483569",
+ "dc65909a8cdb3bf9",
+ "bar.txt"
+ ], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid, FileAttachmentWithUuid
+end
--- /dev/null
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
+require 'net/http'
+
+class CloudfilesTest < Test::Unit::TestCase
+ def self.test_CloudFiles?
+ true unless ENV["TEST_CLOUDFILES"] == "false"
+ end
+
+ if test_CloudFiles? && File.exist?(File.join(File.dirname(__FILE__), '../../rackspace_cloudfiles.yml'))
+ include BaseAttachmentTests
+ attachment_model CloudFilesAttachment
+
+ def test_should_create_correct_container_name(klass = CloudFilesAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_equal attachment.cloudfiles_config[:container_name], attachment.container_name
+ end
+
+ test_against_subclass :test_should_create_correct_container_name, CloudFilesAttachment
+
+ def test_should_create_default_path_prefix(klass = CloudFilesAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_equal File.join(attachment_model.table_name, attachment.attachment_path_id), attachment.base_path
+ end
+
+ test_against_subclass :test_should_create_default_path_prefix, CloudFilesAttachment
+
+ def test_should_create_custom_path_prefix(klass = CloudFilesWithPathPrefixAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_equal File.join('some/custom/path/prefix', attachment.attachment_path_id), attachment.base_path
+ end
+
+ test_against_subclass :test_should_create_custom_path_prefix, CloudFilesWithPathPrefixAttachment
+
+
+ def test_should_create_valid_url(klass = CloudFilesAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_match(%r!http://cdn.cloudfiles.mosso.com/(.*?)/cloud_files_attachments/1/rails.png!, attachment.cloudfiles_url)
+ end
+
+ test_against_subclass :test_should_create_valid_url, CloudFilesAttachment
+
+ def test_should_save_attachment(klass = CloudFilesAttachment)
+ attachment_model klass
+ assert_created do
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_valid attachment
+ assert attachment.image?
+ assert !attachment.size.zero?
+ assert_kind_of Net::HTTPOK, http_response_for(attachment.cloudfiles_url)
+ end
+ end
+
+ test_against_subclass :test_should_save_attachment, CloudFilesAttachment
+
+ def test_should_delete_attachment_from_cloud_files_when_attachment_record_destroyed(klass = CloudFilesAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+
+ urls = [attachment.cloudfiles_url] + attachment.thumbnails.collect(&:cloudfiles_url)
+
+ urls.each {|url| assert_kind_of Net::HTTPOK, http_response_for(url) }
+ attachment.destroy
+ urls.each do |url|
+ begin
+ http_response_for(url)
+ rescue Net::HTTPForbidden, Net::HTTPNotFound
+ nil
+ end
+ end
+ end
+
+ test_against_subclass :test_should_delete_attachment_from_cloud_files_when_attachment_record_destroyed, CloudFilesAttachment
+
+
+
+ protected
+ def http_response_for(url)
+ url = URI.parse(url)
+ Net::HTTP.start(url.host, url.port) {|http| http.request_head(url.path) }
+ end
+
+ def s3_protocol
+ Technoweenie::AttachmentFu::Backends::S3Backend.protocol
+ end
+
+ def s3_hostname
+ Technoweenie::AttachmentFu::Backends::S3Backend.hostname
+ end
+
+ def s3_port_string
+ Technoweenie::AttachmentFu::Backends::S3Backend.port_string
+ end
+ else
+ def test_flunk_s3
+ puts "s3 config file not loaded, tests not running"
+ end
+ end
+end
\ No newline at end of file
require 'net/http'
class S3Test < Test::Unit::TestCase
- if File.exist?(File.join(File.dirname(__FILE__), '../../amazon_s3.yml'))
+ def self.test_S3?
+ true unless ENV["TEST_S3"] == "false"
+ end
+
+ if test_S3? && File.exist?(File.join(File.dirname(__FILE__), '../../amazon_s3.yml'))
include BaseAttachmentTests
attachment_model S3Attachment
end
test_against_subclass :test_should_create_authenticated_url, S3Attachment
+
+ def test_should_create_authenticated_url_for_thumbnail(klass = S3Attachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ ['large', :large].each do |thumbnail|
+ assert_match(
+ /^http.+rails_large\.png.+AWSAccessKeyId.+Expires.+Signature/,
+ attachment.authenticated_s3_url(thumbnail),
+ "authenticated_s3_url failed with #{thumbnail.class} parameter"
+ )
+ end
+ end
def test_should_save_attachment(klass = S3Attachment)
attachment_model klass
end
end
+ def test_should_create_file_from_merb_temp_file
+ assert_created do
+ attachment = upload_merb_file :filename => '/files/foo.txt'
+ assert_valid attachment
+ assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
+ assert attachment.image?
+ assert !attachment.size.zero?
+ #assert_equal 3, attachment.size
+ assert_nil attachment.width
+ assert_nil attachment.height
+ end
+ end
+
def test_reassign_attribute_data
assert_created 1 do
attachment = upload_file :filename => '/files/rails.png'
assert_valid attachment
assert attachment.size > 0, "no data was set"
- attachment.temp_data = 'wtf'
+ attachment.set_temp_data 'wtf'
assert attachment.save_attachment?
attachment.save!
assert_valid attachment
assert attachment.size > 0, "no data was set"
- attachment.temp_data = nil
+ attachment.set_temp_data nil
assert !attachment.save_attachment?
end
end
assert_not_created do # no new db_file records
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
- attachment.temp_path = File.join(fixture_path, file)
+ attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end
assert !attachment.save_attachment?
assert_nothing_raised { attachment.save! }
end
+
+ def test_should_handle_nil_file_upload
+ attachment = attachment_model.create :uploaded_data => ''
+ assert_raise ActiveRecord::RecordInvalid do
+ attachment.save!
+ end
+ end
end
\ No newline at end of file
def test_should_normalize_content_types_to_array
assert_equal %w(pdf), PdfAttachment.attachment_options[:content_type]
assert_equal %w(pdf doc txt), DocAttachment.attachment_options[:content_type]
- assert_equal ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageAttachment.attachment_options[:content_type]
- assert_equal ['pdf', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageOrPdfAttachment.attachment_options[:content_type]
+ assert_equal Technoweenie::AttachmentFu.content_types, ImageAttachment.attachment_options[:content_type]
+ assert_equal ['pdf'] + Technoweenie::AttachmentFu.content_types, ImageOrPdfAttachment.attachment_options[:content_type]
end
def test_should_sanitize_content_type
@attachment.filename = 'f o!O-.bar'
assert_equal 'f_o_O-.bar', @attachment.filename
+
+ @attachment.filename = 'sheeps_says_bææ'
+ assert_equal 'sheeps_says_b__', @attachment.filename
+
+ @attachment.filename = nil
+ assert_nil @attachment.filename
end
def test_should_convert_thumbnail_name
klass.has_attachment :thumbnails => []
end
end
-end
\ No newline at end of file
+end
end
end
+ def test_should_create_file_from_merb_temp_file
+ assert_created do
+ attachment = upload_merb_file :filename => '/files/foo.txt'
+ assert_valid attachment
+ assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
+ assert attachment.image?
+ assert !attachment.size.zero?
+ end
+ end
+
def test_should_create_image_from_uploaded_file_with_custom_content_type
assert_created do
attachment = upload_file :content_type => 'foo/bar', :filename => '/files/rails.png'
class ImageWithThumbsAttachment < Attachment
has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }, :resize_to => [55,55]
after_resize do |record, img|
- record.aspect_ratio = img.columns.to_f / img.rows.to_f
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
end
end
validates_as_attachment
end
+class FileAttachmentWithStringId < ActiveRecord::Base
+ set_table_name 'file_attachments_with_string_id'
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick
+ validates_as_attachment
+
+ before_validation :auto_generate_id
+ before_save :auto_generate_id
+ @@last_id = 0
+
+ private
+ def auto_generate_id
+ @@last_id += 1
+ self.id = "id_#{@@last_id}"
+ end
+end
+
+class FileAttachmentWithUuid < ActiveRecord::Base
+ set_table_name 'file_attachments_with_string_id'
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files', :processor => :rmagick, :uuid_primary_key => true
+ validates_as_attachment
+
+ before_validation :auto_generate_id
+ before_save :auto_generate_id
+ @@last_id = 0
+
+ private
+ def auto_generate_id
+ @@last_id += 1
+ self.id = "%0127dx" % @@last_id
+ end
+end
+
class ImageFileAttachment < FileAttachment
has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
:content_type => :image, :resize_to => [50,50]
has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
:thumbnails => { :thumb => [50, 50], :geometry => 'x50' }, :resize_to => [55,55]
after_resize do |record, img|
- record.aspect_ratio = img.columns.to_f / img.rows.to_f
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
end
end
puts "no ImageScience"
end
+begin
+ class CoreImageAttachment < ActiveRecord::Base
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
+ :processor => :core_image, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
+ end
+rescue MissingSourceFile
+ puts $!.message
+ puts "no CoreImage"
+end
+
begin
class MiniMagickAttachment < ActiveRecord::Base
has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
puts "no Mini Magick"
end
+begin
+ class GD2Attachment < ActiveRecord::Base
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
+ :processor => :gd2, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
+ end
+rescue MissingSourceFile
+ puts $!.message
+ puts "no GD2"
+end
+
+
begin
class MiniMagickAttachment < ActiveRecord::Base
has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
:processor => :mini_magick, :thumbnails => { :thumb => [50, 51], :geometry => '31>' }, :resize_to => 55
end
+ class ImageThumbnailCrop < MiniMagickAttachment
+ has_attachment :path_prefix => 'vendor/plugins/attachment_fu/test/files',
+ :thumbnails => { :square => "50x50c", :vertical => "30x60c", :horizontal => "60x30c"}
+
+ # TODO this is a bad duplication, this method is in the MiniMagick Processor
+ def self.calculate_offset(image_width,image_height,image_aspect,thumb_width,thumb_height,thumb_aspect)
+ # only crop if image is not smaller in both dimensions
+
+ # special cases, image smaller in one dimension then thumbsize
+ if image_width < thumb_width
+ offset = (image_height / 2) - (thumb_height / 2)
+ command = "#{image_width}x#{thumb_height}+0+#{offset}"
+ elsif image_height < thumb_height
+ offset = (image_width / 2) - (thumb_width / 2)
+ command = "#{thumb_width}x#{image_height}+#{offset}+0"
+
+ # normal thumbnail generation
+ # calculate height and offset y, width is fixed
+ elsif (image_aspect <= thumb_aspect or image_width < thumb_width) and image_height > thumb_height
+ height = image_width / thumb_aspect
+ offset = (image_height / 2) - (height / 2)
+ command = "#{image_width}x#{height}+0+#{offset}"
+ # calculate width and offset x, height is fixed
+ else
+ width = image_height * thumb_aspect
+ offset = (image_width / 2) - (width / 2)
+ command = "#{width}x#{image_height}+#{offset}+0"
+ end
+ # crop image
+ command
+ end
+ end
+
rescue MissingSourceFile
end
+
+
begin
class S3Attachment < ActiveRecord::Base
has_attachment :storage => :s3, :processor => :rmagick, :s3_config_path => File.join(File.dirname(__FILE__), '../amazon_s3.yml')
validates_as_attachment
end
+
+ class CloudFilesAttachment < ActiveRecord::Base
+ has_attachment :storage => :cloud_files, :processor => :rmagick, :cloudfiles_config_path => File.join(File.dirname(__FILE__), '../rackspace_cloudfiles.yml')
+ validates_as_attachment
+ end
class S3WithPathPrefixAttachment < S3Attachment
has_attachment :storage => :s3, :path_prefix => 'some/custom/path/prefix', :processor => :rmagick
validates_as_attachment
end
-rescue Technoweenie::AttachmentFu::Backends::S3Backend::ConfigFileNotFoundError
+
+ class CloudFilesWithPathPrefixAttachment < CloudFilesAttachment
+ has_attachment :storage => :cloud_files, :path_prefix => 'some/custom/path/prefix', :processor => :rmagick
+ validates_as_attachment
+ end
+
+rescue
puts "S3 error: #{$!}"
end
"100" => [100, 128]
end
+ def test_should_resize_no_height_with_x
+ assert_geometry 50, 64,
+ "50x" => [50, 64],
+ "60x" => [60, 77],
+ "100x" => [100, 128]
+ end
+
def test_should_resize_with_percent
assert_geometry 50, 64,
"50x50%" => [25, 32],
--- /dev/null
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
+
+class CoreImageTest < Test::Unit::TestCase
+ attachment_model CoreImageAttachment
+
+ if Object.const_defined?(:OSX)
+ def test_should_resize_image
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_valid attachment
+ assert attachment.image?
+ # test core image thumbnail
+ assert_equal 42, attachment.width
+ assert_equal 55, attachment.height
+
+ thumb = attachment.thumbnails.detect { |t| t.filename =~ /_thumb/ }
+ geo = attachment.thumbnails.detect { |t| t.filename =~ /_geometry/ }
+
+ # test exact resize dimensions
+ assert_equal 50, thumb.width
+ assert_equal 51, thumb.height
+
+ # test geometry string
+ assert_equal 31, geo.width
+ assert_equal 41, geo.height
+
+ # This makes sure that we didn't overwrite the original file
+ # and will end up with a thumbnail instead of the original
+ assert_equal 42, attachment.width
+ assert_equal 55, attachment.height
+
+ end
+ else
+ def test_flunk
+ puts "CoreImage not loaded, tests not running"
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
+
+class GD2Test < Test::Unit::TestCase
+ attachment_model GD2Attachment
+
+ if Object.const_defined?(:GD2)
+ def test_should_resize_image
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_valid attachment
+ assert attachment.image?
+ # test gd2 thumbnail
+ assert_equal 43, attachment.width
+ assert_equal 55, attachment.height
+
+ thumb = attachment.thumbnails.detect { |t| t.filename =~ /_thumb/ }
+ geo = attachment.thumbnails.detect { |t| t.filename =~ /_geometry/ }
+
+ # test exact resize dimensions
+ assert_equal 50, thumb.width
+ assert_equal 51, thumb.height
+
+ # test geometry string
+ assert_equal 31, geo.width
+ assert_equal 40, geo.height
+ end
+ else
+ def test_flunk
+ puts "GD2 not loaded, tests not running"
+ end
+ end
+end
\ No newline at end of file
assert_equal 31, geo.width
assert_equal 40, geo.height
end
+
+ def test_should_crop_image(klass = ImageThumbnailCrop)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_valid attachment
+ assert attachment.image?
+ # has_attachment :thumbnails => { :square => "50x50c", :vertical => "30x60c", :horizontal => "60x30c"}
+
+ square = attachment.thumbnails.detect { |t| t.filename =~ /_square/ }
+ vertical = attachment.thumbnails.detect { |t| t.filename =~ /_vertical/ }
+ horizontal = attachment.thumbnails.detect { |t| t.filename =~ /_horizontal/ }
+
+ # test excat resize
+ assert_equal 50, square.width
+ assert_equal 50, square.height
+
+ assert_equal 30, vertical.width
+ assert_equal 60, vertical.height
+
+ assert_equal 60, horizontal.width
+ assert_equal 30, horizontal.height
+ end
+
+ # tests the first step in resize, crop the image in original size to right format
+ def test_should_crop_image_right(klass = ImageThumbnailCrop)
+ @@testcases.collect do |testcase|
+ image_width, image_height, thumb_width, thumb_height = testcase[:data]
+ image_aspect, thumb_aspect = image_width/image_height, thumb_width/thumb_height
+ crop_comand = klass.calculate_offset(image_width, image_height, image_aspect, thumb_width, thumb_height,thumb_aspect)
+ # pattern matching on crop command
+ if testcase.has_key?(:height)
+ assert crop_comand.match(/^#{image_width}x#{testcase[:height]}\+0\+#{testcase[:yoffset]}$/)
+ else
+ assert crop_comand.match(/^#{testcase[:width]}x#{image_height}\+#{testcase[:xoffset]}\+0$/)
+ end
+ end
+ end
+
else
def test_flunk
puts "MiniMagick not loaded, tests not running"
end
end
+
+ @@testcases = [
+ # image_aspect <= 1 && thumb_aspect >= 1
+ {:data => [10.0,40.0,2.0,1.0], :height => 5.0, :yoffset => 17.5}, # 1b
+ {:data => [10.0,40.0,1.0,1.0], :height => 10.0, :yoffset => 15.0}, # 1b
+
+ # image_aspect < 1 && thumb_aspect < 1
+ {:data => [10.0,40.0,1.0,2.0], :height => 20.0, :yoffset => 10.0}, # 1a
+ {:data => [2.0,3.0,1.0,2.0], :width => 1.5, :xoffset => 0.25}, # 1a
+
+ # image_aspect = thumb_aspect
+ {:data => [10.0,10.0,1.0,1.0], :height => 10.0, :yoffset => 0.0}, # QUADRAT 1c
+
+ # image_aspect >= 1 && thumb_aspect > 1 && image_aspect < thumb_aspect
+ {:data => [6.0,3.0,4.0,1.0], :height => 1.5, :yoffset => 0.75}, # 2b
+ {:data => [6.0,6.0,4.0,1.0], :height => 1.5, :yoffset => 2.25}, # 2b
+
+ # image_aspect > 1 && thumb_aspect > 1 && image_aspect > thumb_aspect
+ {:data => [9.0,3.0,2.0,1.0], :width => 6.0, :xoffset => 1.5}, # 2a
+
+ # image_aspect > 1 && thumb_aspect < 1 && image_aspect < thumb_aspect
+ {:data => [10.0,5.0,0.1,2.0], :width => 0.25, :xoffset => 4.875}, # 4
+ {:data => [10.0,5.0,1.0,2.0], :width => 2.5, :xoffset => 3.75}, # 4
+
+ # image_aspect > 1 && thumb_aspect > 1 && image_aspect > thumb_aspect
+ {:data => [9.0,3.0,2.0,1.0], :width => 6.0, :xoffset => 1.5}, # 3a
+ # image_aspect > 1 && thumb_aspect > 1 && image_aspect < thumb_aspect
+ {:data => [9.0,3.0,5.0,1.0], :height => 1.8, :yoffset => 0.6} # 3a
+ ]
+
+
+
+
+
end
assert_valid attachment
end
assert_kind_of ImageThumbnail, attachment.thumbnails.first
- assert_equal attachment.id, attachment.thumbnails.first.parent.id
- assert_kind_of FileAttachment, attachment.thumbnails.first.parent
+ if attachment.thumbnails.first.respond_to?(:parent)
+ assert_equal attachment.id, attachment.thumbnails.first.parent.id
+ assert_kind_of FileAttachment, attachment.thumbnails.first.parent
+ end
assert_equal 'rails_thumb.png', attachment.thumbnails.first.filename
assert_equal attachment.thumbnails.first.full_filename, attachment.full_filename(attachment.thumbnails.first.thumbnail),
"#full_filename does not use thumbnail class' path."
- assert_equal attachment.destroy attachment
+ assert_equal attachment.destroy, attachment
end
test_against_subclass :test_should_use_thumbnail_subclass, ImageWithThumbsClassFileAttachment
assert_not_created do
use_temp_file "files/rails.png" do |file|
attachment.filename = 'rails2.png'
- attachment.temp_path = File.join(fixture_path, file)
+ attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save
new_filenames = [attachment.reload.full_filename] + attachment.thumbnails.collect { |t| t.reload.full_filename }
new_filenames.each { |f| assert File.exists?(f), "#{f} does not exist" }
test_against_subclass :test_should_delete_file_when_in_file_system_when_attachment_record_destroyed, ImageWithThumbsFileAttachment
+ def test_should_have_full_filename_method(klass = FileAttachment)
+ attachment_model klass
+ attachment = upload_file :filename => '/files/rails.png'
+ assert_respond_to attachment, :full_filename
+ end
+
+ test_against_subclass :test_should_have_full_filename_method, FileAttachment
+
def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithThumbsAttachment)
attachment_model klass
attachment = nil
assert_not_created do # no new db_file records
use_temp_file "files/rails.png" do |file|
attachment.filename = 'rails2.png'
- attachment.temp_path = File.join(fixture_path, file)
+ # The above test (#test_should_have_full_filename_method) to pass before be can set the temp_path below --
+ # #temp_path calls #full_filename, which is not getting mixed into the attachment. Maybe we don't need to
+ # set temp_path at all?
+ #
+ # attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end
puts "RMagick not installed, no tests running"
end
end
-end
\ No newline at end of file
+end
t.column :type, :string
t.column :aspect_ratio, :float
end
+
+ create_table :file_attachments_with_string_id, :id => false, :force => true do |t|
+ t.column :id, :string
+ t.column :parent_id, :string
+ t.column :thumbnail, :string
+ t.column :filename, :string, :limit => 255
+ t.column :content_type, :string, :limit => 255
+ t.column :size, :integer
+ t.column :width, :integer
+ t.column :height, :integer
+ t.column :type, :string
+ t.column :aspect_ratio, :float
+ end
+
+ create_table :gd2_attachments, :force => true do |t|
+ t.column :parent_id, :integer
+ t.column :thumbnail, :string
+ t.column :filename, :string, :limit => 255
+ t.column :content_type, :string, :limit => 255
+ t.column :size, :integer
+ t.column :width, :integer
+ t.column :height, :integer
+ t.column :type, :string
+ end
create_table :image_science_attachments, :force => true do |t|
t.column :parent_id, :integer
t.column :type, :string
end
+ create_table :core_image_attachments, :force => true do |t|
+ t.column :parent_id, :integer
+ t.column :thumbnail, :string
+ t.column :filename, :string, :limit => 255
+ t.column :content_type, :string, :limit => 255
+ t.column :size, :integer
+ t.column :width, :integer
+ t.column :height, :integer
+ t.column :type, :string
+ end
+
create_table :mini_magick_attachments, :force => true do |t|
t.column :parent_id, :integer
t.column :thumbnail, :string
t.column :type, :string
t.column :aspect_ratio, :float
end
-end
\ No newline at end of file
+
+ create_table :cloud_files_attachments, :force => true do |t|
+ t.column :parent_id, :integer
+ t.column :thumbnail, :string
+ t.column :filename, :string, :limit => 255
+ t.column :content_type, :string, :limit => 255
+ t.column :size, :integer
+ t.column :width, :integer
+ t.column :height, :integer
+ t.column :type, :string
+ t.column :aspect_ratio, :float
+ end
+
+end
$:.unshift(File.dirname(__FILE__) + '/../lib')
ENV['RAILS_ENV'] = 'test'
+ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
require 'test/unit'
-require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
-require 'breakpoint'
+require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
require 'active_record/fixtures'
require 'action_controller/test_process'
end
end
+ def upload_merb_file(options = {})
+ use_temp_file options[:filename] do |file|
+ att = attachment_model.create :uploaded_data => {"size" => file.size, "content_type" => options[:content_type] || 'image/png', "filename" => file, 'tempfile' => fixture_file_upload(file, options[:content_type] || 'image/png')}
+ att.reload unless att.new_record?
+ return att
+ end
+ end
+
def use_temp_file(fixture_filename)
temp_path = File.join('/tmp', File.basename(fixture_filename))
FileUtils.mkdir_p File.join(fixture_path, 'tmp')
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Color
+
+ def greyscale(color = nil, intensity = 1.00)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ color = OSX::CIColor.colorWithString("1.0 1.0 1.0 1.0") unless color
+
+ @original.color_monochrome :inputColor => color, :inputIntensity => intensity do |greyscale|
+ @target = greyscale
+ end
+ end
+
+ def sepia(intensity = 1.00)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.sepia_tone :inputIntensity => intensity do |sepia|
+ @target = sepia
+ end
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Effects
+
+ def spotlight(position, points_at, brightness, concentration, color)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.spot_light :inputLightPosition => vector3(*position), :inputLightPointsAt => vector3(*points_at),
+ :inputBrightness => brightness, :inputConcentration => concentration, :inputColor => color do |spot|
+ @target = spot
+ end
+ end
+
+ def edges(intensity = 1.00)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.edges :inputIntensity => intensity do |edged|
+ @target = edged
+ end
+ end
+
+ private
+
+ def vector3(x, y, w)
+ OSX::CIVector.vectorWithX_Y_Z(x, y, w)
+ end
+ end
+ end
+ end
+end
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Perspective
+
+ def perspective(top_left, top_right, bottom_left, bottom_right)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.perspective_transform :inputTopLeft => top_left, :inputTopRight => top_right, :inputBottomLeft => bottom_left, :inputBottomRight => bottom_right do |transformed|
+ @target = transformed
+ end
+ end
+
+ def perspective_tiled(top_left, top_right, bottom_left, bottom_right)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.perspective_tile :inputTopLeft => top_left, :inputTopRight => top_right, :inputBottomLeft => bottom_left, :inputBottomRight => bottom_right do |tiled|
+ @target = tiled
+ end
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Quality
+
+ def reduce_noise(level = 0.02, sharpness = 0.4)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.noise_reduction :inputNoiseLevel => level, :inputSharpness => sharpness do |noise_reduced|
+ @target = noise_reduced
+ end
+ end
+
+ def adjust_exposure(input_ev = 0.5)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ @original.exposure_adjust :inputEV => input_ev do |adjusted|
+ @target = adjusted
+ end
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Scale
+
+ def resize(width, height)
+ create_core_image_context(width, height)
+
+ scale_x, scale_y = scale(width, height)
+
+ @original.affine_clamp :inputTransform => OSX::NSAffineTransform.transform do |clamped|
+ clamped.lanczos_scale_transform :inputScale => scale_x > scale_y ? scale_x : scale_y, :inputAspectRatio => scale_x / scale_y do |scaled|
+ scaled.crop :inputRectangle => vector(0, 0, width, height) do |cropped|
+ @target = cropped
+ end
+ end
+ end
+ end
+
+ def thumbnail(width, height)
+ create_core_image_context(width, height)
+
+ transform = OSX::NSAffineTransform.transform
+ transform.scaleXBy_yBy *scale(width, height)
+
+ @original.affine_transform :inputTransform => transform do |scaled|
+ @target = scaled
+ end
+ end
+
+ def fit(size)
+ original_size = @original.extent.size
+ scale = size.to_f / (original_size.width > original_size.height ? original_size.width : original_size.height)
+ resize (original_size.width * scale).to_i, (original_size.height * scale).to_i
+ end
+
+ private
+
+ def scale(width, height)
+ original_size = @original.extent.size
+ return width.to_f / original_size.width.to_f, height.to_f / original_size.height.to_f
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+module RedArtisan
+ module CoreImage
+ module Filters
+ module Watermark
+
+ def watermark(watermark_image, tile = false, strength = 0.1)
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
+
+ if watermark_image.respond_to? :to_str
+ watermark_image = OSX::CIImage.from(watermark_image.to_str)
+ end
+
+ if tile
+ tile_transform = OSX::NSAffineTransform.transform
+ tile_transform.scaleXBy_yBy 1.0, 1.0
+
+ watermark_image.affine_tile :inputTransform => tile_transform do |tiled|
+ tiled.crop :inputRectangle => vector(0, 0, @original.extent.size.width, @original.extent.size.height) do |tiled_watermark|
+ watermark_image = tiled_watermark
+ end
+ end
+ end
+
+ @original.dissolve_transition :inputTargetImage => watermark_image, :inputTime => strength do |watermarked|
+ @target = watermarked
+ end
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+require 'rubygems'
+require 'osx/cocoa'
+require 'active_support'
+
+require 'red_artisan/core_image/filters/scale'
+require 'red_artisan/core_image/filters/color'
+require 'red_artisan/core_image/filters/watermark'
+require 'red_artisan/core_image/filters/quality'
+require 'red_artisan/core_image/filters/perspective'
+require 'red_artisan/core_image/filters/effects'
+
+# Generic image processor for scaling images based on CoreImage via RubyCocoa.
+#
+# Example usage:
+#
+# p = Processor.new OSX::CIImage.from(path_to_image)
+# p.resize(640, 480)
+# p.render do |result|
+# result.save('resized.jpg', OSX::NSJPEGFileType)
+# end
+#
+# This will resize the image to the given dimensions exactly, if you'd like to ensure that aspect ratio is preserved:
+#
+# p = Processor.new OSX::CIImage.from(path_to_image)
+# p.fit(640)
+# p.render do |result|
+# result.save('resized.jpg', OSX::NSJPEGFileType)
+# end
+#
+# fit(size) will attempt its best to resize the image so that the longest width/height (depending on image orientation) will match
+# the given size. The second axis will be calculated automatically based on the aspect ratio.
+#
+# Scaling is performed by first clamping the image so that its external bounds become infinite, this helps when scaling so that any
+# rounding discrepencies in dimensions don't affect the resultant image. We then perform a Lanczos transform on the image which scales
+# it to the target size. We then crop the image to the traget dimensions.
+#
+# If you are generating smaller images such as thumbnails where high quality rendering isn't as important, an additional method is
+# available:
+#
+# p = Processor.new OSX::CIImage.from(path_to_image)
+# p.thumbnail(100, 100)
+# p.render do |result|
+# result.save('resized.jpg', OSX::NSJPEGFileType)
+# end
+#
+# This will perform a straight affine transform and scale the X and Y boundaries to the requested size. Generally, this will be faster
+# than a lanczos scale transform, but with a scaling quality trade.
+#
+# More than welcome to intregrate any patches, improvements - feel free to mail me with ideas.
+#
+# Thanks to
+# * Satoshi Nakagawa for working out that OCObjWrapper needs inclusion when aliasing method_missing on existing OSX::* classes.
+# * Vasantha Crabb for general help and inspiration with Cocoa
+# * Ben Schwarz for example image data and collaboration during performance testing
+#
+# Copyright (c) Marcus Crafter <crafterm@redartisan.com> released under the MIT license
+#
+module RedArtisan
+ module CoreImage
+ class Processor
+
+ def initialize(original)
+ if original.respond_to? :to_str
+ @original = OSX::CIImage.from(original.to_str)
+ else
+ @original = original
+ end
+ end
+
+ def render(&block)
+ raise "unprocessed image: #{@original}" unless @target
+ block.call @target
+ end
+
+ include Filters::Scale, Filters::Color, Filters::Watermark, Filters::Quality, Filters::Perspective, Filters::Effects
+
+ private
+
+ def create_core_image_context(width, height)
+ output = OSX::NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(nil, width, height, 8, 4, true, false, OSX::NSDeviceRGBColorSpace, 0, 0)
+ context = OSX::NSGraphicsContext.graphicsContextWithBitmapImageRep(output)
+ OSX::NSGraphicsContext.setCurrentContext(context)
+ @ci_context = context.CIContext
+ end
+
+ def vector(x, y, w, h)
+ OSX::CIVector.vectorWithX_Y_Z_W(x, y, w, h)
+ end
+ end
+ end
+end
+
+module OSX
+ class CIImage
+ include OCObjWrapper
+
+ def method_missing_with_filter_processing(sym, *args, &block)
+ f = OSX::CIFilter.filterWithName("CI#{sym.to_s.camelize}")
+ return method_missing_without_filter_processing(sym, *args, &block) unless f
+
+ f.setDefaults if f.respond_to? :setDefaults
+ f.setValue_forKey(self, 'inputImage')
+ options = args.last.is_a?(Hash) ? args.last : {}
+ options.each { |k, v| f.setValue_forKey(v, k.to_s) }
+
+ block.call f.valueForKey('outputImage')
+ end
+
+ alias_method_chain :method_missing, :filter_processing
+
+ def save(target, format = OSX::NSJPEGFileType, properties = nil)
+ bitmapRep = OSX::NSBitmapImageRep.alloc.initWithCIImage(self)
+ blob = bitmapRep.representationUsingType_properties(format, properties)
+ blob.writeToFile_atomically(target, false)
+ end
+
+ def self.from(filepath)
+ raise Errno::ENOENT, "No such file or directory - #{filepath}" unless File.exists?(filepath)
+ OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath(filepath))
+ end
+ end
+end
+
--- /dev/null
+= YamlDb
+
+YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.
+
+This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
+
+Any database that has an ActiveRecord adapter should work.
+
+== Usage
+
+rake db:data:dump -> Dump contents of Rails database to db/data.yml
+rake db:data:load -> Load contents of db/data.yml into the database
+
+Further, there are tasks db:dump and db:load which do the entire database (the equivalent of running db:schema:dump followed by db:data:load).
+
+== Examples
+
+One common use would be to switch your data from one database backend to another. For example, let's say you wanted to switch from SQLite to MySQL. You might execute the following steps:
+
+1. rake db:dump
+
+2. Edit config/database.yml and change your adapter to mysql, set up database params
+
+3. mysqladmin create [database name]
+
+4. rake db:load
+
+== Credits
+
+Created by Orion Henry and Adam Wiggins. Major updates by Ricardo Chimal, Jr.
+
+Patches contributed by Michael Irwin, Tom Locke, and Tim Galeckas.
+
+Send questions, feedback, or patches to the Heroku mailing list: http://groups.google.com/group/heroku
+
--- /dev/null
+require 'rake'
+require 'spec/rake/spectask'
+
+desc "Run all specs"
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/*_spec.rb']
+end
+
+task :default => :spec
+
--- /dev/null
+author: Orion Henry and Adam Wiggins of Heroku
+summary: Dumps and loads a database-independent data dump format in db/data.yml.
+homepage: http://opensource.heroku.com/
+license: MIT
+rails_version: 1.2+
--- /dev/null
+require 'yaml_db'
--- /dev/null
+require 'rubygems'
+require 'yaml'
+require 'active_record'
+
+
+module YamlDb
+ def self.dump(filename)
+ disable_logger
+ YamlDb::Dump.dump(File.new(filename, "w"))
+ reenable_logger
+ end
+
+ def self.load(filename)
+ disable_logger
+ YamlDb::Load.load(File.new(filename, "r"))
+ reenable_logger
+ end
+
+ def self.disable_logger
+ @@old_logger = ActiveRecord::Base.logger
+ ActiveRecord::Base.logger = nil
+ end
+
+ def self.reenable_logger
+ ActiveRecord::Base.logger = @@old_logger
+ end
+end
+
+
+module YamlDb::Utils
+ def self.chunk_records(records)
+ yaml = [ records ].to_yaml
+ yaml.sub!("--- \n", "")
+ yaml.sub!('- - -', ' - -')
+ yaml
+ end
+
+ def self.unhash(hash, keys)
+ keys.map { |key| hash[key] }
+ end
+
+ def self.unhash_records(records, keys)
+ records.each_with_index do |record, index|
+ records[index] = unhash(record, keys)
+ end
+
+ records
+ end
+
+ def self.convert_booleans(records, columns)
+ records.each do |record|
+ columns.each do |column|
+ next if is_boolean(record[column])
+ record[column] = (record[column] == 't' or record[column] == '1')
+ end
+ end
+ records
+ end
+
+ def self.boolean_columns(table)
+ columns = ActiveRecord::Base.connection.columns(table).reject { |c| c.type != :boolean }
+ columns.map { |c| c.name }
+ end
+
+ def self.is_boolean(value)
+ value.kind_of?(TrueClass) or value.kind_of?(FalseClass)
+ end
+
+ def self.quote_table(table)
+ ActiveRecord::Base.connection.quote_table_name(table)
+ end
+end
+
+
+module YamlDb::Dump
+ def self.dump(io)
+ tables.each do |table|
+ dump_table(io, table)
+ end
+ end
+
+ def self.tables
+ ActiveRecord::Base.connection.tables.reject { |table| ['schema_info', 'schema_migrations'].include?(table) }
+ end
+
+ def self.dump_table(io, table)
+ return if table_record_count(table).zero?
+
+ dump_table_columns(io, table)
+ dump_table_records(io, table)
+ end
+
+ def self.dump_table_columns(io, table)
+ io.write("\n")
+ io.write({ table => { 'columns' => table_column_names(table) } }.to_yaml)
+ end
+
+ def self.dump_table_records(io, table)
+ table_record_header(io)
+
+ column_names = table_column_names(table)
+
+ each_table_page(table) do |records|
+ rows = YamlDb::Utils.unhash_records(records, column_names)
+ io.write(YamlDb::Utils.chunk_records(records))
+ end
+ end
+
+ def self.table_record_header(io)
+ io.write(" records: \n")
+ end
+
+ def self.table_column_names(table)
+ ActiveRecord::Base.connection.columns(table).map { |c| c.name }
+ end
+
+ def self.each_table_page(table, records_per_page=1000)
+ total_count = table_record_count(table)
+ pages = (total_count.to_f / records_per_page).ceil - 1
+ id = table_column_names(table).first
+ boolean_columns = YamlDb::Utils.boolean_columns(table)
+ quoted_table_name = YamlDb::Utils.quote_table(table)
+
+ (0..pages).to_a.each do |page|
+ sql = ActiveRecord::Base.connection.add_limit_offset!("SELECT * FROM #{quoted_table_name} ORDER BY #{id}",
+ :limit => records_per_page, :offset => records_per_page * page
+ )
+ records = ActiveRecord::Base.connection.select_all(sql)
+ records = YamlDb::Utils.convert_booleans(records, boolean_columns)
+ yield records
+ end
+ end
+
+ def self.table_record_count(table)
+ ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM #{YamlDb::Utils.quote_table(table)}").values.first.to_i
+ end
+end
+
+
+module YamlDb::Load
+ def self.load(io)
+ ActiveRecord::Base.connection.transaction do
+ YAML.load_documents(io) do |ydoc|
+ ydoc.keys.each do |table_name|
+ next if ydoc[table_name].nil?
+ load_table(table_name, ydoc[table_name])
+ end
+ end
+ end
+ end
+
+ def self.truncate_table(table)
+ begin
+ ActiveRecord::Base.connection.execute("TRUNCATE #{YamlDb::Utils.quote_table(table)}")
+ rescue Exception
+ ActiveRecord::Base.connection.execute("DELETE FROM #{YamlDb::Utils.quote_table(table)}")
+ end
+ end
+
+ def self.load_table(table, data)
+ column_names = data['columns']
+ truncate_table(table)
+ load_records(table, column_names, data['records'])
+ reset_pk_sequence!(table)
+ end
+
+ def self.load_records(table, column_names, records)
+ quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
+ quoted_table_name = YamlDb::Utils.quote_table(table)
+ records.each do |record|
+ ActiveRecord::Base.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{record.map { |r| ActiveRecord::Base.connection.quote(r) }.join(',')})")
+ end
+ end
+
+ def self.reset_pk_sequence!(table_name)
+ if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
+ ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
+ end
+ end
+end
--- /dev/null
+require 'rubygems'
+require 'spec'
+
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+require 'yaml_db'
+
+
--- /dev/null
+require File.dirname(__FILE__) + '/base'
+
+describe YamlDb::Dump do
+ before do
+ File.stub!(:new).with('dump.yml', 'w').and_return(StringIO.new)
+
+ ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
+ ActiveRecord::Base.connection = mock('connection')
+ ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
+ ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a'), mock('b', :name => 'b') ])
+ ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
+ ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
+ YamlDb::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
+ end
+
+ before(:each) do
+ @io = StringIO.new
+ end
+
+ it "should return a formatted string" do
+ YamlDb::Dump.table_record_header(@io)
+ @io.rewind
+ @io.read.should == " records: \n"
+ end
+
+ it "should return a list of column names" do
+ YamlDb::Dump.table_column_names('mytable').should == [ 'a', 'b' ]
+ end
+
+ it "should return a list of tables without the rails schema table" do
+ YamlDb::Dump.tables.should == ['mytable']
+ end
+
+ it "should return the total number of records in a table" do
+ YamlDb::Dump.table_record_count('mytable').should == 2
+ end
+
+ it "should return a yaml string that contains a table header and column names" do
+ YamlDb::Dump.stub!(:table_column_names).with('mytable').and_return([ 'a', 'b' ])
+ YamlDb::Dump.dump_table_columns(@io, 'mytable')
+ @io.rewind
+ @io.read.should == <<EOYAML
+
+---
+mytable:
+ columns:
+ - a
+ - b
+EOYAML
+ end
+
+ it "should return all records from the database and return them when there is only 1 page" do
+ YamlDb::Dump.each_table_page('mytable') do |records|
+ records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
+ end
+ end
+
+ it "should paginate records from the database and return them" do
+ ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 } ], [ { 'a' => 3, 'b' => 4 } ])
+
+ records = [ ]
+ YamlDb::Dump.each_table_page('mytable', 1) do |page|
+ page.size.should == 1
+ records.concat(page)
+ end
+
+ records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
+ end
+
+ it "should return dump the records for a table in yaml to a given io stream" do
+ YamlDb::Dump.dump_table_records(@io, 'mytable')
+ @io.rewind
+ @io.read.should == <<EOYAML
+ records:
+ - - 1
+ - 2
+ - - 3
+ - 4
+EOYAML
+ end
+
+ it "should dump a table's contents to yaml" do
+ YamlDb::Dump.should_receive(:dump_table_columns)
+ YamlDb::Dump.should_receive(:dump_table_records)
+ YamlDb::Dump.dump_table(@io, 'mytable')
+ end
+
+ it "should not dump a table's contents when the record count is zero" do
+ YamlDb::Dump.stub!(:table_record_count).with('mytable').and_return(0)
+ YamlDb::Dump.should_not_receive(:dump_table_columns)
+ YamlDb::Dump.should_not_receive(:dump_table_records)
+ YamlDb::Dump.dump_table(@io, 'mytable')
+ end
+end
--- /dev/null
+require File.dirname(__FILE__) + '/base'
+
+describe YamlDb::Load do
+ before do
+ YamlDb::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
+
+ ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
+ ActiveRecord::Base.connection = mock('connection')
+ ActiveRecord::Base.connection.stub!(:transaction).and_yield
+ end
+
+ before(:each) do
+ @io = StringIO.new
+ end
+
+ it "should truncate the table" do
+ ActiveRecord::Base.connection.stub!(:execute).with("TRUNCATE mytable").and_return(true)
+ ActiveRecord::Base.connection.should_not_receive(:execute).with("DELETE FROM mytable")
+ YamlDb::Load.truncate_table('mytable')
+ end
+
+ it "should delete the table if truncate throws an exception" do
+ ActiveRecord::Base.connection.should_receive(:execute).with("TRUNCATE mytable").and_raise()
+ ActiveRecord::Base.connection.should_receive(:execute).with("DELETE FROM mytable").and_return(true)
+ YamlDb::Load.truncate_table('mytable')
+ end
+
+ it "should insert records into a table" do
+ ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
+ ActiveRecord::Base.connection.stub!(:quote_column_name).with('b').and_return('b')
+ ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
+ ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
+ ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
+ ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
+ ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('1','2')")
+ ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('3','4')")
+
+ YamlDb::Load.load_records('mytable', ['a', 'b'], [[1, 2], [3, 4]])
+ end
+
+ it "should quote column names that correspond to sql keywords" do
+ ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
+ ActiveRecord::Base.connection.stub!(:quote_column_name).with('count').and_return('"count"')
+ ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
+ ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
+ ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
+ ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
+ ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('1','2')")
+ ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('3','4')")
+
+ YamlDb::Load.load_records('mytable', ['a', 'count'], [[1, 2], [3, 4]])
+ end
+
+ it "should truncate the table and then load the records into the table" do
+ YamlDb::Load.should_receive(:truncate_table).with('mytable')
+ YamlDb::Load.should_receive(:load_records).with('mytable', ['a', 'b'], [[1, 2], [3, 4]])
+ YamlDb::Load.should_receive(:reset_pk_sequence!).with('mytable')
+
+ YamlDb::Load.load_table('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
+ end
+
+ it "should call load structure for each document in the file" do
+ YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => {
+ 'columns' => [ 'a', 'b' ],
+ 'records' => [[1, 2], [3, 4]]
+ } })
+ YamlDb::Load.should_receive(:load_table).with('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
+ YamlDb::Load.load(@io)
+ end
+
+ it "should not call load structure when the document in the file contains no records" do
+ YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => nil })
+ YamlDb::Load.should_not_receive(:load_table)
+ YamlDb::Load.load(@io)
+ end
+
+ it "should call reset pk sequence if the connection adapter is postgres" do
+ ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(true)
+ ActiveRecord::Base.connection.should_receive(:reset_pk_sequence!).with('mytable')
+ YamlDb::Load.reset_pk_sequence!('mytable')
+ end
+
+ it "should not call reset pk sequence for other adapters" do
+ ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(false)
+ ActiveRecord::Base.connection.should_not_receive(:reset_pk_sequence!)
+ YamlDb::Load.reset_pk_sequence!('mytable')
+ end
+end
--- /dev/null
+require File.dirname(__FILE__) + '/base'
+
+describe YamlDb::Utils, " convert records utility method" do
+ before do
+ ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
+ ActiveRecord::Base.connection = mock('connection')
+ end
+
+ it "turns an array with one record into a yaml chunk" do
+ YamlDb::Utils.chunk_records([ %w(a b) ]).should == <<EOYAML
+ - - a
+ - b
+EOYAML
+ end
+
+ it "turns an array with two records into a yaml chunk" do
+ YamlDb::Utils.chunk_records([ %w(a b), %w(x y) ]).should == <<EOYAML
+ - - a
+ - b
+ - - x
+ - y
+EOYAML
+ end
+
+ it "returns an array of hash values using an array of ordered keys" do
+ YamlDb::Utils.unhash({ 'a' => 1, 'b' => 2 }, [ 'b', 'a' ]).should == [ 2, 1 ]
+ end
+
+ it "should unhash each hash an array using an array of ordered keys" do
+ YamlDb::Utils.unhash_records([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ], [ 'b', 'a' ]).should == [ [ 2, 1 ], [ 4, 3 ] ]
+ end
+
+ it "should return true if it is a boolean type" do
+ YamlDb::Utils.is_boolean(true).should == true
+ YamlDb::Utils.is_boolean('true').should_not == true
+ end
+
+ it "should return an array of boolean columns" do
+ ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a',:type => :string), mock('b', :name => 'b',:type => :boolean) ])
+ YamlDb::Utils.boolean_columns('mytable').should == ['b']
+ end
+
+ it "should quote the table name" do
+ ActiveRecord::Base.connection.should_receive(:quote_table_name).with('values').and_return('`values`')
+ YamlDb::Utils.quote_table('values').should == '`values`'
+ end
+end
--- /dev/null
+namespace :db do
+ desc "Dump schema and data to db/schema.rb and db/data.yml"
+ task(:dump => [ "db:schema:dump", "db:data:dump" ])
+
+ desc "Load schema and data from db/schema.rb and db/data.yml"
+ task(:load => [ "db:schema:load", "db:data:load" ])
+
+ namespace :data do
+ def db_dump_data_file
+ "#{RAILS_ROOT}/db/data.yml"
+ end
+
+ desc "Dump contents of database to db/data.yml"
+ task(:dump => :environment) do
+ YamlDb.dump db_dump_data_file
+ end
+
+ desc "Load contents of db/data.yml into database"
+ task(:load => :environment) do
+ YamlDb.load db_dump_data_file
+ end
+ end
+end