't moet af, orders werken

This commit is contained in:
ohsab 2014-11-23 21:12:31 +01:00
parent df24bcd58e
commit 4318f5b56a
73 changed files with 295 additions and 802 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

16
Gemfile
View file

@ -1,5 +1,6 @@
source 'https://rubygems.org'
ruby '2.1.4'
ruby '2.1.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
@ -23,6 +24,9 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
@ -35,17 +39,15 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin , :x64_mingw]
#bootstrap
gem 'bootstrap-sass', '3.2.0.0'
#debug stuff
gem 'byebug'
#generate data
gem 'faker', '1.4.2'
#passwords
gem 'bcrypt', '3.1.7'
#paginate stuff
gem 'will_paginate', '3.0.7'

View file

@ -28,11 +28,16 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
bootstrap-will_paginate (0.0.10)
will_paginate
builder (3.2.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@ -40,13 +45,13 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.8.0)
columnize (0.8.9)
debugger-linecache (1.2.0)
erubis (2.7.0)
execjs (2.2.2)
faker (1.4.2)
i18n (~> 0.5)
hike (1.2.3)
i18n (0.6.11)
jbuilder (2.2.4)
jbuilder (2.2.5)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.2)
@ -56,7 +61,7 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
minitest (5.4.2)
minitest (5.4.3)
multi_json (1.10.1)
rack (1.5.2)
rack-test (0.6.2)
@ -88,6 +93,8 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slop (3.6.0)
spring (1.2.0)
sprockets (2.11.3)
hike (~> 1.2)
multi_json (~> 1.0)
@ -97,36 +104,35 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10-x64-mingw32)
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
turbolinks (2.5.1)
turbolinks (2.5.2)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2014.9)
tzinfo (>= 1.0.0)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
will_paginate (3.0.7)
PLATFORMS
x64-mingw32
ruby
DEPENDENCIES
bcrypt (= 3.1.7)
bootstrap-sass (= 3.2.0.0)
bootstrap-will_paginate (= 0.0.10)
byebug
coffee-rails (~> 4.0.0)
faker (= 1.4.2)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.1.7)
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
spring
sqlite3
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
will_paginate (= 3.0.7)

View file

@ -1,3 +0,0 @@
# 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://coffeescript.org/

View file

@ -1,3 +0,0 @@
# 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://coffeescript.org/

View file

@ -1,3 +0,0 @@
# 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://coffeescript.org/

View file

@ -1,74 +1,3 @@
@import "bootstrap-sprockets";
@import "bootstrap";
body {
padding-top: 60px;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: #fff;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
}
#logo:hover {
color: #fff;
text-decoration: none;
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid #eaeaea;
color: #777;
}
footer a {
color: #555;
}
footer a:hover {
color: #222;
}
footer small {
float: left;
}
footer ul {
float: right;
list-style: none;
}
footer ul li {
float: left;
margin-left: 15px;
}
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
@ -84,3 +13,43 @@ footer ul li {
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables, etc. */
$gray-medium-light: #eaeaea;
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.
.
.
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}

View file

