ecom2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/javascripts/ecom2/application.js +13 -0
  6. data/app/assets/javascripts/ecom2/cart.js +2 -0
  7. data/app/assets/javascripts/ecom2/products.js +2 -0
  8. data/app/assets/stylesheets/ecom2/application.css +15 -0
  9. data/app/assets/stylesheets/ecom2/cart.css +4 -0
  10. data/app/assets/stylesheets/ecom2/products.css +4 -0
  11. data/app/assets/stylesheets/scaffold.css +56 -0
  12. data/app/controllers/ecom2/application_controller.rb +4 -0
  13. data/app/controllers/ecom2/cart_controller.rb +40 -0
  14. data/app/controllers/ecom2/products_controller.rb +62 -0
  15. data/app/helpers/ecom2/application_helper.rb +4 -0
  16. data/app/helpers/ecom2/cart_helper.rb +4 -0
  17. data/app/helpers/ecom2/products_helper.rb +4 -0
  18. data/app/models/ecom2/category.rb +7 -0
  19. data/app/models/ecom2/line_item.rb +15 -0
  20. data/app/models/ecom2/product.rb +14 -0
  21. data/app/models/ecom2/purchase.rb +19 -0
  22. data/app/models/ecom2/user.rb +40 -0
  23. data/app/uploaders/ecom2/image_uploader.rb +52 -0
  24. data/app/views/ecom2/cart/show.html.erb +30 -0
  25. data/app/views/ecom2/products/_form.html.erb +33 -0
  26. data/app/views/ecom2/products/edit.html.erb +6 -0
  27. data/app/views/ecom2/products/index.html.erb +43 -0
  28. data/app/views/ecom2/products/new.html.erb +5 -0
  29. data/app/views/ecom2/products/show.html.erb +44 -0
  30. data/app/views/layouts/ecom2/application.html.erb +14 -0
  31. data/config/initializers/devise.rb +260 -0
  32. data/config/locales/devise.en.yml +60 -0
  33. data/config/routes.rb +14 -0
  34. data/lib/ecom2.rb +4 -0
  35. data/lib/ecom2/engine.rb +6 -0
  36. data/lib/ecom2/version.rb +3 -0
  37. data/lib/generators/ecom2/install_generator.rb +9 -0
  38. data/lib/tasks/ecom2_tasks.rake +4 -0
  39. data/test/controllers/ecom2/cart_controller_test.rb +11 -0
  40. data/test/controllers/ecom2/products_controller_test.rb +51 -0
  41. data/test/dummy/README.rdoc +28 -0
  42. data/test/dummy/Rakefile +6 -0
  43. data/test/dummy/app/assets/javascripts/application.js +13 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  45. data/test/dummy/app/controllers/application_controller.rb +5 -0
  46. data/test/dummy/app/helpers/application_helper.rb +2 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/test/dummy/bin/bundle +3 -0
  49. data/test/dummy/bin/rails +4 -0
  50. data/test/dummy/bin/rake +4 -0
  51. data/test/dummy/config.ru +4 -0
  52. data/test/dummy/config/application.rb +29 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +34 -0
  56. data/test/dummy/config/environments/production.rb +75 -0
  57. data/test/dummy/config/environments/test.rb +39 -0
  58. data/test/dummy/config/initializers/assets.rb +8 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/test/dummy/config/initializers/inflections.rb +16 -0
  63. data/test/dummy/config/initializers/mime_types.rb +4 -0
  64. data/test/dummy/config/initializers/session_store.rb +3 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  66. data/test/dummy/config/locales/en.yml +23 -0
  67. data/test/dummy/config/mongoid.yml +69 -0
  68. data/test/dummy/config/routes.rb +4 -0
  69. data/test/dummy/config/secrets.yml +22 -0
  70. data/test/dummy/log/development.log +0 -0
  71. data/test/dummy/public/404.html +67 -0
  72. data/test/dummy/public/422.html +67 -0
  73. data/test/dummy/public/500.html +66 -0
  74. data/test/dummy/public/favicon.ico +0 -0
  75. data/test/ecom2_test.rb +7 -0
  76. data/test/fixtures/ecom2/categories.yml +7 -0
  77. data/test/fixtures/ecom2/line_items.yml +9 -0
  78. data/test/fixtures/ecom2/products.yml +13 -0
  79. data/test/fixtures/ecom2/purchases.yml +11 -0
  80. data/test/fixtures/ecom2/users.yml +11 -0
  81. data/test/helpers/ecom2/cart_helper_test.rb +6 -0
  82. data/test/helpers/ecom2/products_helper_test.rb +6 -0
  83. data/test/integration/navigation_test.rb +9 -0
  84. data/test/models/ecom2/category_test.rb +9 -0
  85. data/test/models/ecom2/line_item_test.rb +9 -0
  86. data/test/models/ecom2/product_test.rb +9 -0
  87. data/test/models/ecom2/purchase_test.rb +9 -0
  88. data/test/models/ecom2/user_test.rb +9 -0
  89. data/test/test_helper.rb +15 -0
  90. metadata +253 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99ef628002d7ae4d3b99fe4e411cb7a35a3d067c
