gemstonemerchant 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +20 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/gemstonemerchant/application.js +13 -0
  6. data/app/assets/javascripts/gemstonemerchant/cart.js +2 -0
  7. data/app/assets/javascripts/gemstonemerchant/products.js +2 -0
  8. data/app/assets/stylesheets/gemstonemerchant/application.css +15 -0
  9. data/app/assets/stylesheets/gemstonemerchant/cart.css +4 -0
  10. data/app/assets/stylesheets/gemstonemerchant/products.css +4 -0
  11. data/app/assets/stylesheets/scaffold.css +56 -0
  12. data/app/controllers/gemstonemerchant/application_controller.rb +4 -0
  13. data/app/controllers/gemstonemerchant/cart_controller.rb +44 -0
  14. data/app/controllers/gemstonemerchant/products_controller.rb +62 -0
  15. data/app/helpers/gemstonemerchant/application_helper.rb +4 -0
  16. data/app/helpers/gemstonemerchant/cart_helper.rb +4 -0
  17. data/app/helpers/gemstonemerchant/products_helper.rb +4 -0
  18. data/app/models/gemstonemerchant/category.rb +7 -0
  19. data/app/models/gemstonemerchant/line_item.rb +18 -0
  20. data/app/models/gemstonemerchant/product.rb +17 -0
  21. data/app/models/gemstonemerchant/purchase.rb +21 -0
  22. data/app/models/gemstonemerchant/user.rb +42 -0
  23. data/app/uploaders/gemstonemerchant/images_uploader.rb +51 -0
  24. data/app/views/gemstonemerchant/cart/show.html.erb +27 -0
  25. data/app/views/gemstonemerchant/products/_form.html.erb +33 -0
  26. data/app/views/gemstonemerchant/products/edit.html.erb +6 -0
  27. data/app/views/gemstonemerchant/products/index.html.erb +43 -0
  28. data/app/views/gemstonemerchant/products/new.html.erb +5 -0
  29. data/app/views/gemstonemerchant/products/show.html.erb +42 -0
  30. data/app/views/layouts/gemstonemerchant/application.html.erb +14 -0
  31. data/config/initializers/devise.rb +268 -0
  32. data/config/locales/devise.en.yml +59 -0
  33. data/config/routes.rb +17 -0
  34. data/lib/gemstonemerchant.rb +4 -0
  35. data/lib/gemstonemerchant/engine.rb +5 -0
  36. data/lib/gemstonemerchant/version.rb +3 -0
  37. data/lib/generators/gemstonemerchant/install_generator.rb +10 -0
  38. data/lib/generators/install_generator.rb +7 -0
  39. data/lib/tasks/gemstonemerchant_tasks.rake +4 -0
  40. data/test/controllers/gemstonemerchant/cart_controller_test.rb +11 -0
  41. data/test/controllers/gemstonemerchant/products_controller_test.rb +51 -0
  42. data/test/dummy/README.rdoc +28 -0
  43. data/test/dummy/Rakefile +6 -0
  44. data/test/dummy/app/assets/javascripts/application.js +13 -0
  45. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  46. data/test/dummy/app/controllers/application_controller.rb +5 -0
  47. data/test/dummy/app/helpers/application_helper.rb +2 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/test/dummy/bin/bundle +3 -0
  50. data/test/dummy/bin/rails +4 -0
  51. data/test/dummy/bin/rake +4 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/config/application.rb +23 -0
  54. data/test/dummy/config/boot.rb +5 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +37 -0
  58. data/test/dummy/config/environments/production.rb +82 -0
  59. data/test/dummy/config/environments/test.rb +39 -0
  60. data/test/dummy/config/initializers/assets.rb +8 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/session_store.rb +3 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +23 -0
  69. data/test/dummy/config/mongoid.yml +69 -0
  70. data/test/dummy/config/routes.rb +4 -0
  71. data/test/dummy/config/secrets.yml +22 -0
  72. data/test/dummy/db/development.sqlite3 +0 -0
  73. data/test/dummy/log/development.log +349 -0
  74. data/test/dummy/public/404.html +67 -0
  75. data/test/dummy/public/422.html +67 -0
  76. data/test/dummy/public/500.html +66 -0
  77. data/test/dummy/public/favicon.ico +0 -0
  78. data/test/fixtures/gemstonemerchant/categories.yml +7 -0
  79. data/test/fixtures/gemstonemerchant/line_items.yml +9 -0
  80. data/test/fixtures/gemstonemerchant/products.yml +13 -0
  81. data/test/fixtures/gemstonemerchant/purchases.yml +11 -0
  82. data/test/fixtures/gemstonemerchant/users.yml +11 -0
  83. data/test/gemstonemerchant_test.rb +7 -0
  84. data/test/helpers/gemstonemerchant/cart_helper_test.rb +6 -0
  85. data/test/helpers/gemstonemerchant/products_helper_test.rb +6 -0
  86. data/test/integration/navigation_test.rb +10 -0
  87. data/test/models/gemstonemerchant/category_test.rb +9 -0
  88. data/test/models/gemstonemerchant/line_item_test.rb +9 -0
  89. data/test/models/gemstonemerchant/product_test.rb +9 -0
  90. data/test/models/gemstonemerchant/purchase_test.rb +9 -0
  91. data/test/models/gemstonemerchant/user_test.rb +9 -0
  92. data/test/test_helper.rb +15 -0
  93. metadata +244 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dba0de94fb45ce2db024ab054bb56ec5fa0380b7