@ -1,3 +0,0 @@
// Place all the styles related to the Products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -1,3 +0,0 @@
// Place all the styles related to the Sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -1,3 +0,0 @@
// Place all the styles related to the StaticPages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -1,3 +1,32 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
/* sidebar */
aside {
section.user_info {
margin-top: 20px;
}
section {
padding: 10px 0;
margin-top: 20px;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}

View file

@ -2,18 +2,6 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
include ProductsHelper
include OrdersHelper
private
# Confirms a logged-in user.
def logged_in_user
unless logged_in?
store_location
#flash[:danger] = "Please log in."
redirect_to login_url
end
end
include OrdersHelper
end

View file

@ -1,29 +1,37 @@
class OrdersController < ApplicationController
before_action :logged_in_user, only: [ :destroy]
def new
@users = User.all
end
def create_session
user = User.find(params[:user_id])
if user
ordering(user)
redirect_to order_path
else
redirect_to overview_path
end
end
def order
@order = current_ordering_user.orders.build
end
def create
@order = current_ordering_user.orders.build(order_params)
if @order.save
flash[:success] = "order created!"
end_order
redirect_to overview_path
else
redirect_to overview_path
end
end
def destroy
end
def show
@user = User.find(params[:id])
@order = @user.orders.build
end
def create
user = User.find( 3) #MUST BE FIXED
@order = user.orders.build(order_params)
if @order.save
#@flash[:success] = "Micropost created!"
redirect_to root_url
else
@logs = []
render 'static_pages/home'
end
end_order
redirect_to overview_path
end
private
@ -31,6 +39,4 @@ class OrdersController < ApplicationController
def order_params
params.require(:order).permit(:products)
end
end

View file

@ -1,41 +0,0 @@
class ProductsController < ApplicationController
def new
@product = Product.new
end
def show
@product = Product.find(params[:id])
end
def create
@product = Product.new(product_params) # Not the final implementation!
if @product.save
redirect_to @product
else
render 'new'
end
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to @product
else
render 'edit'
end
end
private
def product_params
params.require(:product).permit(:name, :sale_price, :purchase_price,
:image_path)
end
end

View file

@ -1,21 +0,0 @@
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(name: params[:session][:name])
if user
log_in user
redirect_back_or user
else
#flash.now[:danger] = 'Invalid username'
render 'new'
end
end
def destroy
log_out
redirect_to root_url
end
end

View file

@ -1,19 +0,0 @@
class StaticPagesController < ApplicationController
def home
if logged_in?
@order = current_user.orders.build if logged_in?
@logs = current_user.feed.paginate(page: params[:page])
end
end
def overview
@users = User.all
end
def order
end
def help
end
end

View file

@ -1,68 +1,30 @@
class UsersController < ApplicationController
before_action :logged_in_user, only: [ :index, :edit, :update, :show]
before_action :correct_user, only: [:edit, :update]
def index
@users = User.paginate(page: params[:page])
end
def new
@user = User.new
@user = User.new
end
def show
@user = User.find(params[:id])
@user = User.find(params[:id])
@orders = @user.orders.paginate(page: params[:page])
end
def create
@user = User.new(user_params)
if @user.save
log_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def order
@user = User.find(params[:id])
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
@user = User.new(user_params)
if @user.save
redirect_to @user
else
render 'edit'
render 'new'
end
end
def index
@users = User.all
end
private
def user_params
params.require(:user).permit(:name, :marks)
end
# Confirms a logged-in user.
def logged_in_user
unless logged_in?
store_location
flash[:danger] = "Please log in."
redirect_to login_url
end
end
# Confirms the correct user.
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
def user_params
params.require(:user).permit(:name, :last_name, :password,
:password_confirmation, :nickname)
end
end

View file

@ -1,10 +1,20 @@
module OrdersHelper
def select_user(user)
selected_user = user.id
end
def ordering(user)
session[:order_user_id] = user.id
end
def current_ordering_user
@current_ordering_user ||= User.find_by(id: session[:order_user_id])
end
def end_order
session.delete(:order_user_id)
@current_ordering_user = nil
end
def ordering?
!current_ordering_user.nil?
end
def selected_user
return selected_user
end
end

View file

@ -1,6 +0,0 @@
module ProductsHelper
def current_product?(product)
product == current_product
end
end

View file

@ -1,36 +0,0 @@
module SessionsHelper
def log_in(user)
session[:user_id] = user.id
end
def current_user
@current_user ||= User.find_by(id: session[:user_id])
end
def logged_in?
!current_user.nil?
end
def log_out
session.delete(:user_id)
@current_user = nil
end
# Redirects to stored location (or to the default).
def redirect_back_or(default)
redirect_to(session[:forwarding_url] || default)
session.delete(:forwarding_url)
end
# Stores the URL trying to be accessed.
def store_location
session[:forwarding_url] = request.url if request.get?
end
def current_user?(user)
user == current_user
end
end

View file

@ -1,2 +0,0 @@
module StaticPagesHelper
end

View file

@ -1,6 +1,4 @@
class Order < ActiveRecord::Base
belongs_to :user
belongs_to :users
default_scope -> { order('created_at DESC') }
validates :products, presence: true, length: { maximum: 140 }
end

View file

@ -1,11 +0,0 @@
class Product < ActiveRecord::Base
after_initialize :init
def init
self.name ||= "FOOBAR"
self.sale_price ||= 0
self.purchase_price ||= 0
self.image_path ||= "/" #paperclip gem
end
end

View file

@ -1,18 +1,13 @@
class User < ActiveRecord::Base
has_many :orders, dependent: :destroy
after_initialize :init
has_many :orders
before_save :init
validates :name, presence: true, length: { maximum: 50 },
uniqueness: true
def init
self.marks ||= 0
self.role ||= "user"
def init
self.balance ||= 0
end
def feed
# This is preliminary. See "Following users" for the full implementation.
Order.where("user_id = ?", id)
end
has_secure_password
end

View file

@ -1,13 +0,0 @@
<footer class="footer">
<small>
Tab, <a href="#">The barman</a>
by <a href="#">Basho</a>
</small>
<nav>
<ul>
<li><%= link_to "About", '#' %></li>
<li><%= link_to "Contact", '#' %></li>
<li><a href="http://zeus.ugent.be/">News</a></li>
</ul>
</nav>
</footer>

View file

@ -1,33 +0,0 @@
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to 'Taþ' , root_path , id: "logo" %>
<nav>
<ul class="nav navbar-nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Overview", overview_path %></li>
<li><%= link_to "Help", help_path %></li>
<!-- account -->
<% if logged_in? %>
<li><%= link_to "Users", users_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Log in", login_path %></li>
<% end %>
</ul>
</nav>
</div>
</header>

View file

@ -1,18 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>TaÞ</title>
<title>Tab002</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
<%= yield %>
<%= debug(params) if Rails.env.development? %>
</body>
</html>

View file

@ -1,6 +1,4 @@
<li id="order-<%= order.id %>">
<span class="user"><%= link_to order.user.name, order.user %></span>
<span class="products"><%= order.products %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(order.created_at) %> ago.

View file

@ -1,3 +1,17 @@
<h1>Orders#new</h1>
<p>Find me in app/views/orders/new.html.erb</p>
<p>In opbouw!</p>
<ul class="users">
<% @users.each do |user| %>
<li>
<%= form_for overview_path do |f| %>
<%= hidden_field_tag 'user_id', user.id %>
<%= f.submit user.name , class: "btn btn-primary" %>
<% end %>
</li>
<% end %>
</ul>

View file

@ -1,5 +1,5 @@
<%= form_for(@order) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= current_ordering_user.name %>
<%= form_for @order do |f| %>
<div class="field">
<%= f.text_area :products, placeholder: "Compose new order..." %>
</div>

View file

@ -1,3 +0,0 @@
<%= @user.name %>
<%= render 'shared/order_form' %>

View file

@ -1,2 +0,0 @@
<h1>Products#create</h1>
<p>Find me in app/views/products/create.html.erb</p>

View file

@ -1,26 +0,0 @@
<h1>Product edit</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@product) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :purchase_price %>
<%= f.number_field :purchase_price %>
</br>
<%= f.label :sale_price %>
<%= f.number_field :sale_price %>
</br>
<%= f.label :image_path %>
<%= f.text_field :image_path %>
</br>
<%= f.submit "Update product", class: "btn btn-primary" %>
<% end %>
</div>
</div>

