Skip to content

Commit

Permalink
Feature: Added Bids and Buys
Browse files Browse the repository at this point in the history
  • Loading branch information
hrdwdmrbl committed Mar 23, 2013
1 parent 3e75f20 commit 16b9398
Show file tree
Hide file tree
Showing 39 changed files with 376 additions and 21 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/bids.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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/buys.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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/bids.css.scss
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/buys.css.scss
@@ -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/
2 changes: 2 additions & 0 deletions app/controllers/bids_controller.rb
@@ -0,0 +1,2 @@
class BidsController < InheritedResources::Base
end
2 changes: 2 additions & 0 deletions app/controllers/buys_controller.rb
@@ -0,0 +1,2 @@
class BuysController < InheritedResources::Base
end
4 changes: 4 additions & 0 deletions app/controllers/predictions_controller.rb
@@ -1,2 +1,6 @@
class PredictionsController < InheritedResources::Base
def create
params[:user_id] = current_user.id
create!
end
end
2 changes: 2 additions & 0 deletions app/helpers/bids_helper.rb
@@ -0,0 +1,2 @@
module BidsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/buys_helper.rb
@@ -0,0 +1,2 @@
module BuysHelper
end
3 changes: 3 additions & 0 deletions app/models/bid.rb
@@ -0,0 +1,3 @@
class Bid < ActiveRecord::Base
attr_accessible :price, :user_id
end
3 changes: 3 additions & 0 deletions app/models/buy.rb
@@ -0,0 +1,3 @@
class Buy < ActiveRecord::Base
attr_accessible :prediction_id, :price, :user_id
end
16 changes: 16 additions & 0 deletions app/views/bids/_form.html.haml
@@ -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'
7 changes: 7 additions & 0 deletions app/views/bids/edit.html.haml
@@ -0,0 +1,7 @@
%h1 Editing bid

= render 'form'

= link_to 'Show', @bid
\|
= link_to 'Back', bids_path
21 changes: 21 additions & 0 deletions app/views/bids/index.html.haml
@@ -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
5 changes: 5 additions & 0 deletions app/views/bids/new.html.haml
@@ -0,0 +1,5 @@
%h1 New bid

= render 'form'

= link_to 'Back', bids_path
12 changes: 12 additions & 0 deletions app/views/bids/show.html.haml
@@ -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
19 changes: 19 additions & 0 deletions app/views/buys/_form.html.haml
@@ -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'
7 changes: 7 additions & 0 deletions app/views/buys/edit.html.haml
@@ -0,0 +1,7 @@
%h1 Editing buy

= render 'form'

= link_to 'Show', @buy
\|
= link_to 'Back', buys_path
23 changes: 23 additions & 0 deletions app/views/buys/index.html.haml
@@ -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
5 changes: 5 additions & 0 deletions app/views/buys/new.html.haml
@@ -0,0 +1,5 @@
%h1 New buy

= render 'form'

= link_to 'Back', buys_path
15 changes: 15 additions & 0 deletions app/views/buys/show.html.haml
@@ -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
17 changes: 0 additions & 17 deletions app/views/layouts/application.html.erb

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/layouts/application.html.haml
@@ -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
3 changes: 0 additions & 3 deletions app/views/predictions/_form.html.haml
Expand Up @@ -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'
6 changes: 6 additions & 0 deletions config/routes.rb
@@ -1,4 +1,10 @@
BitPredictor::Application.routes.draw do
resources :buys


resources :bids


resources :predictions

devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks"}
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20130323154656_create_bids.rb
@@ -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
5 changes: 5 additions & 0 deletions db/migrate/20130323154911_add_user_id_to_predictions.rb
@@ -0,0 +1,5 @@
class AddUserIdToPredictions < ActiveRecord::Migration
def change
add_column :predictions, :user_id, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130323155021_add_public_key_to_users.rb
@@ -0,0 +1,5 @@
class AddPublicKeyToUsers < ActiveRecord::Migration
def change
add_column :users, :public_key, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130323155511_add_prediction_id_to_bids.rb
@@ -0,0 +1,5 @@
class AddPredictionIdToBids < ActiveRecord::Migration
def change
add_column :bids, :prediction_id, :integer
end
end
11 changes: 11 additions & 0 deletions db/migrate/20130323155754_create_buys.rb
@@ -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
20 changes: 19 additions & 1 deletion db/schema.rb
Expand Up @@ -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"
Expand All @@ -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|
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/bids.yml
@@ -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
11 changes: 11 additions & 0 deletions test/fixtures/buys.yml
@@ -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
49 changes: 49 additions & 0 deletions test/functional/bids_controller_test.rb
@@ -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

0 comments on commit 16b9398

Please sign in to comment.