4
+ data.tar.gz: 91ea1131aae684e9b9be988183e45dd8c41b2ba2
5
+ SHA512:
6
+ metadata.gz: e88e3bae7d312b13eba6b6b35470568bdd52e27ce093d78584fe0b72e822f507c76f2a0a9edfd3da7538a119a03f2cc1bab45aafd3a39fdc661b199298aca391
7
+ data.tar.gz: 854dff6da6ee3226694e2ad2af72a65f0aaffc26048126ba97a6d52a1021ce472bfd9249548113a5291f0320ab1e21486f4aa7d31254f2ddf4561f78dddff224
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Lucas Aragno
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,20 @@
1
+ Copyright 2014 Lucas Aragno
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,34 @@
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 = 'Gemstonemerchant'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ 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 Gemstonemerchant
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ require_dependency "gemstonemerchant/application_controller"
2
+
3
+ module Gemstonemerchant
4
+ class CartController < ApplicationController
5
+
6
+ before_action :get_cart_value
7
+
8
+ def show
9
+ end
10
+
11
+ def add
12
+ @cart.save
13
+ session[:cart_id] = @cart.id
14
+ product = Product.find(params[:id])
15
+ item = LineItem.new
16
+ item.make_items(@cart.id, product.id, product.base_price)
17
+ @cart.recalculate_price!
18
+ flash[:notice] = "Product Added to Cart"
19
+ redirect_to cart_path
20
+ end
21
+
22
+ def remove
23
+ item = @cart.line_items.find(params[:id])
24
+ item.destroy
25
+ @cart.recalculate_price!
26
+ flash[:notice] = "Product Deleted from Cart"
27
+ redirect_to cart_path
28
+ end
29
+
30
+ protected
31
+
32
+ def get_cart_value
33
+ if session[:cart_id].nil?
34
+ @cart = Purchase.create
35
+ session[:cart_id] = @cart.id
36
+ @cart
37
+ else
38
+ @cart = Purchase.find(session[:cart_id])
39
+ end
40
+ end
41
+
42
+
43
+ end
44
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "gemstonemerchant/application_controller"
2
+
3
+ module Gemstonemerchant
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, :price, :sku)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module Gemstonemerchant
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gemstonemerchant
2
+ module CartHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gemstonemerchant
2
+ module ProductsHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Gemstonemerchant
2
+ class Category
3
+ include Mongoid::Document
4
+ field :name, type: String
5
+ has_many :products
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Gemstonemerchant
2
+ class LineItem
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :purchase_id, type: String
7
+ field :product_id, type: String
8
+ field :price, type: Float
9
+
10
+ belongs_to :purchase
11
+ belongs_to :product
12
+
13
+ def self.make_items(purchase_id, product_id, price)
14
+ LineItem.create(purchase_id: purchase_id, product_id: product_id, price: price)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Gemstonemerchant
2
+ class Product
3
+ include Mongoid::Document
4
+ include Mongoid::Slug
5
+
6
+ field :name, type: String
7
+ field :description, type: String
8
+ field :price, type: Float
9
+ field :sku, type: String
10
+ field :category_id, type: String
11
+
12
+ slug :name, history: true
13
+ belongs_to :category
14
+ has_many :line_items
15
+ mount_uploader :image, ImageUploader
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Gemstonemerchant
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
+
11
+ has_many :line_items, :dependent => :destroy
12
+ belongs_to :user
13
+
14
+
15
+ def recalculate_price!
16
+ self.total_price = line_items.inject(0.0) { |sum, line_item| sum+= line_item.price }
17
+ save!
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ module Gemstonemerchant
2
+ class User
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ # Include default devise modules. Others available are:
7
+ # :confirmable, :lockable, :timeoutable and :omniauthable
8
+ devise :database_authenticatable, :registerable,
9
+ :recoverable, :rememberable, :trackable, :validatable
10
+
11
+ ## Database authenticatable
12
+ field :email, type: String, default: ""
13
+ field :encrypted_password, type: String, default: ""
14
+
15
+ ## Recoverable
16
+ field :reset_password_token, type: String
17
+ field :reset_password_sent_at, type: Time
18
+
19
+ ## Rememberable
20
+ field :remember_created_at, type: Time
21
+
22
+ ## Trackable
23
+ field :sign_in_count, type: Integer, default: 0
24
+ field :current_sign_in_at, type: Time
25
+ field :last_sign_in_at, type: Time
26
+ field :current_sign_in_ip, type: String
27
+ field :last_sign_in_ip, type: String
28
+
29
+ ## Confirmable
30
+ # field :confirmation_token, type: String
31
+ # field :confirmed_at, type: Time
32
+ # field :confirmation_sent_at, type: Time
33
+ # field :unconfirmed_email, type: String # Only if using reconfirmable
34
+
35
+ ## Lockable
36
+ # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
37
+ # field :unlock_token, type: String # Only if unlock strategy is :email or :both
38
+ # field :locked_at, type: Time
39
+
40
+ has_many :purchases, :dependent => :destroy
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ class ImagesUploader < 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