View file

@ -1,25 +0,0 @@
<h1>Product creation</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@product) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :purchase_price %>
<%= f.number_field :purchase_price %>
</br>
<%= f.label :sale_price %>
<%= f.number_field :sale_price %>
</br>
<%= f.label :image_path %>
<%= f.text_field :image_path %>
</br>
<%= f.submit "Create product", class: "btn btn-primary" %>
<% end %>
</div>
</div>

View file

@ -1,8 +0,0 @@
<h1>Products#show</h1>
<p>Find me in app/views/products/show.html.erb</p>
name: <%= @product.name %></br>
verkoop prijs: <%= @product.sale_price %> EUR cent</br>
aankoop prijs: <%= @product.purchase_price %> EUR cent</br>
<%= link_to "Edit", edit_product_path(@product), class: "btn btn-lg btn-primary" %>

View file

@ -1,19 +0,0 @@
<h1>Sessions#new</h1>
<p>Find me in app/views/sessions/new.html.erb</p>
<h1>Log in</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.submit "Log in", class: "btn btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>

View file

@ -1,12 +0,0 @@
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

View file

@ -1,6 +0,0 @@
<% if @logs.any? %>
<ol class="orders">
<%= render @logs %>
</ol>
<%= will_paginate @logs %>
<% end %>

View file

@ -1,3 +0,0 @@
<h1><%= current_user.name %></h1>
<span><%= link_to "view my profile", current_user %></span>
<span><%= pluralize(current_user.orders.count, "order") %></span>

View file

