Permalink
Browse files

add gitignore file

  • Loading branch information...
1 parent 1a6070c commit f618ff6c3827a60253428c58dac312d3c9c9260e @haio committed Nov 16, 2012
Showing with 984 additions and 10 deletions.
  1. +15 −0 .gitignore
  2. +1 −0 Gemfile
  3. +3 −0 app/assets/javascripts/admin.js.coffee
  4. +3 −0 app/assets/javascripts/orders.js.coffee
  5. +3 −0 app/assets/javascripts/sessions.js.coffee
  6. +3 −0 app/assets/javascripts/store.js.coffee
  7. +3 −0 app/assets/javascripts/users.js.coffee
  8. +3 −0 app/assets/stylesheets/admin.css.scss
  9. +3 −0 app/assets/stylesheets/orders.css.scss
  10. +3 −0 app/assets/stylesheets/sessions.css.scss
  11. +3 −0 app/assets/stylesheets/users.css.scss
  12. +5 −0 app/controllers/admin_controller.rb
  13. +5 −0 app/controllers/blog_controller.rb
  14. +96 −0 app/controllers/orders_controller.rb
  15. +21 −0 app/controllers/sessions_controller.rb
  16. +83 −0 app/controllers/users_controller.rb
  17. +2 −0 app/helpers/admin_helper.rb
  18. +2 −0 app/helpers/orders_helper.rb
  19. +2 −0 app/helpers/sessions_helper.rb
  20. +2 −0 app/helpers/users_helper.rb
  21. +25 −0 app/mailers/notifier.rb
  22. +14 −0 app/models/article.rb
  23. +3 −0 app/models/discount.rb
  24. +16 −0 app/models/order.rb
  25. +5 −0 app/models/user.rb
  26. +4 −0 app/views/admin/index.html.erb
  27. +11 −0 app/views/blog/list.html.erb
  28. +2 −1 app/views/layouts/application.html.erb
  29. +3 −0 app/views/line_items/_line_item.text.erb
  30. +9 −0 app/views/notifier/order_received.text.erb
  31. +8 −0 app/views/notifier/order_shipped.html.erb
  32. +3 −0 app/views/notifier/order_shipped.text.erb
  33. +34 −0 app/views/orders/_form.html.erb
  34. +6 −0 app/views/orders/edit.html.erb
  35. +30 −0 app/views/orders/index.html.erb
  36. +6 −0 app/views/orders/new.html.erb
  37. +25 −0 app/views/orders/show.html.erb
  38. +41 −0 app/views/products/who_bought.atom.builder
  39. +2 −0 app/views/sessions/create.html.erb
  40. +2 −0 app/views/sessions/destroy.html.erb
  41. +25 −0 app/views/sessions/new.html.erb
  42. +37 −0 app/views/users/_form.html.erb
  43. +6 −0 app/views/users/edit.html.erb
  44. +25 −0 app/views/users/index.html.erb
  45. +5 −0 app/views/users/new.html.erb
  46. +15 −0 app/views/users/show.html.erb
  47. +12 −7 config/database.yml
  48. +4 −0 config/routes.rb
  49. 0 db/development.sqlite
  50. BIN db/development.sqlite3
  51. +1 −1 db/migrate/20120911145244_create_products.rb
  52. +12 −0 db/migrate/20121011144611_create_orders.rb
  53. +5 −0 db/migrate/20121011144720_add_order_id_to_line_item.rb
  54. +10 −0 db/migrate/20121013151639_create_users.rb
  55. +8 −0 db/migrate/20121030143730_create_discounts.rb
  56. +7 −0 db/migrate/20121030143905_add_price_column.rb
  57. +6 −1 db/schema.rb
  58. +7 −0 lib/tasks/db_schema_migrations.rake
  59. +6 −0 script/load_orders.rb
  60. +11 −0 test/fixtures/discounts.yml
  61. +13 −0 test/fixtures/orders.yml
  62. +8 −0 test/fixtures/users.yml
  63. +9 −0 test/functional/admin_controller_test.rb
  64. +20 −0 test/functional/notifier_test.rb
  65. +58 −0 test/functional/orders_controller_test.rb
  66. +19 −0 test/functional/sessions_controller_test.rb
  67. +55 −0 test/functional/users_controller_test.rb
  68. +53 −0 test/integration/user_stories_test.rb
  69. +7 −0 test/unit/discount_test.rb
  70. +4 −0 test/unit/helpers/admin_helper_test.rb
  71. +4 −0 test/unit/helpers/orders_helper_test.rb
  72. +4 −0 test/unit/helpers/sessions_helper_test.rb
  73. +4 −0 test/unit/helpers/users_helper_test.rb
  74. +7 −0 test/unit/order_test.rb
  75. +7 −0 test/unit/user_test.rb
  76. BIN tmp/cache/assets/CF9/180/sprockets%2F4116bb96b0fee7cc4866b799759b3792
  77. BIN tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
  78. BIN tmp/cache/assets/D96/470/sprockets%2F5dd6c018563912ffbd5c2e5e30add25c
  79. BIN tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
  80. BIN tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
  81. BIN tmp/cache/assets/EC1/7C0/sprockets%2F1d24c4ccdd69bf9f11bcefdce6bddb87
