spree_favorite_products 2.2.0 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,14 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Provides basic authentication functionality for testing parts of your engine
4
- gem 'spree', '2.1.0'
5
- gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
4
+ gem 'spree', '2.2.0'
5
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
6
6
  gem 'mysql2'
7
7
 
8
+ group :assets do
9
+ gem 'coffee-rails', '4.0.1'
10
+ end
11
+
8
12
  group :test do
9
13
  gem 'rspec-rails', '~> 2.10'
10
14
  gem 'shoulda-matchers', '2.2.0'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- SpreeFavoriteProducts [![Code Climate](https://codeclimate.com/github/vinsol/spree_favorite_products.png)](https://codeclimate.com/github/vinsol/spree_favorite_products) [![Build Status](https://travis-ci.org/vinsol/spree_favorite_products.png?branch=master)](https://travis-ci.org/vinsol/spree_favorite_products)
1
+ Spree Favorite Products [![Code Climate](https://codeclimate.com/github/vinsol/spree_favorite_products.png)](https://codeclimate.com/github/vinsol/spree_favorite_products) [![Build Status](https://travis-ci.org/vinsol/spree_favorite_products.png?branch=master)](https://travis-ci.org/vinsol/spree_favorite_products)
2
2
  =====================
3
3
 
4
4
  This extension adds the following features:
@@ -20,7 +20,7 @@ For older versions of spree.
20
20
 
21
21
  ```ruby
22
22
  # Spree 2.1.x
23
- gem 'spree_favorite_products', '2.0.1'
23
+ gem 'spree_favorite_products', '2.0.2'
24
24
  ```
25
25
 
26
26
  ```ruby
@@ -53,6 +53,17 @@ Simply add this require statement to your spec_helper:
53
53
  require 'spree_favorite_products/factories'
54
54
  ```
55
55
 
56
+ Contributing
57
+ ------------
58
+
59
+ 1. Fork the repo.
60
+ 2. Clone your repo.
61
+ 3. Run `bundle install`.
62
+ 4. Run `bundle exec rake test_app` to create the test application in `spec/test_app`.
63
+ 5. Make your changes.
64
+ 6. Ensure specs pass by running `bundle exec rspec spec`.
65
+ 7. Submit your pull request.
66
+
56
67
  Credits
57
68
  -------
58
69
 
@@ -3,13 +3,19 @@ module Spree
3
3
  class FavoriteProductsController < Spree::Admin::BaseController
4
4
 
5
5
  def index
6
- @favorite_products = Spree::Product.favorite.page(params[:page])
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])
7
8
  end
8
9
 
9
10
  def users
10
11
  @product = Spree::Product.where(:id => params[:id]).first
11
12
  @users = @product.favorite_users.page(params[:page])
12
13
  end
14
+
15
+ private
16
+ def sort_in_ascending_users_count?
17
+ params[:q] && params[:q][:s] == 'favorite_users_count asc'
18
+ end
13
19
  end
14
20
  end
15
21
  end
@@ -3,6 +3,10 @@ Spree::Product.class_eval do
3
3
  has_many :favorite_users, :through => :favorites, :class_name => 'Spree::User', :source => 'user'
4
4
 
5
5
  def self.favorite
6
- joins(:favorites).uniq
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'}")
7
11
  end
8
12
  end
@@ -0,0 +1,11 @@
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
+ )
@@ -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"><%= Spree.t(:name) %></th>
23
- <th><%= Spree.t(:master_price) %></th>
24
- <th>Favorite Users</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>
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><%= product.try(:name) %></td>
32
+ <td><%= link_to product.try(:name), edit_admin_product_path(product) %></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>
@@ -15,17 +15,18 @@ 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)
18
25
  end
19
26
 
20
27
  describe "GET index" do
21
28
  def send_request
22
- get :index, :page => 1 ,:use_route => 'spree'
23
- end
24
-
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)
29
+ get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'name desc' }
29
30
  end
30
31
 
31
32
  it "returns favorite products" do
@@ -33,6 +34,34 @@ describe Spree::Admin::FavoriteProductsController do
33
34
  send_request
34
35
  end
35
36
 
37
+ it "searches favorite products" do
38
+ @favorite_products.should_receive(:search).with('s' => 'name desc')
39
+ send_request
40
+ end
41
+
42
+ it "assigns @search" do
43
+ 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
+ end
64
+
36
65
  it "paginates favorite products" do
37
66
  @favorite_products.should_receive(:page).with("1")
38
67
  send_request
@@ -69,4 +98,21 @@ describe Spree::Admin::FavoriteProductsController do
69
98
  send_request
70
99
  end
71
100
  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
72
118
  end
@@ -1,25 +1,42 @@
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
+
4
18
  it { should have_many(:favorites) }
5
19
  it { should have_many(:favorite_users).through(:favorites).class_name('Spree::User') }
6
20
 
7
21
  describe "Spree::Product.favorite" do
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
19
- end
22
+
20
23
 
21
24
  it "returns favorite products" do
22
25
  Spree::Product.favorite.should =~ [@favorite_product1, @favorite_product2]
23
26
  end
24
27
  end
28
+
29
+ describe ".order_by_favorite_users_count" do
30
+ context 'when order not passed' do
31
+ it "returns products ordered by users_count in descending order" do
32
+ Spree::Product.favorite.order_by_favorite_users_count.should eq([@favorite_product1, @favorite_product2])
33
+ end
34
+ end
35
+
36
+ context 'when asc order passed' do
37
+ it "returns products ordered by users_count in ascending order" do
38
+ Spree::Product.favorite.order_by_favorite_users_count(true).should eq([@favorite_product2, @favorite_product1])
39
+ end
40
+ end
41
+ end
25
42
  end
@@ -2,8 +2,8 @@
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.2.0'
6
- s.summary = 'users can mark product as favorite'
5
+ s.version = '2.2.2'
6
+ s.summary = 'Favorite Products in Spree'
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'
9
9
 
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: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 0
10
- version: 2.2.0
9
+ - 2
10
+ version: 2.2.2
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-03-12 00:00:00 Z
18
+ date: 2014-04-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spree_core
@@ -63,6 +63,7 @@ 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
66
67
  - app/overrides/add_link_to_mark_product_as_favorite.rb
67
68
  - app/overrides/add_link_to_users_favorite_products.rb
68
69
  - app/views/spree/.DS_Store
@@ -122,6 +123,6 @@ rubyforge_project:
122
123
  rubygems_version: 1.8.24
123
124
  signing_key:
124
125
  specification_version: 3
125
- summary: users can mark product as favorite
126
+ summary: Favorite Products in Spree
126
127
  test_files: []
127
128