@ -1,14 +0,0 @@
<% @users.each do |user| %>
<% link = 'orders/' + user.id.to_s %>
<tr class="clickableRow" href= <%= link %> >
<td><%= user.id %></td>
<td><%= user.name %></td>
<td><% user.marks.times do %>
<%= "|" %>
<% end %>
</td>
<td></td>
<td></td>
</tr>
<%end%>

View file

@ -1 +0,0 @@
<h1> HELP MIJ!!!! O.O </h1>

View file

@ -1,24 +0,0 @@
<h1>StaticPages#home</h1>
<p>Find me in app/views/static_pages/home.html.erb</p>
<% if logged_in? %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<%= render 'shared/user_info' %>
</section>
<section class="order_form">
<%= render 'shared/order_form' %>
</section>
</aside>
<div class="col-md-8">
<h3>User logs</h3>
<%= render 'shared/feed' %>
</div>
</div>
<% else %>
<%= link_to "Sign up now!", signup_path , class: "btn btn-lg btn-primary" %>
<% end %>

View file

@ -1,26 +0,0 @@
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Marks</th>
<th> </th>
<th></th>
</tr>
</thead>
<tbody>
<%= render "static_pages/user" %>
</tbody>
</table>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".clickableRow").click(function() {
window.document.location = $(this).attr("href");
});
});
</script>

View file

@ -1,23 +0,0 @@
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :marks %>
<%= f.number_field :marks, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
</div>
</div>

View file

@ -1,7 +1,5 @@
<h1>All users</h1>
<%= will_paginate %>
<ul class="users">
<% @users.each do |user| %>
<li>
@ -9,5 +7,3 @@
</li>
<% end %>
</ul>
<%= will_paginate %>

View file

@ -3,15 +3,21 @@
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :nickname %>
<%= f.text_field :nickname %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :marks %>
<%= f.number_field :marks %> (tijdelijk)
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
</br>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>

View file

View file

@ -1,13 +1,22 @@
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<h1>Name: <%= @user.name %></h1>
<h1>Last name: <%= @user.last_name %></h1>
<h1>Nickname: <%= @user.nickname %></h1>
<h1>Balance: <%= @user.balance %></h1>
<h1>User id: <%= @user.id %></h1>
<% if ordering? %>
<h1>Ordering!</h1>
<% else %>
<h1>Not ordering!</h1>
<% end %>
<%= link_to "End order", end_order_path, method: "delete" %>
<%= @user.name %>
<%= @user.marks %>
</h1>
</section>
</aside>
<div class="col-md-8">
<% if @user.orders.any? %>
<h3>Orders (<%= @user.orders.count %>)</h3>

2
bin/bundle Normal file → Executable file
View file

@ -1,3 +1,3 @@
#!/usr/bin/env ruby.exe
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

6
bin/rails Normal file → Executable file
View file

@ -1,4 +1,8 @@
#!/usr/bin/env ruby.exe
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

6
bin/rake Normal file → Executable file
View file

@ -1,4 +1,8 @@
#!/usr/bin/env ruby.exe
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require_relative '../config/boot'
require 'rake'
Rake.application.run

18
bin/spring Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command
unless defined?(Spring)
require "rubygems"
require "bundler"
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = ""
Gem.paths = ENV
gem "spring", match[1]
require "spring/binstub"
end
end

View file

@ -6,7 +6,7 @@ require 'rails/all'
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Tab
module Tab002
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers

View file

@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_Tab_session'
Rails.application.config.session_store :cookie_store, key: '_Tab_0_0_2_session'

View file

@ -1,43 +1,17 @@
Rails.application.routes.draw do
get 'products/new'
get 'products/show'
get 'products/create'
get 'products/edit'
get 'orders/show'
root 'static_pages#home'
get 'sessions/new'
get 'users/new'
get 'help' => 'static_pages#help'
get 'static_pages/home'
get 'overview' => 'static_pages#overview'
get 'static_pages/overview'
#order stuff
get 'order' => 'orders#new'
post 'order' => 'orders#create'
delete 'chaos' => 'orders#destroy'
#account stuff
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
root "users#index"
resources :users
resources :orders
#product
resources :products
get 'overview' => 'orders#new'
post 'overview' => 'orders#create_session'
delete 'end_order' => 'orders#destroy'
get 'order' => 'orders#order'
post 'orders' => 'orders#create'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

View file