4
+ data.tar.gz: 0fa1cd28e54fea38d19a6e970b88099298453eeb
5
+ SHA512:
6
+ metadata.gz: 5944a2feab9b7ad185fe3008650f05d31092cc0d0c17a9cfb2c902028cd99a68c16f756ac6ad8c9ac00f6db7f592095bb2d60b7e4e567a9eb1d54087dbe014ab
7
+ data.tar.gz: 97a60eab952fdb6502ea69ab6a2cab6a566691c9427cfcdd30fd30752df1f7e735a3a026fcacdb65dfcf3a6024fd2085e22e539827d3fb40921f6955e19f55ea
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Ecom2
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ecom2'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ module Ecom2
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,40 @@
1
+ require_dependency "ecom2/application_controller"
2
+
3
+ module Ecom2
4
+ class CartController < ApplicationController
5
+ before_filter :authenticate_user!
6
+ before_action :get_cart_value
7
+ def add
8
+ @cart.save
9
+ session[:cart_id] = @cart.id
10
+ product = Product.find(params[:id])
11
+ item = LineItem.new
12
+ item.make_items(@cart.id, product.id, product.base_price)
13
+ @cart.recalculate_price!
14
+ flash[:notice] = "Product Added to Cart"
15
+ redirect_to cart_path
16
+ end
17
+ def remove
18
+ item = @cart.line_items.find(params[:id])
19
+ item.destroy
20
+ @cart.recalculate_price!
21
+ flash[:notice] = "Product Deleted from Cart"
22
+ redirect_to cart_path
23
+ end
24
+
25
+ def show
26
+
27
+ end
28
+
29
+ protected
30
+ def get_cart_value
31
+ if session[:cart_id].nil?
32
+ @cart = Purchase.create
33
+ session[:cart_id] = @cart.id
34
+ @cart
35
+ else
36
+ @cart = Purchase.find(session[:cart_id])
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "ecom2/application_controller"
2
+
3
+ module Ecom2
4
+ class ProductsController < ApplicationController
5
+ before_action :set_product, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /products
8
+ def index
9
+ @products = Product.all
10
+ end
11
+
12
+ # GET /products/1
13
+ def show
14
+ end
15
+
16
+ # GET /products/new
17
+ def new
18
+ @product = Product.new
19
+ end
20
+
21
+ # GET /products/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /products
26
+ def create
27
+ @product = Product.new(product_params)
28
+
29
+ if @product.save
30
+ redirect_to @product, notice: 'Product was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /products/1
37
+ def update
38
+ if @product.update(product_params)
39
+ redirect_to @product, notice: 'Product was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /products/1
46
+ def destroy
47
+ @product.destroy
48
+ redirect_to products_url, notice: 'Product was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_product
54
+ @product = Product.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def product_params
59
+ params.require(:product).permit(:name, :description, :base_price, :sku)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module Ecom2
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ecom2
2
+ module CartHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ecom2
2
+ module ProductsHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Ecom2
2
+ class Category
3
+ include Mongoid::Document
4
+ field :title, type: String
5
+ has_many :products
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Ecom2
2
+ class LineItem
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ field :product_id, type: String
6
+ field :price, type: Float
7
+ belongs_to :purchase
8
+ belongs_to :product
9
+
10
+ def self.make_items(purchase_id, product_id, price)
11
+ LineItem.create(purchase_id: purchase_id, product_id:
12
+ product_id, price: price)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Ecom2
2
+ class Product
3
+ include Mongoid::Document
4
+ include Mongoid::Slug
5
+ field :name, type: String
6
+ field :description, type: String
7
+ field :base_price, type: Float
8
+ field :sku, type: String
9
+ slug :name, history: true
10
+ belongs_to :category
11
+ has_many :line_items
12
+ mount_uploader :image, ImageUploader
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Ecom2
2
+ class Purchase
3
+ include Mongoid::Document
4
+ include Mongoid::MultiParameterAttributes
5
+ include Mongoid::Timestamps
6
+
7
+ field :user_id, type: String
8
+ field :checked_out_at, type: Time
9
+ field :total_price, type: Float
10
+ has_many :line_items, :dependent => :destroy
11
+ belongs_to :user
12
+
13
+ def recalculate_price!
14
+ self.total_price = line_items.inject(0.0){|sum, line_item| sum
15
+ += line_item.price }
16
+ save!
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ module Ecom2
2
+ class User
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ # Include default devise modules. Others available are:
6
+ # :confirmable, :lockable, :timeoutable and :omniauthable
7
+ devise :database_authenticatable, :registerable,
8
+ :recoverable, :rememberable, :trackable, :validatable
9
+
10
+ ## Database authenticatable
11
+ field :email, type: String, default: ""
12
+ field :encrypted_password, type: String, default: ""
13
+
14
+ ## Recoverable
15
+ field :reset_password_token, type: String
16
+ field :reset_password_sent_at, type: Time
17
+
18
+ ## Rememberable
19
+ field :remember_created_at, type: Time
20
+
21
+ ## Trackable
22
+ field :sign_in_count, type: Integer, default: 0
23
+ field :current_sign_in_at, type: Time
24
+ field :last_sign_in_at, type: Time
25
+ field :current_sign_in_ip, type: String
26
+ field :last_sign_in_ip, type: String
27
+
28
+ ## Confirmable
29
+ # field :confirmation_token, type: String
30
+ # field :confirmed_at, type: Time
31
+ # field :confirmation_sent_at, type: Time
32
+ # field :unconfirmed_email, type: String # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
36
+ # field :unlock_token, type: String # Only if unlock strategy is :email or :both
37
+ # field :locked_at, type: Time
38
+ has_many :purchases, :dependent => :destroy
39
+ end
40
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ module Ecom2
3
+ class ImageUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ # include CarrierWave::RMagick
7
+ # include CarrierWave::MiniMagick
8
+
9
+ # Choose what kind of storage to use for this uploader:
10
+ storage :file
11
+ # storage :fog
12
+
13
+ # Override the directory where uploaded files will be stored.
14
+ # This is a sensible default for uploaders that are meant to be mounted:
15
+ def store_dir
16
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17
+ end
18
+
19
+ # Provide a default URL as a default if there hasn't been a file uploaded:
20
+ # def default_url
21
+ # # For Rails 3.1+ asset pipeline compatibility:
22
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
23
+ #
24
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
25
+ # end
26
+
27
+ # Process files as they are uploaded:
28
+ # process :scale => [200, 300]
29
+ #
30
+ # def scale(width, height)
31
+ # # do something
32
+ # end
33
+
34
+ # Create different versions of your uploaded files:
35
+ # version :thumb do
36
+ # process :resize_to_fit => [50, 50]
37
+ # end
38
+
39
+ # Add a white list of extensions which are allowed to be uploaded.
40
+ # For images you might use something like this:
41
+ # def extension_white_list
42
+ # %w(jpg jpeg gif png)
43
+ # end
44
+
45
+ # Override the filename of the uploaded files:
46
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
47
+ # def filename
48
+ # "something.jpg" if original_filename
49
+ # end
50
+
51
+ end
52
+ end