Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jackquack/BitPredictor
base: c813fe6829
...
head fork: jackquack/BitPredictor
compare: c6a9339306
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 40 files changed
  • 0 commit comments
  • 1 contributor
Showing with 234 additions and 149 deletions.
  1. +1 −1  Gemfile
  2. +2 −2 Gemfile.lock
  3. +1 −1  app/assets/stylesheets/bids.css.scss
  4. +0 −2  app/controllers/bids_controller.rb
  5. +5 −0 app/controllers/buys_controller.rb
  6. +1 −1  app/controllers/predictions_controller.rb
  7. +7 −0 app/controllers/sells_controller.rb
  8. +0 −2  app/helpers/bids_helper.rb
  9. +2 −0  app/helpers/sells_helper.rb
  10. +0 −3  app/models/bid.rb
  11. +3 −1 app/models/buy.rb
  12. +3 −0  app/models/prediction.rb
  13. +5 −0 app/models/sell.rb
  14. +4 −0 app/models/user.rb
  15. +0 −16 app/views/bids/_form.html.haml
  16. +0 −7 app/views/bids/edit.html.haml
  17. +0 −21 app/views/bids/index.html.haml
  18. +0 −5 app/views/bids/new.html.haml
  19. +0 −12 app/views/bids/show.html.haml
  20. +3 −8 app/views/buys/_form.html.haml
  21. +2 −2 app/views/buys/index.html.haml
  22. +3 −3 app/views/buys/show.html.haml
  23. +2 −1  app/views/layouts/application.html.haml
  24. +48 −9 app/views/predictions/show.html.haml
  25. +14 −0 app/views/sells/_form.html.haml
  26. +7 −0 app/views/sells/edit.html.haml
  27. +21 −0 app/views/sells/index.html.haml
  28. +5 −0 app/views/sells/new.html.haml
  29. +12 −0 app/views/sells/show.html.haml
  30. +21 −9 config/database.yml
  31. +5 −6 config/routes.rb
  32. +9 −0 db/migrate/20130323171725_rename_bids_to_sell.rb
  33. +11 −0 db/migrate/20130323172552_rename_price_to_number_of_shares.rb
  34. +12 −12 db/schema.rb
  35. +2 −2 test/fixtures/bids.yml
  36. +2 −2 test/fixtures/buys.yml
  37. +17 −17 test/functional/bids_controller_test.rb
  38. +2 −2 test/functional/buys_controller_test.rb
  39. +1 −1  test/unit/bid_test.rb
  40. +1 −1  test/unit/helpers/bids_helper_test.rb