@ -11,10 +11,10 @@
# if you're sharing your code publicly.
development:
secret_key_base: 00f7233f9fe2e58e16b50f63f48e7160e9e99152b092004907130f4b7b8e3aac1b03f80b78b7666edf83ed84e20fd81890eec7e09ef3198cb47ee91bd08fa0ef
secret_key_base: 5d40610321e19e4f71ee2ba8af4f426fe15096c405da3800c6b33bed6779f2d11f55a0edc455974b19a01fd71f6cd508dba980305dbc55ff82521a2d12f891d8
test:
secret_key_base: c3861256e97380e1bcc1b78be6a5cc5b1b4bb3caacad11bb3b8de0d1a27d8df35d6fb6fe41f7c5cd41235c49d8ebd63a8aacf9925410a6714dc051b22edc2783
secret_key_base: 961437e28e7d6055ffaad9cf1f8d614354f57f10cb2d7601c9d6ede72a03b9c9535ad9e63507e3eb31252c4895970a63117493408f2e9a46c7a0c4a5a7836b81
# Do not keep production secrets in the repository,
# instead read values from the environment.

View file

@ -1,13 +0,0 @@
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.integer :sale_price
t.integer :purchase_price
t.string :image_path
t.string :type
t.timestamps
end
end
end

View file

@ -2,8 +2,10 @@ class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.integer :marks
t.string :role
t.string :last_name
t.integer :balance
t.string :nickname
t.string :password_digest
t.timestamps
end

View file

@ -1,10 +1,11 @@
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
t.text :products
t.references :user, index: true
t.string :products
t.integer :cost
t.timestamps
t.timestamps null: false
end
add_index :orders, [:user_id, :created_at]
end

View file

@ -11,32 +11,25 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141110141100) do
ActiveRecord::Schema.define(version: 20141123151756) do
create_table "orders", force: true do |t|
t.text "products"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "products"
t.integer "cost"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "orders", ["user_id", "created_at"], name: "index_orders_on_user_id_and_created_at"
add_index "orders", ["user_id"], name: "index_orders_on_user_id"
create_table "products", force: true do |t|
t.string "name"
t.integer "sale_price"
t.integer "purchase_price"
t.string "image_path"
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: true do |t|
t.string "name"
t.integer "marks"
t.string "role"
t.string "last_name"
t.integer "balance"
t.string "nickname"
t.string "password_digest"
t.datetime "created_at"
t.datetime "updated_at"
end

View file

@ -5,19 +5,3 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
User.create!(name: "Example User", marks: 5)
99.times do |n|
name = Faker::Name.name
marks = n+1
User.create!(name: name,
marks: marks)
end
users = User.order(:created_at).take(6)
50.times do
products = Faker::Lorem.sentence(5)
users.each { |user| user.orders.create!(products: products) }
end

View file

@ -1,9 +1,7 @@
require 'test_helper'
class OrdersControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
# test "the truth" do
# assert true
# end
end

View file

@ -1,24 +0,0 @@
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
test "should get show" do
get :show
assert_response :success
end
test "should get create" do
get :create
assert_response :success
end
test "should get edit" do
get :edit
assert_response :success
end
end

View file

@ -1,9 +0,0 @@
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end

View file

@ -1,14 +0,0 @@
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
end
test "should get overview" do
get :overview
assert_response :success
end
end

View file

@ -6,4 +6,9 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
end
test "should get show" do
get :show
assert_response :success
end
end

View file

@ -1,9 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
products:
user_id:
user:
products: MyString
cost:
two:
products:
user_id:
user:
products: MyString
cost:

View file

@ -1,11 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
sale-price: 1
purchase-price: 1
two:
name: MyString
sale-price: 1
purchase-price: 1

View file

@ -2,10 +2,14 @@
one:
name: MyString
marks: 1
role: MyString
last_name: MyString
balance: 1
nickname: MyString
password_digest: MyString
two:
name: MyString
marks: 1
role: MyString
last_name: MyString
balance: 1
nickname: MyString
password_digest: MyString

View file

@ -1,4 +0,0 @@
require 'test_helper'
class ProductsHelperTest < ActionView::TestCase
end

View file

@ -1,4 +0,0 @@
require 'test_helper'
class SessionsHelperTest < ActionView::TestCase
end

View file

@ -1,4 +0,0 @@
require 'test_helper'
class StaticPagesHelperTest < ActionView::TestCase
end

View file

@ -1,7 +0,0 @@
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end