spree_favorite_products 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -1
  4. data/Gemfile +10 -11
  5. data/README.md +8 -25
  6. data/Rakefile +1 -2
  7. data/app/assets/javascripts/spree/backend/spree_favorite_products.js +0 -0
  8. data/app/assets/javascripts/spree/frontend/spree_favorite_products.js +23 -0
  9. data/app/assets/stylesheets/spree/backend/spree_favorite_products.css +0 -0
  10. data/app/assets/stylesheets/spree/frontend/spree_favorite_products.css +0 -0
  11. data/app/controllers/spree/admin/favorite_products_controller.rb +14 -5
  12. data/app/controllers/spree/admin/products_controller_decorator.rb +6 -0
  13. data/app/controllers/spree/admin/users_controller_decorator.rb +5 -0
  14. data/app/controllers/spree/favorite_products_controller.rb +14 -6
  15. data/app/models/spree/app_configuration_decorator.rb +2 -1
  16. data/app/models/spree/favorite.rb +9 -6
  17. data/app/models/spree/product_decorator.rb +6 -10
  18. data/app/models/spree/user_decorator.rb +5 -5
  19. data/app/overrides/add_favorite_products_per_page_configuration.rb +5 -5
  20. data/app/overrides/add_favorite_products_to_products_tab.rb +4 -4
  21. data/app/overrides/add_favorite_users_tab_to_products.rb +10 -0
  22. data/app/overrides/add_link_to_mark_product_as_favorite.rb +8 -7
  23. data/app/overrides/add_link_to_users_favorite_products.rb +5 -5
  24. data/app/overrides/addd_favorite_products_tab_to_users.rb +10 -0
  25. data/app/views/spree/admin/favorite_products/_users.html.erb +25 -0
  26. data/app/views/spree/admin/favorite_products/index.html.erb +9 -16
  27. data/app/views/spree/admin/products/favorite_users.html.erb +14 -0
  28. data/app/views/spree/admin/users/favorite_products.html.erb +50 -0
  29. data/app/views/spree/favorite_products/destroy.js.erb +1 -1
  30. data/app/views/spree/favorite_products/index.html.erb +6 -6
  31. data/config/locales/bg.yml +13 -0
  32. data/config/locales/en.yml +21 -3
  33. data/config/locales/pl.yml +19 -0
  34. data/config/routes.rb +11 -3
  35. data/db/migrate/20130705080641_create_table_favorites.rb +1 -1
  36. data/db/migrate/20130710105100_rename_favorites_to_spree_favorites.rb +1 -1
  37. data/db/migrate/20160304152800_add_favorites_user_counts_to_product.rb +6 -0
  38. data/lib/generators/spree_favorite_products/install/install_generator.rb +4 -3
  39. data/spec/controllers/spree/admin/favorite_products_controller_spec.rb +31 -41
  40. data/spec/controllers/spree/admin/products_controller_decorator_spec.rb +28 -0
  41. data/spec/controllers/spree/admin/users_controller_decorator_spec.rb +28 -0
  42. data/spec/controllers/spree/favorite_products_controller_spec.rb +25 -33
  43. data/spec/models/spree/app_configuration_decorator_spec.rb +2 -2
  44. data/spec/models/spree/favorite_spec.rb +21 -19
  45. data/spec/models/spree/product_decorator_spec.rb +16 -16
  46. data/spec/models/spree/user_decorator_spec.rb +9 -8
  47. data/spec/spec_helper.rb +21 -0
  48. data/spree_favorite_products.gemspec +9 -5
  49. metadata +80 -7
  50. data/Gemfile.lock +0 -345
