spree_favorite_products 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/spree/favorite_products_controller.rb +2 -2
- data/app/models/spree/app_configuration_decorator.rb +3 -0
- data/app/models/spree/user_decorator.rb +4 -0
- data/app/overrides/add_favorite_products_per_page_configuration.rb +16 -0
- data/app/overrides/add_link_to_mark_product_as_favorite.rb +7 -1
- data/app/views/spree/favorite_products/create.js.erb +3 -0
- data/app/views/spree/favorite_products/destroy.js.erb +7 -2
- data/app/views/spree/favorite_products/index.html.erb +3 -1
- data/config/locales/en.yml +5 -0
- data/spec/controllers/spree/favorite_products_controller_spec.rb +19 -6
- data/spec/models/spree/app_configuration_decorator_spec.rb +3 -0
- data/spec/models/spree/user_decorator_spec.rb +20 -0
- data/spree_favorite_products.gemspec +1 -1
- metadata +54 -34
| @@ -5,7 +5,7 @@ module Spree | |
| 5 5 | 
             
                before_filter :find_favorite_product, :only => :destroy
         | 
| 6 6 |  | 
| 7 7 | 
             
                def index
         | 
| 8 | 
            -
                  @favorite_products = spree_current_user.favorite_products
         | 
| 8 | 
            +
                  @favorite_products = spree_current_user.favorite_products.page(params[:page]).per(Spree::Config.favorite_products_per_page)
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 11 | 
             
                def create
         | 
| @@ -28,7 +28,7 @@ module Spree | |
| 28 28 |  | 
| 29 29 | 
             
                private
         | 
| 30 30 | 
             
                  def find_favorite_product
         | 
