Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Feature: Added ability to create predictions.

  • Loading branch information...
commit 3e75f2037ee670b241b62b054d78310d67be2d63 1 parent 99e673b
@jackquack authored
View
3  app/assets/javascripts/predictions.js.coffee
@@ -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/
View
3  app/assets/stylesheets/predictions.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Predictions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
69 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,69 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a {
+ color: #000;
+ &:visited {
+ color: #666;
+ }
+ &:hover {
+ color: #fff;
+ background-color: #000;
+ }
+}
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px;
+ }
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+ }
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
View
2  app/controllers/predictions_controller.rb
@@ -0,0 +1,2 @@
+class PredictionsController < InheritedResources::Base
+end
View
2  app/helpers/predictions_helper.rb
@@ -0,0 +1,2 @@
+module PredictionsHelper
+end
View
3  app/models/prediction.rb
@@ -0,0 +1,3 @@
+class Prediction < ActiveRecord::Base
+ attr_accessible :end_date, :name, :prediction, :source, :verified_by
+end
View
25 app/views/predictions/_form.html.haml
@@ -0,0 +1,25 @@
+= form_for @prediction do |f|
+ - if @prediction.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@prediction.errors.count, "error")} prohibited this prediction from being saved:"
+ %ul
+ - @prediction.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .field
+ = f.label :end_date
+ = f.datetime_select :end_date
+ .field
+ = f.label :prediction
+ = f.text_area :prediction
+ .field
+ = f.label :source
+ = f.text_field :source
+ .field
+ = f.label :verified_by
+ = f.number_field :verified_by
+ .actions
+ = f.submit 'Save'
View
7 app/views/predictions/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing prediction
+
+= render 'form'
+
+= link_to 'Show', @prediction
+\|
+= link_to 'Back', predictions_path
View
27 app/views/predictions/index.html.haml
@@ -0,0 +1,27 @@
+%h1 Listing predictions
+
+%table
+ %tr
+ %th Name
+ %th End date
+ %th Prediction
+ %th Source
+ %th Verified by
+ %th
+ %th
+ %th
+
+ - @predictions.each do |prediction|
+ %tr
+ %td= prediction.name
+ %td= prediction.end_date
+ %td= prediction.prediction
+ %td= prediction.source
+ %td= prediction.verified_by
+ %td= link_to 'Show', prediction
+ %td= link_to 'Edit', edit_prediction_path(prediction)
+ %td= link_to 'Destroy', prediction, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+
+= link_to 'New Prediction', new_prediction_path
View
5 app/views/predictions/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New prediction
+
+= render 'form'
+
+= link_to 'Back', predictions_path
View
21 app/views/predictions/show.html.haml
@@ -0,0 +1,21 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @prediction.name
+%p
+ %b End date:
+ = @prediction.end_date
+%p
+ %b Prediction:
+ = @prediction.prediction
+%p
+ %b Source:
+ = @prediction.source
+%p
+ %b Verified by:
+ = @prediction.verified_by
+
+= link_to 'Edit', edit_prediction_path(@prediction)
+\|
+= link_to 'Back', predictions_path
View
4 config/routes.rb
@@ -1,7 +1,9 @@
BitPredictor::Application.routes.draw do
+ resources :predictions
+
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks"}
- root :to => "statics#index"
+ root :to => "predictions#index"
# The priority is based upon order of creation:
# first created -> highest priority.
View
13 db/migrate/20130323154142_create_predictions.rb
@@ -0,0 +1,13 @@
+class CreatePredictions < ActiveRecord::Migration
+ def change
+ create_table :predictions do |t|
+ t.string :name
+ t.datetime :end_date
+ t.text :prediction
+ t.string :source
+ t.integer :verified_by
+
+ t.timestamps
+ end
+ end
+end
View
12 db/schema.rb
@@ -11,7 +11,17 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130323153415) do
+ActiveRecord::Schema.define(:version => 20130323154142) do
+
+ create_table "predictions", :force => true do |t|
+ t.string "name"
+ t.datetime "end_date"
+ t.text "prediction"
+ t.string "source"
+ t.integer "verified_by"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
View
15 test/fixtures/predictions.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ end_date: 2013-03-23 11:41:42
+ prediction: MyText
+ source: MyString
+ verified_by: 1
+
+two:
+ name: MyString
+ end_date: 2013-03-23 11:41:42
+ prediction: MyText
+ source: MyString
+ verified_by: 1
View
49 test/functional/predictions_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PredictionsControllerTest < ActionController::TestCase
+ setup do
+ @prediction = predictions(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:predictions)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create prediction" do
+ assert_difference('Prediction.count') do
+ post :create, prediction: { end_date: @prediction.end_date, name: @prediction.name, prediction: @prediction.prediction, source: @prediction.source, verified_by: @prediction.verified_by }
+ end
+
+ assert_redirected_to prediction_path(assigns(:prediction))
+ end
+
+ test "should show prediction" do
+ get :show, id: @prediction
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @prediction
+ assert_response :success
+ end
+
+ test "should update prediction" do
+ put :update, id: @prediction, prediction: { end_date: @prediction.end_date, name: @prediction.name, prediction: @prediction.prediction, source: @prediction.source, verified_by: @prediction.verified_by }
+ assert_redirected_to prediction_path(assigns(:prediction))
+ end
+
+ test "should destroy prediction" do
+ assert_difference('Prediction.count', -1) do
+ delete :destroy, id: @prediction
+ end
+
+ assert_redirected_to predictions_path
+ end
+end
View
4 test/unit/helpers/predictions_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PredictionsHelperTest < ActionView::TestCase
+end
View
7 test/unit/prediction_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PredictionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.