@@ -0,0 +1,14 @@
1
+ <% content_for :page_actions do %>
2
+ <% if can?(:create, Spree::Product) %>
3
+ <%= button_link_to Spree.t(:new_product), new_object_url, { class: "btn-success", icon: 'add', id: 'admin_new_product' } %>
4
+ <% end %>
5
+ <% end %>
6
+
7
+ <%= render partial: 'spree/admin/shared/product_tabs', locals: { current: :favorited_by } %>
8
+
9
+
10
+ <%= paginate @users if @user.present? %>
11
+
12
+ <%= render 'spree/admin/favorite_products/users', users: @users %>
13
+
14
+ <%= paginate @users if @user.present? %>
@@ -0,0 +1,50 @@
1
+ <%= render partial: 'spree/admin/users/sidebar', locals: { current: :favorite_products } %>
2
+ <%= render partial: 'spree/admin/users/user_page_actions' %>
3
+
4
+ <% content_for :page_title do %>
5
+ <%= @user.email %>
6
+ <% end %>
7
+
8
+ <div data-hook="admin_user_edit_general_settings" class="panel panel-default">
9
+ <div class="panel-heading">
10
+ <h1 class="panel-title">
11
+ <%= Spree.t(:favorite_product) %>
12
+ </h1>
13
+ </div>
14
+
15
+ <div class="panel-body">
16
+ <div data-hook="account_my_favorite_products" class="account-my-favorite-products commonform">
17
+ <h3><%= Spree.t(:favorite_products, scope: [:admin, :tab]) %></h3>
18
+ <% if @favorite_products.present? %>
19
+ <table class="favorite-products order-summary table table-striped" width="100%">
20
+ <thead>
21
+ <tr>
22
+ <th class="favorite-product-image"><%= Spree.t(:product_image) %></th>
23
+ <th class="favorite-product-name"><%= Spree.t(:product_name) %></th>
24
+ <th class="favorite-product-action actions"></th>
25
+ </tr>
26
+ </thead>
27
+ <tbody>
28
+ <% @favorite_products.each do |product| %>
29
+ <tr class="<%= cycle('even', 'odd') %> favorite_product" id="favorite_product_<%= product.id %>">
30
+ <td class="favorite-product-image"><%= link_to admin_product_path(product) do %>
31
+ <%= mini_image product %>
32
+ <% end %>
33
+ </td>
34
+ <td class="favorite-product-name"><%=link_to product.name, admin_product_path(product) %></td>
35
+ <td class="favorite-product-remove actions text-right">
36
+ <%= link_to_edit product, no_text: true, url: admin_product_path(product) %>
37
+ <%= link_to_delete product, no_text: true, url: admin_favorite_product_path(id: product.favorites.where(user_id: @user.id).first) %>
38
+ </tr>
39
+ <% end %>
40
+ </tbody>
41
+ </table>
42
+ <% else %>
43
+ <p><%= Spree.t(:you_have_no_favorite_products_yet) %></p>
44
+ <% end %>
45
+
46
+ <%= paginate @favorite_products %>
47
+ </div>
48
+ </div>
49
+ </div>
50
+
@@ -11,4 +11,4 @@
11
11
  }
12
12
  <% else %>
13
13
  alert("Could not remove product form your list")
14
- <% end %>
14
+ <% end %>
@@ -1,20 +1,20 @@
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 table table-striped" width="100%">
5
5
  <thead>
6
6
  <tr>
7
7
  <th class="favorite-product-image"><%= Spree.t(:product_image) %></th>
8
8
  <th class="favorite-product-name"><%= Spree.t(:product_name) %></th>
9
- <th class="favorite-product-action">Action</th>
9
+ <th class="favorite-product-action text-right"><%= Spree.t(:action) %></th>
10
10
  </tr>
11
11
  </thead>
12
12
  <tbody>
13
13
  <% @favorite_products.each do |product| %>
14
14
  <tr class="<%= cycle('even', 'odd') %> favorite_product" id="favorite_product_<%= product.id %>">
15
- <td class="favorite-product-image"><%= link_to small_image(product), product_path(product) %></td>
15
+ <td class="favorite-product-image"><%= link_to mini_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 text-right"><%= link_to Spree.t(:remove), favorite_product_path(id: product.id), method: :delete, remote: true, confirm: 'Are you sure you want to remove the product?' %>
18
18
  </tr>
19
19
  <% end %>
20
20
  </tbody>
@@ -22,6 +22,6 @@
22
22
  <% else %>
23
23
  <p><%= Spree.t(:you_have_no_favorite_products_yet) %></p>
24
24
  <% end %>
25
-
25
+
26
26
  <%= paginate @favorite_products %>
27
- </div>
27
+ </div>
@@ -0,0 +1,13 @@
1
+ bg:
2
+ spree:
3
+ duplicate_favorite: 'Вече е добавено в любимо'
4
+ favorite_products:
5
+ create:
6
+ success: 'Успешно маркиран като любим'
7
+ favorite_products_per_page: "Любими продукти на страница"
8
+ favorite_products_settings: "Любими продукти настойки"
9
+ mark_as_favorite: "Добави в любими"
10
+ unmark_as_favorite: "Премахни от любими"
11
+ admin:
12
+ tab:
13
+ favorite_products: "Любими продукти"
@@ -3,7 +3,25 @@
3
3
 