| 31 | 
            -
                    @favorite = spree_current_user.favorites.joins(:product).readonly(false).where(:spree_products => {: | 
| 31 | 
            +
                    @favorite = spree_current_user.favorites.joins(:product).readonly(false).where(:spree_products => {:id => params[:id]}).first
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 | 
             
              end
         | 
| 34 34 | 
             
            end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            Deface::Override.new(
         | 
| 2 | 
            +
              :virtual_path => 'spree/admin/general_settings/edit',
         | 
| 3 | 
            +
              :name => 'add_favorite_products_per_page_configuration',
         | 
| 4 | 
            +
              :insert_after => "#preferences .row",
         | 
| 5 | 
            +
              :text => %Q{
         | 
| 6 | 
            +
                <div class="row">
         | 
| 7 | 
            +
                  <fieldset class="no-border-bottom">
         | 
| 8 | 
            +
                    <legend align="center"><%= Spree.t(:favorite_products_settings) %></legend>
         | 
| 9 | 
            +
                    <div class="field">
         | 
| 10 | 
            +
                      <%= label_tag :favorite_products_per_page, Spree.t(:favorite_products_per_page) %><br>
         | 
| 11 | 
            +
                      <%= text_field_tag :favorite_products_per_page, Spree::Config[:favorite_products_per_page], :size => 3 %>
         | 
| 12 | 
            +
                    </div>
         | 
| 13 | 
            +
                  </fieldset>
         | 
| 14 | 
            +
                </div>
         | 
| 15 | 
            +
              }
         | 
| 16 | 
            +
            )
         | 
| @@ -2,5 +2,11 @@ Deface::Override.new( | |
| 2 2 | 
             
              :virtual_path => 'spree/products/show',
         | 
| 3 3 | 
             
              :name => 'add_link_to_mark_product_as_favorite',
         | 
| 4 4 | 
             
              :insert_after => "div[itemprop='description']",
         | 
| 5 | 
            -
              :text =>  | 
| 5 | 
            +
              :text => %Q{
         | 
| 6 | 
            +
                <% if spree_user_signed_in? && spree_current_user.has_favorite_product?(@product.id) %>
         | 
| 7 | 
            +
                  <%= link_to Spree.t(:unmark_as_favorite), favorite_product_path(:id => @product.id), :method => :delete, :remote => true, :class => 'favorite_link' %>
         | 
| 8 | 
            +
                <% else %>
         | 
| 9 | 
            +
                  <%= link_to Spree.t(:mark_as_favorite), favorite_products_path(:id => @product.id), :method => :post, :remote => spree_user_signed_in?, :class => 'favorite_link' %>
         | 
| 10 | 
            +
                <% end %>
         | 
| 11 | 
            +
              }
         | 
| 6 12 | 
             
            )
         | 
| @@ -1,6 +1,11 @@ | |
| 1 1 | 
             
            <% if @success %>
         | 
| 2 | 
            -
              $( | 
| 3 | 
            -
             | 
| 2 | 
            +
              if($('.favorite_link').length) {
         | 
| 3 | 
            +
                $('.favorite_link').attr('href', '<%= favorite_products_path(:id => @favorite.product_id) %>').data('method', 'post').text('<%= Spree.t(:mark_as_favorite) %>')
         | 
| 4 | 
            +
                alert('Successfully unmarked as favorite');
         | 
| 5 | 
            +
              } else {
         | 
| 6 | 
            +
                $("#favorite_product_<%= @favorite.product_id%>").remove();
         | 
| 7 | 
            +
                alert("Successfully removed favorite product from your list");
         | 
| 8 | 
            +
              }
         | 
| 4 9 | 
             
            <% else %>
         | 
| 5 10 | 
             
              alert("Could not remove product form your list")
         | 
| 6 11 | 
             
            <% end %>
         | 
| @@ -14,7 +14,7 @@ | |
| 14 14 | 
             
                    <tr class="<%= cycle('even', 'odd') %>" id="favorite_product_<%= product.id %>">
         | 
| 15 15 | 
             
                      <td class="favorite-product-image"><%= link_to small_image(product), product_path(product) %></td>
         | 
| 16 16 | 
             
                      <td class="favorite-product-name"><%= product.name %></td>
         | 
| 17 | 
            -
                      <td class="favorite-product-remove"><%= link_to 'Remove', favorite_product_path(product), :method => :delete, :remote => true %>
         | 
| 17 | 
            +
                      <td class="favorite-product-remove"><%= link_to 'Remove', favorite_product_path(:id => product.id), :method => :delete, :remote => true %>
         | 
| 18 18 | 
             
                    </tr>
         | 
| 19 19 | 
             
                  <% end %>
         | 
| 20 20 | 
             
                  </tbody>
         | 
| @@ -22,4 +22,6 @@ | |
| 22 22 | 
             
              <% else %>
         | 
| 23 23 | 
             
                <p><%= Spree.t(:you_have_no_favorite_products_yet) %></p>
         | 
| 24 24 | 
             
              <% end %>
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
              <%= paginate @favorite_products %>
         | 
| 25 27 | 
             
            </div>
         | 
    
        data/config/locales/en.yml
    CHANGED
    
    
| @@ -11,7 +11,7 @@ describe Spree::FavoriteProductsController do | |
| 11 11 |  | 
| 12 12 | 
             
              shared_examples_for "request which finds favorite product" do
         | 
| 13 13 | 
             
                it "finds favorite product" do
         | 
| 14 | 
            -
                  @current_user_favorites.should_receive(:where).with(:spree_products => {: | 
| 14 | 
            +
                  @current_user_favorites.should_receive(:where).with(:spree_products => {:id => 'id'})
         | 
| 15 15 | 
             
                  send_request
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| @@ -84,12 +84,15 @@ describe Spree::FavoriteProductsController do | |
| 84 84 |  | 
| 85 85 | 
             
              describe 'GET index' do
         | 
| 86 86 | 
             
                def send_request
         | 
| 87 | 
            -
                  get :index, :use_route => 'spree'
         | 
| 87 | 
            +
                  get :index, :page => 'current_page', :use_route => 'spree'
         | 
| 88 88 | 
             
                end
         | 
| 89 89 |  | 
| 90 90 | 
             
                before(:each) do
         | 
| 91 | 
            -
                  @ | 
| 92 | 
            -
                  @ | 
| 91 | 
            +
                  @favorite_products = double('favorite_products')
         | 
| 92 | 
            +
                  @favorite_products.stub(:page).and_return(@favorite_products)
         | 
| 93 | 
            +
                  @favorite_products.stub(:per).and_return(@favorite_products)
         | 
| 94 | 
            +
                  Spree::Config.stub(:favorite_products_per_page).and_return('favorite_products_per_page')
         | 
| 95 | 
            +
                  @user = mock_model(Spree::User, :favorite_products => @favorite_products, :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
         | 
| 93 96 | 
             
                  controller.stub(:authenticate_spree_user!).and_return(true)
         | 
| 94 97 | 
             
                  controller.stub(:spree_current_user).and_return(@user)
         | 
| 95 98 | 
             
                end
         | 
| @@ -104,15 +107,25 @@ describe Spree::FavoriteProductsController do | |
| 104 107 | 
             
                  send_request
         | 
| 105 108 | 
             
                end
         | 
| 106 109 |  | 
| 110 | 
            +
                it "paginates favorite products" do
         | 
| 111 | 
            +
                  @favorite_products.should_receive(:page).with('current_page')
         | 
| 112 | 
            +
                  send_request
         | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                it "shows Spree::Config.favorite_products_per_page" do
         | 
| 116 | 
            +
                  @favorite_products.should_receive(:per).with('favorite_products_per_page')
         | 
| 117 | 
            +
                  send_request
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
             | 
| 107 120 | 
             
                it "assigns @favorite_products" do
         | 
| 108 121 | 
             
                  send_request
         | 
| 109 | 
            -
                  assigns(:favorite_products).should eq( | 
| 122 | 
            +
                  assigns(:favorite_products).should eq(@favorite_products)
         | 
| 110 123 | 
             
                end
         | 
| 111 124 | 
             
              end
         | 
| 112 125 |  | 
| 113 126 | 
             
              describe 'destroy' do
         | 
| 114 127 | 
             
                def send_request(params = {})
         | 
| 115 | 
            -
                  post :destroy, params.merge({:use_route => 'spree', :method => :delete, :format => :js, :id => ' | 
| 128 | 
            +
                  post :destroy, params.merge({:use_route => 'spree', :method => :delete, :format => :js, :id => 'id'})
         | 
| 116 129 | 
             
                end
         | 
| 117 130 |  | 
| 118 131 | 
             
                before do
         | 
| @@ -1,6 +1,26 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Spree::User do
         | 
| 4 | 
            +
              before(:each) do
         | 
| 5 | 
            +
                @user = Spree::User.create! :email => 'test@example.com', :password => 'spree123'
         | 
| 6 | 
            +
                @product1 = Spree::Product.create! :name => 'product1', :price => 100, :shipping_category_id => 1
         | 
| 7 | 
            +
                @product2 = Spree::Product.create! :name => 'product2', :price => 100, :shipping_category_id => 1
         | 
| 8 | 
            +
                favorite = Spree::Favorite.new
         | 
| 9 | 
            +
                favorite.product_id = @product1.id
         | 
| 10 | 
            +
                favorite.user_id = @user.id
         | 
| 11 | 
            +
                favorite.save!
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 4 14 | 
             
              it { should have_many(:favorites) }
         | 
| 5 15 | 
             
              it { should have_many(:favorite_products).through(:favorites).class_name('Spree::Product') }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              describe "has_favorite_product?" do
         | 
| 18 | 
            +
                context "when product in user's favorite products" do
         | 
| 19 | 
            +
                  it { @user.has_favorite_product?(@product1.id).should be_true }
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                context 'when product is not in users favorite products' do
         | 
| 23 | 
            +
                  it { @user.has_favorite_product?(@product2.id).should be_false }
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 6 26 | 
             
            end
         | 
| @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            Gem::Specification.new do |s|
         | 
| 3 3 | 
             
              s.platform    = Gem::Platform::RUBY
         | 
| 4 4 | 
             
              s.name        = 'spree_favorite_products'
         | 
| 5 | 
            -
              s.version     = '2.0. | 
| 5 | 
            +
              s.version     = '2.0.1'
         | 
| 6 6 | 
             
              s.summary     = 'users can mark product as favorite'
         | 
| 7 7 | 
             
              s.description = 'This extension adds the following features: 1. Adds a link Mark as favorite on product detail page. 2. Favorite Products tab on header 3. Favorite Products tab in admin section'
         | 
| 8 8 | 
             
              s.required_ruby_version = '>= 1.9.3'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,40 +1,47 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification
         | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: spree_favorite_products
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 13
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 2
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 2.0.1
         | 
| 6 11 | 
             
            platform: ruby
         | 
| 7 | 
            -
            authors:
         | 
| 12 | 
            +
            authors: 
         | 
| 8 13 | 
             
            - Mohit Bansal
         | 
| 9 14 | 
             
            autorequire: 
         | 
| 10 15 | 
             
            bindir: bin
         | 
| 11 16 | 
             
            cert_chain: []
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2014-03-07 00:00:00 Z
         | 
| 19 | 
            +
            dependencies: 
         | 
| 20 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 15 21 | 
             
              name: spree_core
         | 
| 16 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 | 
            -
                requirements:
         | 
| 19 | 
            -
                - - ~>
         | 
| 20 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            -
                    version: 2.1.0
         | 
| 22 | 
            -
              type: :runtime
         | 
| 23 22 | 
             
              prerelease: false
         | 
| 24 | 
            -
               | 
| 23 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 24 | 
             
                none: false
         | 
| 26 | 
            -
                requirements:
         | 
| 25 | 
            +
                requirements: 
         | 
| 27 26 | 
             
                - - ~>
         | 
| 28 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 28 | 
            +
                    hash: 11
         | 
| 29 | 
            +
                    segments: 
         | 
| 30 | 
            +
                    - 2
         | 
| 31 | 
            +
                    - 1
         | 
| 32 | 
            +
                    - 0
         | 
| 29 33 | 
             
                    version: 2.1.0
         | 
| 30 | 
            -
             | 
| 31 | 
            -
               | 
| 32 | 
            -
             | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              version_requirements: *id001
         | 
| 36 | 
            +
            description: "This extension adds the following features: 1. Adds a link Mark as favorite on product detail page. 2. Favorite Products tab on header 3. Favorite Products tab in admin section"
         | 
| 33 37 | 
             
            email: info@vinsol.com
         | 
| 34 38 | 
             
            executables: []
         | 
| 39 | 
            +
             | 
| 35 40 | 
             
            extensions: []
         | 
| 41 | 
            +
             | 
| 36 42 | 
             
            extra_rdoc_files: []
         | 
| 37 | 
            -
             | 
| 43 | 
            +
             | 
| 44 | 
            +
            files: 
         | 
| 38 45 | 
             
            - .rspec
         | 
| 39 46 | 
             
            - .travis.yml
         | 
| 40 47 | 
             
            - Gemfile
         | 
| @@ -49,10 +56,12 @@ files: | |
| 49 56 | 
             
            - app/assets/stylesheets/store/spree_favorite_products.css
         | 
| 50 57 | 
             
            - app/controllers/spree/admin/favorite_products_controller.rb
         | 
| 51 58 | 
             
            - app/controllers/spree/favorite_products_controller.rb
         | 
| 59 | 
            +
            - app/models/spree/app_configuration_decorator.rb
         | 
| 52 60 | 
             
            - app/models/spree/favorite.rb
         | 
| 53 61 | 
             
            - app/models/spree/product_decorator.rb
         | 
| 54 62 | 
             
            - app/models/spree/user_decorator.rb
         | 
| 55 63 | 
             
            - app/overrides/.DS_Store
         | 
| 64 | 
            +
            - app/overrides/add_favorite_products_per_page_configuration.rb
         | 
| 56 65 | 
             
            - app/overrides/add_favorite_products_tab.rb
         | 
| 57 66 | 
             
            - app/overrides/add_link_to_mark_product_as_favorite.rb
         | 
| 58 67 | 
             
            - app/overrides/add_link_to_users_favorite_products.rb
         | 
| @@ -73,35 +82,46 @@ files: | |
| 73 82 | 
             
            - script/rails
         | 
| 74 83 | 
             
            - spec/controllers/spree/admin/favorite_products_controller_spec.rb
         | 
| 75 84 | 
             
            - spec/controllers/spree/favorite_products_controller_spec.rb
         | 
| 85 | 
            +
            - spec/models/spree/app_configuration_decorator_spec.rb
         | 
| 76 86 | 
             
            - spec/models/spree/favorite_spec.rb
         | 
| 77 87 | 
             
            - spec/models/spree/product_decorator_spec.rb
         | 
| 78 88 | 
             
            - spec/models/spree/user_decorator_spec.rb
         | 
| 79 89 | 
             
            - spec/spec_helper.rb
         | 
| 80 90 | 
             
            - spree_favorite_products.gemspec
         | 
| 81 91 | 
             
            homepage: http://vinsol.com
         | 
| 82 | 
            -
            licenses:
         | 
| 92 | 
            +
            licenses: 
         | 
| 83 93 | 
             
            - MIT
         | 
| 84 94 | 
             
            post_install_message: 
         | 
| 85 95 | 
             
            rdoc_options: []
         | 
| 86 | 
            -
             | 
| 96 | 
            +
             | 
| 97 | 
            +
            require_paths: 
         | 
| 87 98 | 
             
            - lib
         | 
| 88 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 99 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 89 100 | 
             
              none: false
         | 
| 90 | 
            -
              requirements:
         | 
| 91 | 
            -
              - -  | 
| 92 | 
            -
                - !ruby/object:Gem::Version
         | 
| 101 | 
            +
              requirements: 
         | 
| 102 | 
            +
              - - ">="
         | 
| 103 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 104 | 
            +
                  hash: 53
         | 
| 105 | 
            +
                  segments: 
         | 
| 106 | 
            +
                  - 1
         | 
| 107 | 
            +
                  - 9
         | 
| 108 | 
            +
                  - 3
         | 
| 93 109 | 
             
                  version: 1.9.3
         | 
| 94 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 110 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 95 111 | 
             
              none: false
         | 
| 96 | 
            -
              requirements:
         | 
| 97 | 
            -
              - -  | 
| 98 | 
            -
                - !ruby/object:Gem::Version
         | 
| 99 | 
            -
                   | 
| 100 | 
            -
             | 
| 112 | 
            +
              requirements: 
         | 
| 113 | 
            +
              - - ">="
         | 
| 114 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 115 | 
            +
                  hash: 3
         | 
| 116 | 
            +
                  segments: 
         | 
| 117 | 
            +
                  - 0
         | 
| 118 | 
            +
                  version: "0"
         | 
| 119 | 
            +
            requirements: 
         | 
| 101 120 | 
             
            - none
         | 
| 102 121 | 
             
            rubyforge_project: 
         | 
| 103 | 
            -
            rubygems_version: 1.8. | 
| 122 | 
            +
            rubygems_version: 1.8.24
         | 
| 104 123 | 
             
            signing_key: 
         | 
| 105 124 | 
             
            specification_version: 3
         | 
| 106 125 | 
             
            summary: users can mark product as favorite
         | 
| 107 126 | 
             
            test_files: []
         | 
| 127 | 
            +
             |