Permalink
Browse files

Feature: Added Bids and Buys

  • Loading branch information...
hrdwdmrbl committed Mar 23, 2013
1 parent 3e75f20 commit 16b9398ce2d051681957ce4c5f4ef78f2bf1ddef
Showing with 376 additions and 21 deletions.
  1. +3 −0 app/assets/javascripts/bids.js.coffee
  2. +3 −0 app/assets/javascripts/buys.js.coffee
  3. +3 −0 app/assets/stylesheets/bids.css.scss
  4. +3 −0 app/assets/stylesheets/buys.css.scss
  5. +2 −0 app/controllers/bids_controller.rb
  6. +2 −0 app/controllers/buys_controller.rb
  7. +4 −0 app/controllers/predictions_controller.rb
  8. +2 −0 app/helpers/bids_helper.rb
  9. +2 −0 app/helpers/buys_helper.rb
  10. +3 −0 app/models/bid.rb
  11. +3 −0 app/models/buy.rb
  12. +16 −0 app/views/bids/_form.html.haml
  13. +7 −0 app/views/bids/edit.html.haml
  14. +21 −0 app/views/bids/index.html.haml
  15. +5 −0 app/views/bids/new.html.haml
  16. +12 −0 app/views/bids/show.html.haml
  17. +19 −0 app/views/buys/_form.html.haml
  18. +7 −0 app/views/buys/edit.html.haml
  19. +23 −0 app/views/buys/index.html.haml
  20. +5 −0 app/views/buys/new.html.haml
  21. +15 −0 app/views/buys/show.html.haml
  22. +0 −17 app/views/layouts/application.html.erb
  23. +15 −0 app/views/layouts/application.html.haml
  24. +0 −3 app/views/predictions/_form.html.haml
  25. +6 −0 config/routes.rb
  26. +10 −0 db/migrate/20130323154656_create_bids.rb
  27. +5 −0 db/migrate/20130323154911_add_user_id_to_predictions.rb
  28. +5 −0 db/migrate/20130323155021_add_public_key_to_users.rb
  29. +5 −0 db/migrate/20130323155511_add_prediction_id_to_bids.rb
  30. +11 −0 db/migrate/20130323155754_create_buys.rb
  31. +19 −1 db/schema.rb
  32. +9 −0 test/fixtures/bids.yml
  33. +11 −0 test/fixtures/buys.yml
  34. +49 −0 test/functional/bids_controller_test.rb
  35. +49 −0 test/functional/buys_controller_test.rb
  36. +7 −0 test/unit/bid_test.rb
  37. +7 −0 test/unit/buy_test.rb
  38. +4 −0 test/unit/helpers/bids_helper_test.rb
  39. +4 −0 test/unit/helpers/buys_helper_test.rb