4
4
  en:
5
5
  spree:
6
- favorite_products_settings: "Favorite Products Settings"
6
+ admin:
7
+ tab:
8
+ favorite_products: Favorite Products
9
+ duplicate_favorite: 'already marked as favorite'
10
+ favorite_products:
11
+ create:
12
+ success: 'Product has been successfully marked as favorite'
13
+ favorite_users: "Favorite users"
7
14
  favorite_products_per_page: "Favorite Products Shown Per Page"
8
- mark_as_favorite: "Mark as favorite"
9
- unmark_as_favorite: "Unmark as favorite"
15
+ favorite_products_settings: "Favorite Products Settings"
16
+ mark_as_favorite: "Mark As Favorite"
17
+ unmark_as_favorite: "Remove From Favorite"
18
+ listing_favorite_products: Listing Favorite Products
19
+ listing_favorite_products_users: Listing Favorite Product Users
20
+ user_count: User Count
21
+ my_favorite_products: My Favorite Products
22
+ product_image: Product Image
23
+ product_name: Product Name
24
+ favorites: Favorites
25
+ are_you_sure_to_remove_product: Are you sure you want to remove the product?
26
+ login_to_add_favorite: Please Login to Add Favorite
27
+ favorited_by: Favorited By
@@ -0,0 +1,19 @@
1
+ pl:
2
+ spree:
3
+ duplicate_favorite: 'Produkt jest już dodany do ulubionych'
4
+ favorite_products:
5
+ title: Ulubione produkty
6
+ create:
7
+ success: 'Polubiono produkt!'
8
+ favorite_products_per_page: "Liczba ulubionych produktów wyświetlona na stronie"
9
+ favorite_products_settings: "Ustawienia ulubionych produktów"
10
+ favorite_users: "Użytkownicy"
11
+ listing_favorite_products: "Lista polubionych produktów"
12
+ listing_favorite_products_users: "Użytkownicy, którzy polubili produkt"
13
+ my_favorite_products: Polubione przeze mnie
14
+ mark_as_favorite: "Dodaj do ulubionych"
15
+ unmark_as_favorite: "Usuń z ulubionych"
16
+ you_have_no_favorite_products_yet: "Nie polubiono jeszcze żadnego produktu."
17
+ admin:
18
+ tab:
19
+ favorite_products: "Lista polubionych produktów"
@@ -1,10 +1,18 @@
1
1
  Spree::Core::Engine.routes.draw do
2
2
  # Add your extension routes here
3
3
  namespace :admin do
4
- resources :favorite_products, :only => :index do
5
- get :users, :on => :member
4
+ resources :favorite_products, only: [:index, :destroy] do
5
+ get :users, on: :member, to: 'products#favorite_users'
6
+ end
7
+
8
+ resources :products do
9
+ get :favorite_users, on: :member
10
+ end
11
+
12
+ resources :users do
13
+ get :favorite_products, on: :member
6
14
  end
7
15
  end
8
16
 
9
- resources :favorite_products, :only => [:index, :create, :destroy]
17
+ resources :favorite_products, only: [:index, :create, :destroy]
10
18
  end
@@ -3,7 +3,7 @@ class CreateTableFavorites < ActiveRecord::Migration
3
3
  create_table :favorites do |t|
4
4
  t.integer :user_id
5
5
  t.integer :product_id
6
- t.timestamps
6
+ t.timestamps null: false
7
7
  end
8
8
  end
9
9
  end
@@ -1,7 +1,7 @@
1
1
  class RenameFavoritesToSpreeFavorites < ActiveRecord::Migration
2
2
  def change
3
3
  rename_table :favorites, :spree_favorites
4
- add_index :spree_favorites, [:user_id, :product_id], :unique => true
4
+ add_index :spree_favorites, [:user_id, :product_id], unique: true
5
5
  add_index :spree_favorites, :user_id
6
6
  end
7
7
  end
@@ -0,0 +1,6 @@
1
+ class AddFavoritesUserCountsToProduct < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_products, :favorite_users_count, :integer, default: 0
4
+ add_index :spree_products, :favorite_users_count
5
+ end
6
+ end
@@ -2,16 +2,17 @@ module SpreeFavoriteProducts
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
 
