Skip to content

Commit

Permalink
Survived driving day 2 enabled guard and other updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dylansimpson committed May 10, 2012
1 parent b558058 commit bcf5817
Show file tree
Hide file tree
Showing 23 changed files with 483 additions and 38 deletions.
18 changes: 14 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ gem 'jquery-rails'

group :development do
gem "rspec-rails"
gem "guard-rspec"
gem "guard-spork"

# mac
gem "rb-fsevent" if RUBY_PLATFORM.downcase.include?("darwin")
gem "growl" if RUBY_PLATFORM.downcase.include?("darwin")

# linux
gem 'rb-inotify' if RUBY_PLATFORM.downcase.include?("linux")
gem 'libnotify' if RUBY_PLATFORM.downcase.include?("linux")

end

group :test do
gem "rspec-rails"
gem "factory_girl_rails"
gem "database_cleaner"
gem "capybara"
end




48 changes: 48 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,61 @@ GEM
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.8)
arel (3.0.2)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.2)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.1)
database_cleaner (0.7.2)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
factory_girl (3.2.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.2.0)
factory_girl (~> 3.2.0)
railties (>= 3.0.0)
ffi (1.0.11)
guard (1.0.2)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.7.0)
guard (>= 0.10.0)
guard-spork (0.8.0)
guard (>= 0.10.0)
spork (>= 0.8.4)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
libnotify (0.7.2)
libwebsocket (0.1.3)
addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.2)
nokogiri (1.5.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -78,6 +107,8 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rb-inotify (0.8.8)
ffi (>= 0.5.0)
rdoc (3.12)
json (~> 1.4)
rspec (2.9.0)
Expand All @@ -93,11 +124,19 @@ GEM
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.9.0)
rubyzip (0.9.8)
sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.21.2)
childprocess (>= 0.2.5)
ffi (~> 1.0)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
spork (0.9.1)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
Expand All @@ -112,14 +151,23 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara
coffee-rails (~> 3.2.1)
database_cleaner
factory_girl_rails
guard-rspec
guard-spork
jquery-rails
libnotify
rails (= 3.2.3)
rb-inotify
rspec-rails
sass-rails (~> 3.2.3)
sqlite3
Expand Down
31 changes: 31 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end


guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
end
3 changes: 3 additions & 0 deletions app/assets/javascripts/votes.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/votes.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the votes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
83 changes: 83 additions & 0 deletions app/controllers/votes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class VotesController < ApplicationController
# GET /votes
# GET /votes.json
def index
@votes = Vote.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @votes }
end
end

# GET /votes/1
# GET /votes/1.json
def show
@vote = Vote.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @vote }
end
end

# GET /votes/new
# GET /votes/new.json
def new
@vote = Vote.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @vote }
end
end

# GET /votes/1/edit
def edit
@vote = Vote.find(params[:id])
end

# POST /votes
# POST /votes.json
def create
@vote = Vote.new(params[:vote])

respond_to do |format|
if @vote.save
format.html { redirect_to @vote, notice: 'Vote was successfully created.' }
format.json { render json: @vote, status: :created, location: @vote }
else
format.html { render action: "new" }
format.json { render json: @vote.errors, status: :unprocessable_entity }
end
end
end

# PUT /votes/1
# PUT /votes/1.json
def update
@vote = Vote.find(params[:id])

respond_to do |format|
if @vote.update_attributes(params[:vote])
format.html { redirect_to @vote, notice: 'Vote was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @vote.errors, status: :unprocessable_entity }
end
end
end

# DELETE /votes/1
# DELETE /votes/1.json
def destroy
@vote = Vote.find(params[:id])
@vote.destroy

respond_to do |format|
format.html { redirect_to votes_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/votes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VotesHelper
end
9 changes: 8 additions & 1 deletion app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ class Story < ActiveRecord::Base
attr_accessible :content, :story_id, :twitter_handle
validates_presence_of :twitter_handle
validates_presence_of :content
#validates_format_of :twitter_handle, with: /A@.*/
validates_format_of :twitter_handle, with: /\A@\w+\Z/
has_many :votes



def rank
votes.inject(0) { |sum,v| sum += v.value }
end
end
10 changes: 10 additions & 0 deletions app/models/vote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Vote < ActiveRecord::Base
attr_accessible :story_id, :twitter_handle, :value
validates_presence_of :twitter_handle
validates_presence_of :story_id
validates_presence_of :value
validates_format_of :twitter_handle, with: /\A@\w+\Z/
validates_inclusion_of :value, in: [-1,1]
belongs_to :story
validates_uniqueness_of :twitter_handle, scope: :story_id
end
29 changes: 29 additions & 0 deletions app/views/votes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= form_for(@vote) do |f| %>
<% if @vote.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@vote.errors.count, "error") %> prohibited this vote from being saved:</h2>

<ul>
<% @vote.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :twitter_handle %><br />
<%= f.text_field :twitter_handle %>
</div>
<div class="field">
<%= f.label :value %><br />
<%= f.number_field :value %>
</div>
<div class="field">
<%= f.label :story_id %><br />
<%= f.number_field :story_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/votes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing vote</h1>

<%= render 'form' %>

<%= link_to 'Show', @vote %> |
<%= link_to 'Back', votes_path %>
27 changes: 27 additions & 0 deletions app/views/votes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1>Listing votes</h1>

<table>
<tr>
<th>Twitter handle</th>
<th>Value</th>
<th>Story</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @votes.each do |vote| %>
<tr>
<td><%= vote.twitter_handle %></td>
<td><%= vote.value %></td>
<td><%= vote.story_id %></td>
<td><%= link_to 'Show', vote %></td>
<td><%= link_to 'Edit', edit_vote_path(vote) %></td>
<td><%= link_to 'Destroy', vote, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Vote', new_vote_path %>
5 changes: 5 additions & 0 deletions app/views/votes/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New vote</h1>

<%= render 'form' %>

<%= link_to 'Back', votes_path %>
20 changes: 20 additions & 0 deletions app/views/votes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p id="notice"><%= notice %></p>

<p>
<b>Twitter handle:</b>
<%= @vote.twitter_handle %>
</p>

<p>
<b>Value:</b>
<%= @vote.value %>
</p>

<p>
<b>Story:</b>
<%= @vote.story_id %>
</p>


<%= link_to 'Edit', edit_vote_path(@vote) %> |
<%= link_to 'Back', votes_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
VegastechApp::Application.routes.draw do
resources :votes

resources :stories

# The priority is based upon order of creation:
Expand Down
Loading

0 comments on commit bcf5817

Please sign in to comment.