View
2  Gemfile
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
gem 'rails'
-gem 'sqlite3'
+gem 'mysql2'
gem 'parallel'
gem 'json'
gem 'has_scope'
View
4 Gemfile.lock
@@ -111,6 +111,7 @@ GEM
mime-types (1.21)
multi_json (1.7.2)
multipart-post (1.2.0)
+ mysql2 (0.3.11)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
@@ -190,7 +191,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.7)
squeel (1.0.18)
activerecord (~> 3.0)
activesupport (~> 3.0)
@@ -225,6 +225,7 @@ DEPENDENCIES
js-routes
json
kaminari
+ mysql2
nested_form!
omniauth-facebook
parallel
@@ -239,6 +240,5 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sentient_user
simple_form (= 2.0.1)
- sqlite3
squeel
uglifier (>= 1.0.3)
View
2  app/assets/stylesheets/bids.css.scss
@@ -1,3 +1,3 @@
-// Place all the styles related to the Bids controller here.
+// Place all the styles related to the Sells controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
View
2  app/controllers/bids_controller.rb
@@ -1,2 +0,0 @@
-class BidsController < InheritedResources::Base
-end
View
5 app/controllers/buys_controller.rb
@@ -1,2 +1,7 @@
class BuysController < InheritedResources::Base
+ belongs_to :prediction, :optional => true
+ def create
+ params[:buy][:user_id] = current_user.id
+ create!
+ end
end
View
2  app/controllers/predictions_controller.rb
@@ -1,6 +1,6 @@
class PredictionsController < InheritedResources::Base
def create
- params[:user_id] = current_user.id
+ params[:prediction][:user_id] = current_user.id
create!
end
end
View
7 app/controllers/sells_controller.rb
@@ -0,0 +1,7 @@
+class SellsController < InheritedResources::Base
+ belongs_to :prediction, :optional => true
+ def create
+ params[:sell][:user_id] = current_user.id
+ create!
+ end
+end
View
2  app/helpers/bids_helper.rb
@@ -1,2 +0,0 @@
-module BidsHelper
-end
View
2  app/helpers/sells_helper.rb
@@ -0,0 +1,2 @@
+module SellsHelper
+end
View
3  app/models/bid.rb
@@ -1,3 +0,0 @@
-class Bid < ActiveRecord::Base
- attr_accessible :price, :user_id
-end
View
4 app/models/buy.rb
@@ -1,3 +1,5 @@
class Buy < ActiveRecord::Base
- attr_accessible :prediction_id, :price, :user_id
+ attr_accessible :prediction_id, :number_of_shares, :user_id
+ belongs_to :prediction
+ belongs_to :user
end
View
3  app/models/prediction.rb
@@ -1,3 +1,6 @@
class Prediction < ActiveRecord::Base
attr_accessible :end_date, :name, :prediction, :source, :verified_by
+ has_many :sells
+ has_many :buys
+ belongs_to :user
end
View
5 app/models/sell.rb
@@ -0,0 +1,5 @@
+class Sell < ActiveRecord::Base
+ attr_accessible :number_of_shares, :user_id, :prediction_id
+ belongs_to :prediction
+ belongs_to :user
+end
View
4 app/models/user.rb
@@ -2,6 +2,10 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, :omniauth_providers => [:facebook]
+ has_many :predictions
+ has_many :sells
+ has_many :buys
+
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name
# attr_accessible :title, :body
View
16 app/views/bids/_form.html.haml
@@ -1,16 +0,0 @@
-= 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'
View
7 app/views/bids/edit.html.haml
@@ -1,7 +0,0 @@
-%h1 Editing bid
-
-= render 'form'
-
-= link_to 'Show', @bid
-\|
-= link_to 'Back', bids_path
View
21 app/views/bids/index.html.haml
@@ -1,21 +0,0 @@
-%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
View
5 app/views/bids/new.html.haml
@@ -1,5 +0,0 @@
-%h1 New bid
-
-= render 'form'
-
-= link_to 'Back', bids_path
View
12 app/views/bids/show.html.haml
@@ -1,12 +0,0 @@
-%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
View
11 app/views/buys/_form.html.haml
@@ -7,13 +7,8 @@
%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
+ = f.label :number_of_shares
+ = f.text_field :number_of_shares
+ = f.hidden_field :prediction_id, :value => @prediction.id
.actions
= f.submit 'Save'
View
4 app/views/buys/index.html.haml
@@ -2,7 +2,7 @@
%table
%tr
- %th Price
+ %th NumberOfShares
%th User
%th Prediction
%th
@@ -11,7 +11,7 @@
- @buys.each do |buy|
%tr
- %td= buy.price
+ %td= buy.number_of_shares
%td= buy.user_id
%td= buy.prediction_id
%td= link_to 'Show', buy
View
6 app/views/buys/show.html.haml
@@ -1,8 +1,8 @@
%p#notice= notice
%p
- %b Price:
- = @buy.price
+ %b NumberOfShares:
+ = @buy.number_of_shares
%p
%b User:
= @buy.user_id
@@ -12,4 +12,4 @@
= link_to 'Edit', edit_buy_path(@buy)
\|
-= link_to 'Back', buys_path
+= link_to 'Back', prediction_path(@buy.prediction_id)
View
3  app/views/layouts/application.html.haml
@@ -1,13 +1,14 @@
!!!
%html
%head
- %title BitPredictor
+ %title BitPredictor - Predicting Your Bits Since 2013
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
%p.notice= notice
%p.alert= alert
+ %h1 Prediction Done Right (kinda)
- if !current_user
= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook)
- else
View
57 app/views/predictions/show.html.haml
@@ -1,8 +1,5 @@
+%h1= @prediction.name
%p#notice= notice
-
-%p
- %b Name:
- = @prediction.name
%p
%b End date:
= @prediction.end_date
@@ -10,11 +7,53 @@
%b Prediction:
= @prediction.prediction
%p
- %b Source:
- = @prediction.source
-%p
- %b Verified by:
- = @prediction.verified_by
+ %b Created By:
+ = @prediction.user.name
+
+%h1 Place Your Bits
+%h2 Listing sells
+
+%table
+ %tr
+ %th NumberOfShares
+ %th User
+ %th
+ %th
+ %th
+
+ - @prediction.sells.each do |sell|
+ %tr
+ %td= sell.number_of_shares
+ %td= sell.user.name
+ %td= link_to 'Show', sell
+ %td= link_to 'Edit', edit_sell_path(sell)
+ %td= link_to 'Destroy', sell, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+= link_to 'New Sell', new_prediction_sell_path(@prediction.id)
+
+%h2 Listing buys
+
+%table
+ %tr
+ %th NumberOfShares
+ %th User
+ %th Prediction
+ %th
+ %th
+ %th
+
+ - @prediction.buys.each do |buy|
+ %tr
+ %td= buy.number_of_shares
+ %td= buy.user.name
+ %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_prediction_buy_path(@prediction.id)
= link_to 'Edit', edit_prediction_path(@prediction)
\|
View
14 app/views/sells/_form.html.haml
@@ -0,0 +1,14 @@
+= form_for @sell do |f|
+ - if @sell.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@sell.errors.count, "error")} prohibited this sell from being saved:"
+ %ul
+ - @sell.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :number_of_shares
+ = f.text_field :number_of_shares
+ = f.hidden_field :prediction_id, :value => @prediction.id
+ .actions
+ = f.submit 'Save'
View
7 app/views/sells/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing sell
+
+= render 'form'
+
+= link_to 'Show', @sell
+\|
+= link_to 'Back', sells_path
View
21 app/views/sells/index.html.haml
@@ -0,0 +1,21 @@
+%h1 Listing sells
+
+%table
+ %tr
+ %th NumberOfShares
+ %th User
+ %th
+ %th
+ %th
+
+ - @sells.each do |sell|
+ %tr
+ %td= sell.number_of_shares
+ %td= sell.user_id
+ %td= link_to 'Show', sell
+ %td= link_to 'Edit', edit_sell_path(sell)
+ %td= link_to 'Destroy', sell, :method => :delete, :data => { :confirm => 'Are you sure?' }
+
+%br
+
+= link_to 'New Sell', new_sell_path
View
5 app/views/sells/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New sell
+
+= render 'form'
+
+= link_to 'Back', sells_path
View
12 app/views/sells/show.html.haml
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b NumberOfShares:
+ = @sell.number_of_shares
+%p
+ %b User:
+ = @sell.user_id
+
+= link_to 'Edit', edit_sell_path(@sell)
+\|
+= link_to 'Back', prediction_path(@sell.prediction_id)
View
30 config/database.yml
@@ -4,22 +4,34 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
- adapter: sqlite3
- database: db/development.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_development
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: sqlite3
- database: db/test.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_test
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
production:
- adapter: sqlite3
- database: db/production.sqlite3
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: bitpredictor_production
pool: 5
- timeout: 5000
+ username: root
+ password: root
+ socket: /tmp/mysql.sock
View
11 config/routes.rb
@@ -1,11 +1,10 @@
BitPredictor::Application.routes.draw do
resources :buys
-
-
- resources :bids
-
-
- resources :predictions
+ resources :sells
+ resources :predictions do
+ resources :buys
+ resources :sells
+ end
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks"}
View
9 db/migrate/20130323171725_rename_bids_to_sell.rb
@@ -0,0 +1,9 @@
+class RenameBidsToSell < ActiveRecord::Migration
+ def self.up
+ rename_table :bids, :sells
+ end
+
+ def self.down
+ rename_table :sells, :bids
+ end
+end
View
11 db/migrate/20130323172552_rename_price_to_number_of_shares.rb
@@ -0,0 +1,11 @@
+class RenamePriceToNumberOfShares < ActiveRecord::Migration
+ def up
+ rename_column :sells, :price, :number_of_shares
+ rename_column :buys, :price, :number_of_shares
+ end
+
+ def down
+ rename_column :sells, :price, :number_of_shares
+ rename_column :buys, :price, :number_of_shares
+ end
+end
View
24 db/schema.rb
@@ -11,22 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.
-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
+ActiveRecord::Schema.define(:version => 20130323172552) do
create_table "buys", :force => true do |t|
- t.decimal "price"
+ t.decimal "number_of_shares", :precision => 10, :scale => 0
t.integer "user_id"
t.integer "prediction_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "predictions", :force => true do |t|
@@ -40,6 +32,14 @@
t.integer "user_id"
end
+ create_table "sells", :force => true do |t|
+ t.decimal "number_of_shares", :precision => 10, :scale => 0
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "prediction_id"
+ end
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
View
4 test/fixtures/bids.yml
@@ -1,9 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
- price: 9.99
+ number_of_shares: 9.99
user_id: 1
two:
- price: 9.99
+ number_of_shares: 9.99
user_id: 1
View
4 test/fixtures/buys.yml
@@ -1,11 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
- price: 9.99
+ number_of_shares: 9.99
user_id: 1
prediction_id: 1
two:
- price: 9.99
+ number_of_shares: 9.99
user_id: 1
prediction_id: 1
View
34 test/functional/bids_controller_test.rb
@@ -1,14 +1,14 @@
require 'test_helper'
-class BidsControllerTest < ActionController::TestCase
+class SellsControllerTest < ActionController::TestCase
setup do
- @bid = bids(:one)
+ @sell = sells(:one)
end
test "should get index" do
get :index
assert_response :success
- assert_not_nil assigns(:bids)
+ assert_not_nil assigns(:sells)
end
test "should get new" do
@@ -16,34 +16,34 @@ class BidsControllerTest < ActionController::TestCase
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 }
+ test "should create sell" do
+ assert_difference('Sell.count') do
+ post :create, sell: { number_of_shares: @sell.number_of_shares, user_id: @sell.user_id }
end
- assert_redirected_to bid_path(assigns(:bid))
+ assert_redirected_to sell_path(assigns(:sell))
end
- test "should show bid" do
- get :show, id: @bid
+ test "should show sell" do
+ get :show, id: @sell
assert_response :success
end
test "should get edit" do
- get :edit, id: @bid
+ get :edit, id: @sell
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))
+ test "should update sell" do
+ put :update, id: @sell, sell: { number_of_shares: @sell.number_of_shares, user_id: @sell.user_id }
+ assert_redirected_to sell_path(assigns(:sell))
end
- test "should destroy bid" do
- assert_difference('Bid.count', -1) do
- delete :destroy, id: @bid
+ test "should destroy sell" do
+ assert_difference('Sell.count', -1) do
+ delete :destroy, id: @sell
end
- assert_redirected_to bids_path
+ assert_redirected_to sells_path
end
end
View
4 test/functional/buys_controller_test.rb
@@ -18,7 +18,7 @@ class BuysControllerTest < ActionController::TestCase
test "should create buy" do
assert_difference('Buy.count') do
- post :create, buy: { prediction_id: @buy.prediction_id, price: @buy.price, user_id: @buy.user_id }
+ post :create, buy: { prediction_id: @buy.prediction_id, number_of_shares: @buy.number_of_shares, user_id: @buy.user_id }
end
assert_redirected_to buy_path(assigns(:buy))
@@ -35,7 +35,7 @@ class BuysControllerTest < ActionController::TestCase
end
test "should update buy" do
- put :update, id: @buy, buy: { prediction_id: @buy.prediction_id, price: @buy.price, user_id: @buy.user_id }
+ put :update, id: @buy, buy: { prediction_id: @buy.prediction_id, number_of_shares: @buy.number_of_shares, user_id: @buy.user_id }
assert_redirected_to buy_path(assigns(:buy))
end
View
2  test/unit/bid_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class BidTest < ActiveSupport::TestCase
+class SellTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
View
2  test/unit/helpers/bids_helper_test.rb
@@ -1,4 +1,4 @@
require 'test_helper'
-class BidsHelperTest < ActionView::TestCase
+class SellsHelperTest < ActionView::TestCase
end

No commit comments for this range

Something went wrong with that request. Please try again.