5
- class_option :auto_run_migrations, :type => :boolean, :default => false
5
+ class_option :auto_run_migrations, type: :boolean, default: false
6
6
 
7
7
  def add_javascripts
8
8
  append_file 'vendor/assets/javascripts/spree/frontend/all.js', "\n//= require store/spree_favorite_products\n"
9
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "\n//= require spree/frontend/spree_favorite_products\n"
9
10
  append_file 'vendor/assets/javascripts/spree/backend/all.js', "\n//= require admin/spree_favorite_products\n"
10
11
  end
11
12
 
12
13
  def add_stylesheets
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
14
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require store/spree_favorite_products\n", before: /\*\//, verbose: true
15
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require admin/spree_favorite_products\n", before: /\*\//, verbose: true
15
16
  end
16
17
 
17
18
  def add_migrations
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::Admin::FavoriteProductsController do
4
- let(:role) { Spree::Role.create!(:name => 'user') }
4
+ let(:role) { Spree::Role.create!(name: 'user') }
5
5
  let(:roles) { [role] }
6
6
  let(:product) { mock_model( Spree::Product) }
7
7
  let(:proxy_object) { Object.new }
8
8
 
9
9
  before(:each) do
10
- @user = mock_model(Spree::User, :generate_spree_api_key! => false)
10
+ @user = mock_model(Spree::User, generate_spree_api_key!: false)
11
11
  allow(@user).to receive(:roles).and_return(proxy_object)
12
12
  allow(proxy_object).to receive(:includes).and_return([])
13
13
 
@@ -20,8 +20,9 @@ describe Spree::Admin::FavoriteProductsController do
20
20
  allow(controller).to receive(:authorize!).and_return(true)
21
21
 
22
22
  @favorite_products = double('favorite_products')
23
+ allow(@favorite_products).to receive(:includes).and_return(@favorite_products)
23
24
  allow(@favorite_products).to receive(:order_by_favorite_users_count).and_return(@favorite_products)
24
- @search = double('search', :result => @favorite_products)
25
+ @search = double('search', result: @favorite_products)
25
26
  allow(@favorite_products).to receive(:search).and_return(@search)
26
27
  allow(@favorite_products).to receive(:page).and_return(@favorite_products)
27
28
  allow(Spree::Product).to receive(:favorite).and_return(@favorite_products)
@@ -29,93 +30,82 @@ describe Spree::Admin::FavoriteProductsController do
29
30
 
30
31
  describe "GET index" do
31
32
  def send_request
32
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'name desc' }
33
+ get :index, params: { page: 1, q: { s: 'name desc' } }
33
34
  end
34
35
 
35
36
  it "returns favorite products" do
36
- Spree::Product.should_receive(:favorite)
37
+ expect(Spree::Product).to receive(:favorite)
37
38
  send_request
38
39
  end
39
40
 
40
41
  it "searches favorite products" do
41
- @favorite_products.should_receive(:search).with('s' => 'name desc')
42
+ search_params = ActionController::Parameters.new(s: 'name desc')
43
+ expect(@favorite_products).to receive(:search).with(search_params)
42
44
  send_request
43
45
  end
44
46
 
45
47
  it "assigns @search" do
46
48
  send_request
47
- assigns(:search).should eq(@search)
49
+ expect(assigns(:search)).to eq(@search)
48
50
  end
49
51
 
50
52
  context 'when order favorite products by users count in asc order' do
51
53
  def send_request
52
- get :index, :page => 1 ,:use_route => 'spree', :q => { :s => 'favorite_users_count asc' }
54
+ get :index, params: { page: 1, q: { s: 'favorite_users_count asc' } }
53
55
  end
54
56
 
55
57
  it "orders favorite products by users count in asc order" do
56
- @favorite_products.should_receive(:order_by_favorite_users_count).with(true)
58
+ expect(@favorite_products).to receive(:order_by_favorite_users_count).with(true)
57
59
  send_request
58
60
  end
59
61
  end
60
62
 
61
63
  context 'when order favorite products by users count in desc order' do
62
64
  it "orders favorite products by users count in asc order" do
63
- @favorite_products.should_receive(:order_by_favorite_users_count).with(false)
65
+ expect(@favorite_products).to receive(:order_by_favorite_users_count).with(false)
64
66
  send_request
