spree_favorite_products 2.0.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,12 +13,18 @@ Installation
13
13
  Add spree_favorite_products to your Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'spree_favorite_products', '2.0.2'
16
+ gem 'spree_favorite_products'
17
17
  ```
18
18
 
19
- If you're still using Spree 2.0.x, you should do this instead:
19
+ For older versions of spree.
20
20
 
21
21
  ```ruby
22
+ # Spree 2.1.x
23
+ gem 'spree_favorite_products', '2.0.1'
24
+ ```
25
+
26
+ ```ruby
27
+ # Spree 2.0.x
22
28
  gem 'spree_favorite_products', '1.0.0'
23
29
  ```
24
30
 
@@ -1 +0,0 @@
1
- //= require admin/spree_backend
@@ -1 +0,0 @@
1
- //= require store/spree_frontend
@@ -1,3 +0,0 @@
1
- /*
2
- *= require admin/spree_backend
3
- */
@@ -1,3 +1 @@
1
- /*
2
- *= require store/spree_frontend
3
- */
1
+
@@ -3,20 +3,13 @@ module Spree
3
3
  class FavoriteProductsController < Spree::Admin::BaseController
4
4
 
5
5
  def index
6
- @search = Spree::Product.favorite.search(params[:q])
7
- @favorite_products = @search.result.order_by_favorite_users_count(sort_in_ascending_users_count?).page(params[:page])
6
+ @favorite_products = Spree::Product.favorite.page(params[:page])
8
7
  end
9
8
 
10
9
  def users
11
10
  @product = Spree::Product.where(:id => params[:id]).first
12
11
  @users = @product.favorite_users.page(params[:page])
13
12
  end
14
-
15
-
16
- private
17
- def sort_in_ascending_users_count?
18
- params[:q] && params[:q][:s] == 'favorite_users_count asc'
19
- end
20
13
  end
21
14
  end
22
15
  end
@@ -1,12 +1,8 @@
1
1
  Spree::Product.class_eval do
2
- has_many :favorites, :dependent => :destroy
2
+ has_many :favorites
3
3
  has_many :favorite_users, :through => :favorites, :class_name => 'Spree::User', :source => 'user'
4
4
 
5
5
  def self.favorite
6
- joins(:favorites).group('spree_favorites.product_id')
7
- end
8
-
9
- def self.order_by_favorite_users_count(asc=false)
10
- order("count(spree_favorites.user_id) #{asc ? 'asc' : 'desc'}")
6
+ joins(:favorites).uniq
11
7
  end
12
8
  end
@@ -1,5 +1,5 @@
1
1
  Spree::User.class_eval do
2
- has_many :favorites, :dependent => :destroy
2
+ has_many :favorites
3
3
  has_many :favorite_products, :through => :favorites, :class_name => 'Spree::Product', :source => 'product'
4
4
 
5
5
  def has_favorite_product?(product_id)
@@ -19,9 +19,9 @@
19
19
  <thead>
20
20
  <tr data-hook="admin_products_index_headers">
21
21
  <th><%= Spree.t(:sku) %></th>
22
- <th colspan="2"><%= sort_link @search, :name, Spree.t(:name) %></th>
23
- <th><%= sort_link @search, :master_default_price_amount, Spree.t(:master_price) %></th>
24
- <th><%= sort_link @search, 'favorite_users_count', 'Favorite Users' %></th>
22
+ <th colspan="2"><%= Spree.t(:name) %></th>
23
+ <th><%= Spree.t(:master_price) %></th>
24
+ <th>Favorite Users</th>
25
25
  </tr>
26
26
  </thead>
27
27
  <tbody>
@@ -29,7 +29,7 @@
29
29
  <tr <%= "style='color: red;'" if product.deleted? %> id="<%= spree_dom_id product %>" data-hook="admin_products_index_rows" class="<%= cycle('odd', 'even') %>">
30
30
  <td class="align-center"><%= product.sku rescue '' %></td>
31
31
  <td class="align-center"><%= mini_image(product) %></td>
32
- <td><%= link_to product.try(:name), edit_admin_product_path(product) %></td>
32
+ <td><%= product.try(:name) %></td>
33
33
  <td class="align-center"><%= product.display_price.to_html rescue '' %></td>
34
34
  <td class='align-center'><%= link_to product.favorite_users.count, users_admin_favorite_product_path(:id => product.id) %></td>
35
35
  </tr>
@@ -5,9 +5,6 @@
5
5
  } else {
6
6
  $("#favorite_product_<%= @favorite.product_id%>").remove();
7
7
  alert("Successfully removed favorite product from your list");
8
- if (!$('.favorite_product').length) {
9
- window.location = '<%= favorite_products_path %>'
10
- }
11
8
  }
12
9
  <% else %>
13
10
  alert("Could not remove product form your list")
@@ -1,7 +1,7 @@
1
1
  <div data-hook="account_my_favorite_products" class="account-my-favorite-products commonform">
2
2
  <h3><%= Spree.t(:my_favorite_products) %></h3>
3
3
  <% if @favorite_products.present? %>
4
- <table class="favorite-products order-summary" width='100%'>
4
+ <table class="favorite-products order-summary">
5
5
  <thead>
6
6
  <tr>
7
7
  <th class="favorite-product-image"><%= Spree.t(:product_image) %></th>
@@ -11,10 +11,10 @@
11
11
  </thead>
12
12
  <tbody>
13
13
  <% @favorite_products.each do |product| %>
14
- <tr class="<%= cycle('even', 'odd') %> favorite_product" id="favorite_product_<%= product.id %>">
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(:id => product.id), :method => :delete, :remote => true, :confirm => 'Are you sure you want to remove the product?' %>
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>
@@ -5,13 +5,13 @@ module SpreeFavoriteProducts
5
5
  class_option :auto_run_migrations, :type => :boolean, :default => false
6
6
 
7
7
  def add_javascripts
8
- append_file 'app/assets/javascripts/store/all.js', "\n//= require store/spree_favorite_products\n"
9
- append_file 'app/assets/javascripts/admin/all.js', "\n//= require admin/spree_favorite_products\n"
8
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "\n//= require store/spree_favorite_products\n"
9
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "\n//= require admin/spree_favorite_products\n"
10
10
  end
11
11
 
12
12
  def add_stylesheets
13
- inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_favorite_products\n", :before => /\*\//, :verbose => true
14
- inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_favorite_products\n", :before => /\*\//, :verbose => true
13
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require store/spree_favorite_products\n", :before => /\*\//, :verbose => true
14
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require admin/spree_favorite_products\n", :before => /\*\//, :verbose => true
15
15
  end
16
16
 
17
17
  def add_migrations
@@ -15,51 +15,22 @@ describe Spree::Admin::FavoriteProductsController do
15
15
  roles.stub(:includes).with(:permissions).and_return(roles)
16
16
  controller.stub(:authorize_admin).and_return(true)
17
17
  controller.stub(:authorize!).and_return(true)
18
-
19
- @favorite_products = double('favorite_products')
20
- @favorite_products.stub(:order_by_favorite_users_count).and_return(@favorite_products)
21
- @search = double('search', :result => @favorite_products)
22
- @favorite_products.stub(:search).and_return(@search)
23
- @favorite_products.stub(:page).and_return(@favorite_products)
24
- Spree::Product.stub(:favorite).and_return(@favorite_products)
25
18
  end
26
19
 
27
20
  describe "GET index" do
28
21
  def send_request
29
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'name desc' }
30
- end
31
-
32
- it "returns favorite products" do
33
- Spree::Product.should_receive(:favorite)
34
- send_request
22
+ get :index, :page => 1 ,:use_route => 'spree'
35
23
  end
36
24
 
37
- it "searches favorite products" do
38
- @favorite_products.should_receive(:search).with('s' => 'name desc')
39
- send_request
25
+ before(:each) do
26
+ @favorite_products = double('favorite_products')
27
+ @favorite_products.stub(:page).and_return(@favorite_products)
28
+ Spree::Product.stub(:favorite).and_return(@favorite_products)
40
29
  end
41
30
 
42
- it "assigns @search" do
31
+ it "returns favorite products" do
32
+ Spree::Product.should_receive(:favorite)
43
33
  send_request
44
- assigns(:search).should eq(@search)
45
- end
46
-
47
- context 'when order favorite products by users count in asc order' do
48
- def send_request
49
- get :index, :page => 1 ,:use_route => 'spree', :q => { :s => 'favorite_users_count asc' }
50
- end
51
-
52
- it "orders favorite products by users count in asc order" do
53
- @favorite_products.should_receive(:order_by_favorite_users_count).with(true)
54
- send_request
55
- end
56
- end
57
-
58
- context 'when order favorite products by users count in desc order' do
59
- it "orders favorite products by users count in asc order" do
60
- @favorite_products.should_receive(:order_by_favorite_users_count).with(false)
61
- send_request
62
- end
63
34
  end
64
35
 
65
36
  it "paginates favorite products" do
@@ -98,21 +69,4 @@ describe Spree::Admin::FavoriteProductsController do
98
69
  send_request
99
70
  end
100
71
  end
101
-
102
- describe "#sort_in_ascending_users_count?" do
103
-
104
- context 'when favorite_user_count asc present in params[q][s]' do
105
- it "is true" do
106
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'favorite_users_count asc' }
107
- controller.send(:sort_in_ascending_users_count?).should be_true
108
- end
109
- end
110
-
111
- context 'when favorite_user_count not present in params' do
112
- it "is false" do
113
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'name asc' }
114
- controller.send(:sort_in_ascending_users_count?).should be_false
115
- end
116
- end
117
- end
118
72
  end
@@ -1,39 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::Product do
4
- before(:each) do
5
- shipping_category = Spree::ShippingCategory.create! :name => 'shipping_category'
6
- @favorite_product1 = Spree::Product.create! :name => 'favorite_product1', :price => 100, :shipping_category_id => shipping_category.id
7
- @favorite_product2 = Spree::Product.create! :name => 'favorite_product2', :price => 100, :shipping_category_id => shipping_category.id
8
- @product1 = Spree::Product.create! :name => 'product1', :price => 100, :shipping_category_id => shipping_category.id
9
- @product2 = Spree::Product.create! :name => 'product2', :price => 100, :shipping_category_id => shipping_category.id
10
- @user1 = Spree::User.create! :email => 'user1@example.com', :password => 'example', :password_confirmation => "example"
11
- @user2 = Spree::User.create! :email => 'user2@example.com', :password => "example", :password_confirmation => 'example'
12
- @user1.favorites.create! :product_id => @favorite_product1.id
13
- @user2.favorites.create! :product_id => @favorite_product1.id
14
- @user2.favorites.create! :product_id => @favorite_product2.id
15
- end
16
-
17
- it { should have_many(:favorites).dependent(:destroy) }
4
+ it { should have_many(:favorites) }
18
5
  it { should have_many(:favorite_users).through(:favorites).class_name('Spree::User') }
19
6
 
20
7
  describe "Spree::Product.favorite" do
21
- it "returns favorite products" do
22
- Spree::Product.favorite.should =~ [@favorite_product1, @favorite_product2]
8
+ before(:each) do
9
+ shipping_category = Spree::ShippingCategory.create! :name => 'shipping_category'
10
+ @favorite_product1 = Spree::Product.create! :name => 'favorite_product1', :price => 100, :shipping_category_id => shipping_category.id
11
+ @favorite_product2 = Spree::Product.create! :name => 'favorite_product2', :price => 100, :shipping_category_id => shipping_category.id
12
+ @product1 = Spree::Product.create! :name => 'product1', :price => 100, :shipping_category_id => shipping_category.id
13
+ @product2 = Spree::Product.create! :name => 'product2', :price => 100, :shipping_category_id => shipping_category.id
14
+ @user1 = Spree::User.create! :email => 'user1@example.com', :password => 'example', :password_confirmation => "example"
15
+ @user2 = Spree::User.create! :email => 'user2@example.com', :password => "example", :password_confirmation => 'example'
16
+ @user1.favorites.create! :product_id => @favorite_product1.id
17
+ @user2.favorites.create! :product_id => @favorite_product1.id
18
+ @user2.favorites.create! :product_id => @favorite_product2.id
23
19
  end
24
- end
25
20
 
26
- describe ".order_by_favorite_users_count" do
27
- context 'when order not passed' do
28
- it "returns products ordered by users_count in descending order" do
29
- Spree::Product.favorite.order_by_favorite_users_count.should eq([@favorite_product1, @favorite_product2])
30
- end
31
- end
32
-
33
- context 'when asc order passed' do
34
- it "returns products ordered by users_count in ascending order" do
35
- Spree::Product.favorite.order_by_favorite_users_count(true).should eq([@favorite_product2, @favorite_product1])
36
- end
21
+ it "returns favorite products" do
22
+ Spree::Product.favorite.should =~ [@favorite_product1, @favorite_product2]
37
23
  end
38
24
  end
39
25
  end
@@ -11,7 +11,7 @@ describe Spree::User do
11
11
  favorite.save!
12
12
  end
13
13
 
14
- it { should have_many(:favorites).dependent(:destroy) }
14
+ it { should have_many(:favorites) }
15
15
  it { should have_many(:favorite_products).through(:favorites).class_name('Spree::Product') }
16
16
 
17
17
  describe "has_favorite_product?" do
@@ -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.3'
5
+ s.version = '2.2.0'
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'
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.require_path = 'lib'
18
18
  s.requirements << 'none'
19
19
 
20
- s.add_dependency 'spree_core', '~> 2.1.0'
20
+ s.add_dependency 'spree_core', '~> 2.2.0'
21
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_favorite_products
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
+ - 2
8
9
  - 0
9
- - 3
10
- version: 2.0.3
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mohit Bansal
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-05-15 00:00:00 Z
18
+ date: 2014-03-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spree_core
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 11
28
+ hash: 7
29
29
  segments:
30
30
  - 2
31
- - 1
31
+ - 2
32
32
  - 0
33
- version: 2.1.0
33
+ version: 2.2.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
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"
@@ -63,7 +63,6 @@ files:
63
63
  - app/overrides/.DS_Store
64
64
  - app/overrides/add_favorite_products_per_page_configuration.rb
65
65
  - app/overrides/add_favorite_products_tab.rb
66
- - app/overrides/add_favorite_products_to_products_tab.rb
67
66
  - app/overrides/add_link_to_mark_product_as_favorite.rb
68
67
  - app/overrides/add_link_to_users_favorite_products.rb
69
68
  - app/views/spree/.DS_Store
@@ -1,11 +0,0 @@
1
- Deface::Override.new(
2
- :virtual_path => 'spree/admin/shared/_tabs',
3
- :name => 'select_products_tab',
4
- :replace => "erb[silent]:contains('if can? :admin, Spree::Product')",
5
- :closing_selector => "erb[silent]:contains('end')",
6
- :text => %Q{
7
- <% if can? :admin, Spree::Product %>
8
- <%= tab :products, :option_types, :properties, :prototypes, :variants, :product_properties, :taxonomies, :favorite_products, :icon => 'icon-th-large' %>
9
- <% end %>
10
- }
11
- )