View
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
View
@@ -7,6 +7,7 @@ gem 'rails', '3.2.8'
gem 'sqlite3'
+
group :production do
gem 'mysql'
end
@@ -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 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/
@@ -1,3 +1,6 @@
# 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/
+$ ->
+ $('.store .entry >img').click ->
+ $(this).parent().find(':submit').click()
@@ -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 Admin 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 orders 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 Sessions 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 users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,5 @@
+class AdminController < ApplicationController
+ def index
+ @total_orders = Order.count
+ end
+end
@@ -0,0 +1,5 @@
+class BlogController < ApplicationController
+ def list
+ @dynamic_content = Time.now.to_s
+ end
+end
@@ -0,0 +1,96 @@
+class OrdersController < ApplicationController
+ skip_before_filter :authorize, only: [:new, :create]
+
+ # GET /orders
+ # GET /orders.json
+ def index
+ @orders = Order.paginate :page => params[:page], :order => 'created_at desc',
+ :per_page => 10
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @orders }
+ end
+ end
+
+ # GET /orders/1
+ # GET /orders/1.json
+ def show
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @order }
+ end
+ end
+
+ # GET /orders/new
+ # GET /orders/new.json
+ def new
+ @cart = current_cart
+ if @cart.line_items.empty?
+ redirect_to store_url, :notice => "Your cart is empty"
+ return
+ end
+
+ @order = Order.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @order }
+ end
+ end
+
+ # GET /orders/1/edit
+ def edit
+ @order = Order.find(params[:id])
+ end
+
+ # POST /orders
+ # POST /orders.json
+ def create
+ @order = Order.new(params[:order])
+ @order.add_line_items_from_cart(current_cart)
+
+ respond_to do |format|
+ if @order.save
+ Cart.destroy(session[:cart_id])
+ session[:cart_id] = nil
+ Notifier.order_received(@order).deliver
+ format.html { redirect_to(store_url, :notice => 'Thank you for your order.') }
+ format.json { render json: @order, status: :created, location: @order }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @order.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /orders/1
+ # PUT /orders/1.json
+ def update
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ if @order.update_attributes(params[:order])
+ format.html { redirect_to @order, notice: 'Order was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @order.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /orders/1
+ # DELETE /orders/1.json
+ def destroy
+ @order = Order.find(params[:id])
+ @order.destroy
+
+ respond_to do |format|
+ format.html { redirect_to orders_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,21 @@
+class SessionsController < ApplicationController
+ skip_before_filter :authorize
+
+ def new
+ end
+
+ def create
+ user = User.find_by_name(params[:name])
+ if user and user.authenticate(params[:password])
+ session[:user_id] = user.id
+ redirect_to admin_url
+ else
+ redirect_to login_url, alert: "Invalid user/password combination #{params[:password]}"
+ end
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to store_url, notice: "Logged Out"
+ end
+end
@@ -0,0 +1,83 @@
+class UsersController < ApplicationController
+ # GET /users
+ # GET /users.json
+ def index
+ @users = User.order(:name)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.json
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to users_url, notice: "User #{@user.name} was successfully created." }
+ format.json { render json: @user, status: :created, location: @user }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.json
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to users_url, notice: "User #{@user.name} was successfully updated." }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to users_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module AdminHelper
+end
@@ -0,0 +1,2 @@
+module OrdersHelper
+end
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
@@ -0,0 +1,25 @@
+class Notifier < ActionMailer::Base
+ default from: "Zhongyu <zhongyu.johny@gmail.com>"
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.notifier.order_received.subject
+ #
+ def order_received(order)
+ @order = order
+
+ mail to: order.email, subject: 'Pragmatic Store Order Confirmation'
+ end
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.notifier.order_shipped.subject
+ #
+ def order_shipped(order)
+ @order = order
+
+ mail to: order.email, subject: 'Pragmatic Store Order Confirmation'
+ end
+end
View
@@ -0,0 +1,14 @@
+class Article
+ attr_reader :body
+
+ def initialize(body)
+ @body = body
+ end
+
+ def self.find_recent
+ [ new("It is now #{Time.now.to_s}"),
+ new("Today i had a pizza"),
+ new("Did nothing on yesterday")
+ ]
+ end
+end
View
@@ -0,0 +1,3 @@
+class Discount < ActiveRecord::Base
+ # attr_accessible :title, :body
+end
View
@@ -0,0 +1,16 @@
+class Order < ActiveRecord::Base
+ has_many :line_items, :dependent => :destroy
+
+ attr_accessible :address, :email, :name, :pay_type
+ PAYMENT_TYPES = ["Check", "Credit card", "Purchase order" ]
+
+ validates :name, :address, :email, :pay_type, :presence => true
+ validates :pay_type, :inclusion => PAYMENT_TYPES
+
+ def add_line_items_from_cart(cart)
+ cart.line_items.each do |item|
+ item.cart_id = nil
+ line_items << item
+ end
+ end
+end
View
@@ -0,0 +1,5 @@
+class User < ActiveRecord::Base
+ has_secure_password
+ attr_accessible :name, :password, :password_confirmation, :password_digest
+ validates :name, presence: true, uniqueness: true
+end
@@ -0,0 +1,4 @@
+<h1>Welcome</h1>
+
+It's <%= Time.now %>
+We have <%= pluralize(@total_orders, "order") %>
@@ -0,0 +1,11 @@
+<%= @dynamic_content %>
+
+<% cache do %>
+ <ul>
+ <%for article in Article.find_recent %>
+ <li><p><%= h(article.body) %></p></li>
+ <% end %>
+ </ul>
+<% end %>
+
+<%= @dynamic_content %>
@@ -18,7 +18,7 @@
<!-- START_HIGHLIGHT -->
<% if @cart %>
<%= hidden_div_if(@cart.line_items.empty?, :id => 'cart') do %>
- <%= render @cart %>
+ <%= render @cart%>
<% end %>
<% end %>
<!-- END_HIGHLIGHT -->
@@ -27,6 +27,7 @@
<li><a href="http://www..../faq">Questions</a></li>
<li><a href="http://www..../news">News</a></li>
<li><a href="http://www..../contact">Contact</a></li>
+ <li><%= mail_to("hello@ruby.com", "E-mail", encode: "javascript")%></li>
</ul>
<% if session[:user_id] %>
Oops, something went wrong.

0 comments on commit f618ff6

Please sign in to comment.