65
67
  end
66
68
  end
67
69
 
68
70
  it "paginates favorite products" do
69
- @favorite_products.should_receive(:page).with("1")
71
+ expect(@favorite_products).to receive(:page).with("1")
70
72
  send_request
71
73
  end
72
74
 
73
75
  it "renders favorite products template" do
74
76
  send_request
75
- response.should render_template(:index)
76
- end
77
- end
78
-
79
- describe "#users" do
80
- before do
81
- @users = [@user]
82
- allow(@users).to receive(:page).and_return(@users)
83
- allow(product).to receive(:favorite_users).and_return(@users)
84
- @products = [product]
85
- allow(Spree::Product).to receive(:where).with(:id => product.id).and_return(@products)
86
- end
87
-
88
- def send_request
89
- get :users, :use_route => 'spree', :id => product.id, :format => :js
90
- end
91
-
92
- it 'fetches the product' do
93
- Spree::Product.should_receive(:where).with(:id => product.id).and_return(@products)
94
- end
95
-
96
- it 'fetches the users who marked the product as favorite' do
97
- product.should_receive(:favorite_users).and_return(@users)
98
- end
99
-
100
- after do
101
- send_request
77
+ expect(response).to render_template(:index)
102
78
  end
103
79
  end
104
80
 
105
81
  describe "#sort_in_ascending_users_count?" do
106
82
 
107
83
  context 'when favorite_user_count asc present in params[q][s]' do
84
+ def send_request
85
+ get :index, params: { page: 1, q: { s: 'favorite_users_count asc' } }
86
+ end
87
+
108
88
  it "is true" do
109
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'favorite_users_count asc' }
110
- controller.send(:sort_in_ascending_users_count?).should be_true
89
+ controller.send(:sort_in_ascending_users_count?).should be true
90
+ end
91
+
92
+ before do
93
+ send_request
111
94
  end
112
95
  end
113
96
 
114
97
  context 'when favorite_user_count not present in params' do
98
+ def send_request
99
+ get :index, params: { page: 1, q: { s: 'name asc' } }
100
+ end
101
+
115
102
  it "is false" do
116
- get :index, :page => 1 ,:use_route => 'spree', :q => { 's' => 'name asc' }
117
103
  controller.send(:sort_in_ascending_users_count?).should be false
118
104
  end
105
+
106
+ before do
107
+ send_request
108
+ end
119
109
  end
120
110
  end
121
111
  end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Spree::Admin::ProductsController, type: :controller do
4
+
5
+ describe 'GET users' do
6
+ stub_authorization!
7
+ let(:product) { mock_model(Spree::Product, id: 10) }
8
+ let(:favorite_product) { mock_model(Spree::Product) }
9
+ let(:favorite_users) { double(ActiveRecord::Relation) }
10
+
11
+ def send_request
12
+ get :favorite_users, params: { id: product.id }
13
+ end
14
+
15
+
16
+ before do
17
+ allow(Spree::Product).to receive_message_chain( :with_deleted, :friendly, :find).and_return(product)
18
+ allow(product).to receive(:favorite_users).and_return(favorite_users)
19
+ allow(favorite_users).to receive_message_chain(:page, :per).and_return(favorite_users)
20
+ end
21
+
22
+ it 'is expected to set favorite_users' do
23
+ expect(product).to receive(:favorite_users).and_return(favorite_users)
24
+ send_request
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Spree::Admin::UsersController, type: :controller do
4
+ let(:user) { mock_model(Spree::User) }
5
+ let(:favorite_product) { mock_model(Spree::Product) }
6
+ let(:favorite_products) { double(ActiveRecord::Relation) }
7
+
8
+ describe 'favorite_products' do
9
+ stub_authorization!
10
+
11
+ def send_request
12
+ get :favorite_products, params: { id: user.id }
13
+ end
14
+
15
+
16
+ before do
17
+ allow(Spree::User).to receive(:find).and_return(user)
18
+ allow(user).to receive(:favorite_products).and_return(favorite_products)
19
+ allow(favorite_products).to receive_message_chain(:page, :per).and_return(favorite_products)
20
+ end
21
+
22
+ it 'is expected to set favorite_products' do
23
+ expect(user).to receive(:favorite_products).and_return(favorite_products)
24
+ send_request
25
+ end
26
+
27
+ end
28
+ end