@@ -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/
@@ -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/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Bids controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Buys controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,2 @@
+class BidsController < InheritedResources::Base
+end
@@ -0,0 +1,2 @@
+class BuysController < InheritedResources::Base
+end
@@ -1,2 +1,6 @@
class PredictionsController < InheritedResources::Base
+ def create
+ params[:user_id] = current_user.id
+ create!
+ end
end
@@ -0,0 +1,2 @@
+module BidsHelper
+end
@@ -0,0 +1,2 @@
+module BuysHelper
+end
View
@@ -0,0 +1,3 @@
+class Bid < ActiveRecord::Base
+ attr_accessible :price, :user_id
+end
View
@@ -0,0 +1,3 @@
+class Buy < ActiveRecord::Base
+ attr_accessible :prediction_id, :price, :user_id
+end
@@ -0,0 +1,16 @@
+= form_for @bid do |f|
+ - if @bid.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@bid.errors.count, "error")} prohibited this bid from being saved:"
+ %ul
+ - @bid.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :price
+ = f.text_field :price
+ .field
+ = f.label :user_id
+ = f.number_field :user_id
+ .actions
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
+%h1 Editing bid
+
+= render 'form'
+
+= link_to 'Show', @bid
+\|
+= link_to 'Back', bids_path
@@ -0,0 +1,21 @@
+%h1 Listing bids
+
+%table
+ %tr
+ %th Price
+ %th User
+ %th
+ %th
+ %th
+
+ - @bids.each do |bid|
+ %tr
+ %td= bid.price
+ %td= bid.user_id
+ %td= link_to 'Show', bid
+ %td= link_to 'Edit', edit_bid_path(bid)
+ %td= link_to 'Destroy', bid, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+
+= link_to 'New Bid', new_bid_path
@@ -0,0 +1,5 @@
+%h1 New bid
+
+= render 'form'
+
+= link_to 'Back', bids_path
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b Price:
+ = @bid.price
+%p
+ %b User:
+ = @bid.user_id
+
+= link_to 'Edit', edit_bid_path(@bid)
+\|
+= link_to 'Back', bids_path
@@ -0,0 +1,19 @@
+= form_for @buy do |f|
+ - if @buy.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@buy.errors.count, "error")} prohibited this buy from being saved:"
+ %ul
+ - @buy.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :price
+ = f.text_field :price
+ .field
+ = f.label :user_id
+ = f.number_field :user_id
+ .field
+ = f.label :prediction_id
+ = f.number_field :prediction_id
+ .actions
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
+%h1 Editing buy
+
+= render 'form'
+
+= link_to 'Show', @buy
+\|
+= link_to 'Back', buys_path
@@ -0,0 +1,23 @@
+%h1 Listing buys
+
+%table
+ %tr
+ %th Price
+ %th User
+ %th Prediction
+ %th
+ %th
+ %th
+
+ - @buys.each do |buy|
+ %tr
+ %td= buy.price
+ %td= buy.user_id
+ %td= buy.prediction_id
+ %td= link_to 'Show', buy
+ %td= link_to 'Edit', edit_buy_path(buy)
+ %td= link_to 'Destroy', buy, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+
+= link_to 'New Buy', new_buy_path
@@ -0,0 +1,5 @@
+%h1 New buy
+
+= render 'form'
+
+= link_to 'Back', buys_path
@@ -0,0 +1,15 @@
+%p#notice= notice
+
+%p
+ %b Price:
+ = @buy.price
+%p
+ %b User:
+ = @buy.user_id
+%p
+ %b Prediction:
+ = @buy.prediction_id
+
+= link_to 'Edit', edit_buy_path(@buy)
+\|
+= link_to 'Back', buys_path
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>BitPredictor</title>
- <%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
-</head>
-<body>
-
- <p class="notice"><%= notice %></p>
- <p class="alert"><%= alert %></p>
- <%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %>
- <%= yield %>
-
-</body>
-</html>
@@ -0,0 +1,15 @@
+!!!
+%html
+ %head
+ %title BitPredictor
+ = stylesheet_link_tag "application", :media => "all"
+ = javascript_include_tag "application"
+ = csrf_meta_tags
+ %body
+ %p.notice= notice
+ %p.alert= alert
+ - if !current_user
+ = link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook)
+ - else
+ Hi, #{current_user.name}
+ = yield
@@ -18,8 +18,5 @@
.field
= f.label :source
= f.text_field :source
- .field
- = f.label :verified_by
- = f.number_field :verified_by
.actions
= f.submit 'Save'
View
@@ -1,4 +1,10 @@
BitPredictor::Application.routes.draw do
+ resources :buys
+
+
+ resources :bids
+
+
resources :predictions
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks"}
@@ -0,0 +1,10 @@
+class CreateBids < ActiveRecord::Migration
+ def change
+ create_table :bids do |t|
+ t.decimal :price
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,5 @@
+class AddUserIdToPredictions < ActiveRecord::Migration
+ def change
+ add_column :predictions, :user_id, :integer
+ end
+end
@@ -0,0 +1,5 @@
+class AddPublicKeyToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :public_key, :string
+ end
+end
@@ -0,0 +1,5 @@
+class AddPredictionIdToBids < ActiveRecord::Migration
+ def change
+ add_column :bids, :prediction_id, :integer
+ end
+end
@@ -0,0 +1,11 @@
+class CreateBuys < ActiveRecord::Migration
+ def change
+ create_table :buys do |t|
+ t.decimal :price
+ t.integer :user_id
+ t.integer :prediction_id
+
+ t.timestamps
+ end
+ end
+end
View
@@ -11,7 +11,23 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130323154142) do
+ActiveRecord::Schema.define(:version => 20130323155754) do
+
+ create_table "bids", :force => true do |t|
+ t.decimal "price"
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "prediction_id"
+ end
+
+ create_table "buys", :force => true do |t|
+ t.decimal "price"
+ t.integer "user_id"
+ t.integer "prediction_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "predictions", :force => true do |t|
t.string "name"
@@ -21,6 +37,7 @@
t.integer "verified_by"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
create_table "users", :force => true do |t|
@@ -39,6 +56,7 @@
t.string "provider"
t.string "uid"
t.string "name"
+ t.string "public_key"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ price: 9.99
+ user_id: 1
+
+two:
+ price: 9.99
+ user_id: 1
View
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ price: 9.99
+ user_id: 1
+ prediction_id: 1
+
+two:
+ price: 9.99
+ user_id: 1
+ prediction_id: 1
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class BidsControllerTest < ActionController::TestCase
+ setup do
+ @bid = bids(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:bids)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create bid" do
+ assert_difference('Bid.count') do
+ post :create, bid: { price: @bid.price, user_id: @bid.user_id }
+ end
+
+ assert_redirected_to bid_path(assigns(:bid))
+ end
+
+ test "should show bid" do
+ get :show, id: @bid
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @bid
+ assert_response :success
+ end
+
+ test "should update bid" do
+ put :update, id: @bid, bid: { price: @bid.price, user_id: @bid.user_id }
+ assert_redirected_to bid_path(assigns(:bid))
+ end
+
+ test "should destroy bid" do
+ assert_difference('Bid.count', -1) do
+ delete :destroy, id: @bid
+ end
+
+ assert_redirected_to bids_path
+ end
+end
Oops, something went wrong.

0 comments on commit 16b9398

Please sign in to comment.