spree_favorite_products 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -3
- data/README.md +7 -0
- data/app/controllers/spree/favorite_products_controller.rb +2 -2
- data/app/models/spree/favorite.rb +0 -1
- data/app/models/spree/user_decorator.rb +0 -4
- data/app/overrides/add_link_to_mark_product_as_favorite.rb +1 -7
- data/app/views/spree/favorite_products/create.js.erb +0 -3
- data/app/views/spree/favorite_products/destroy.js.erb +3 -8
- data/app/views/spree/favorite_products/index.html.erb +1 -3
- data/config/locales/en.yml +0 -5
- data/spec/controllers/spree/admin/favorite_products_controller_spec.rb +1 -1
- data/spec/controllers/spree/favorite_products_controller_spec.rb +11 -18
- data/spec/models/spree/favorite_spec.rb +0 -1
- data/spec/models/spree/user_decorator_spec.rb +0 -22
- data/spree_favorite_products.gemspec +2 -2
- metadata +35 -55
- data/app/models/spree/app_configuration_decorator.rb +0 -3
- data/app/overrides/add_favorite_products_per_page_configuration.rb +0 -16
- data/spec/models/spree/app_configuration_decorator_spec.rb +0 -3
data/Gemfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Provides basic authentication functionality for testing parts of your engine
|
4
|
-
gem 'spree', '2.0
|
5
|
-
gem '
|
6
|
-
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable'
|
4
|
+
gem 'spree', '2.1.0'
|
5
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
|
7
6
|
gem 'mysql2'
|
8
7
|
|
9
8
|
group :test do
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@ SpreeFavoriteProducts [![Code Climate](https://codeclimate.com/github/vinsol/spr
|
|
2
2
|
=====================
|
3
3
|
|
4
4
|
This extension adds the following features:
|
5
|
+
|
5
6
|
1. Adds a link 'Mark as favorite' on product detail page.
|
6
7
|
2. Favorite Products tab on header
|
7
8
|
3. Favorite Products tab in admin section
|
@@ -15,6 +16,12 @@ Add spree_favorite_products to your Gemfile:
|
|
15
16
|
gem 'spree_favorite_products'
|
16
17
|
```
|
17
18
|
|
19
|
+
If you're still using Spree 2.0.x, you should do this instead:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'spree_favorite_products', '1.0.0'
|
23
|
+
```
|
24
|
+
|
18
25
|
Bundle your dependencies and run the installation generator:
|
19
26
|
|
20
27
|
```shell
|
@@ -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
|
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).where(:spree_products => {:
|
31
|
+
@favorite = spree_current_user.favorites.joins(:product).readonly(false).where(:spree_products => {:permalink => params[:id]}).first
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -2,11 +2,5 @@ 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 =>
|
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
|
-
}
|
5
|
+
:text => "<%= link_to 'Mark as favorite', favorite_products_path(:id => @product.id), :method => :post, :remote => spree_user_signed_in? %>"
|
12
6
|
)
|
@@ -1,11 +1,6 @@
|
|
1
1
|
<% if @success %>
|
2
|
-
|
3
|
-
|
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
|
-
}
|
2
|
+
$("#favorite_product_<%= @favorite.product_id%>").remove();
|
3
|
+
alert("Successfully removed favorite product from your list")
|
9
4
|
<% else %>
|
10
|
-
alert("Could not remove product form your list")
|
5
|
+
alert("Could not remove product form your list")
|
11
6
|
<% 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(
|
17
|
+
<td class="favorite-product-remove"><%= link_to 'Remove', favorite_product_path(product), :method => :delete, :remote => true %>
|
18
18
|
</tr>
|
19
19
|
<% end %>
|
20
20
|
</tbody>
|
@@ -22,6 +22,4 @@
|
|
22
22
|
<% else %>
|
23
23
|
<p><%= Spree.t(:you_have_no_favorite_products_yet) %></p>
|
24
24
|
<% end %>
|
25
|
-
|
26
|
-
<%= paginate @favorite_products %>
|
27
25
|
</div>
|
data/config/locales/en.yml
CHANGED
@@ -11,7 +11,12 @@ 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 => {:permalink => 'permalink'})
|
15
|
+
send_request
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets readonly to false" do
|
19
|
+
@current_user_favorites.should_receive(:readonly).with(false)
|
15
20
|
send_request
|
16
21
|
end
|
17
22
|
|
@@ -79,15 +84,12 @@ describe Spree::FavoriteProductsController do
|
|
79
84
|
|
80
85
|
describe 'GET index' do
|
81
86
|
def send_request
|
82
|
-
get :index, :
|
87
|
+
get :index, :use_route => 'spree'
|
83
88
|
end
|
84
89
|
|
85
90
|
before(:each) do
|
86
|
-
@
|
87
|
-
@
|
88
|
-
@favorite_products.stub(:per).and_return(@favorite_products)
|
89
|
-
Spree::Config.stub(:favorite_products_per_page).and_return('favorite_products_per_page')
|
90
|
-
@user = mock_model(Spree::User, :favorite_products => @favorite_products, :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
|
91
|
+
@favorite_product = mock_model(Spree::Product)
|
92
|
+
@user = mock_model(Spree::User, :favorite_products => [@favorite_product], :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
|
91
93
|
controller.stub(:authenticate_spree_user!).and_return(true)
|
92
94
|
controller.stub(:spree_current_user).and_return(@user)
|
93
95
|
end
|
@@ -104,17 +106,7 @@ describe Spree::FavoriteProductsController do
|
|
104
106
|
|
105
107
|
it "assigns @favorite_products" do
|
106
108
|
send_request
|
107
|
-
assigns(:favorite_products).should eq(@
|
108
|
-
end
|
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
|
109
|
+
assigns(:favorite_products).should eq([@favorite_product])
|
118
110
|
end
|
119
111
|
end
|
120
112
|
|
@@ -127,6 +119,7 @@ describe Spree::FavoriteProductsController do
|
|
127
119
|
@favorite = mock_model(Spree::Favorite)
|
128
120
|
@current_user_favorites = double('spree_favorites')
|
129
121
|
@current_user_favorites.stub(:where).and_return([@favorite])
|
122
|
+
@current_user_favorites.stub(:readonly).and_return(@current_user_favorites)
|
130
123
|
@favorites = double('spree_favorites')
|
131
124
|
@favorites.stub(:joins).with(:product).and_return(@current_user_favorites)
|
132
125
|
@user = mock_model(Spree::User, :favorites => @favorites, :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::Favorite do
|
4
|
-
it { should allow_mass_assignment_of :product_id }
|
5
4
|
it { should belong_to(:product) }
|
6
5
|
it { should belong_to(:user) }
|
7
6
|
it { should validate_uniqueness_of(:product_id).scoped_to(:user_id).with_message("already marked as favorite") }
|
@@ -1,28 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::User do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@user = Spree::User.create! :email => 'test@example.com', :password => 'spree123'
|
7
|
-
@product1 = Spree::Product.create! :name => 'product1', :price => 100, :shipping_category_id => 1
|
8
|
-
@product2 = Spree::Product.create! :name => 'product2', :price => 100, :shipping_category_id => 1
|
9
|
-
favorite = Spree::Favorite.new
|
10
|
-
favorite.product_id = @product1.id
|
11
|
-
favorite.user_id = @user.id
|
12
|
-
favorite.save!
|
13
|
-
end
|
14
|
-
|
15
4
|
it { should have_many(:favorites) }
|
16
5
|
it { should have_many(:favorite_products).through(:favorites).class_name('Spree::Product') }
|
17
|
-
|
18
|
-
|
19
|
-
describe "has_favorite_product?" do
|
20
|
-
context "when product in user's favorite products" do
|
21
|
-
it { @user.has_favorite_product?(@product1.id).should be_true }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when product is not in users favorite products' do
|
25
|
-
it { @user.has_favorite_product?(@product2.id).should be_false }
|
26
|
-
end
|
27
|
-
end
|
28
6
|
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 = '
|
5
|
+
s.version = '2.0.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.0
|
20
|
+
s.add_dependency 'spree_core', '~> 2.1.0'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,47 +1,40 @@
|
|
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
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mohit Bansal
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: spree_core
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 0
|
32
|
-
- 3
|
33
|
-
version: 2.0.3
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.1.0
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.0
|
30
|
+
description: ! 'This extension adds the following features: 1. Adds a link Mark as
|
31
|
+
favorite on product detail page. 2. Favorite Products tab on header 3. Favorite
|
32
|
+
Products tab in admin section'
|
37
33
|
email: info@vinsol.com
|
38
34
|
executables: []
|
39
|
-
|
40
35
|
extensions: []
|
41
|
-
|
42
36
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
37
|
+
files:
|
45
38
|
- .rspec
|
46
39
|
- .travis.yml
|
47
40
|
- Gemfile
|
@@ -56,12 +49,10 @@ files:
|
|
56
49
|
- app/assets/stylesheets/store/spree_favorite_products.css
|
57
50
|
- app/controllers/spree/admin/favorite_products_controller.rb
|
58
51
|
- app/controllers/spree/favorite_products_controller.rb
|
59
|
-
- app/models/spree/app_configuration_decorator.rb
|
60
52
|
- app/models/spree/favorite.rb
|
61
53
|
- app/models/spree/product_decorator.rb
|
62
54
|
- app/models/spree/user_decorator.rb
|
63
55
|
- app/overrides/.DS_Store
|
64
|
-
- app/overrides/add_favorite_products_per_page_configuration.rb
|
65
56
|
- app/overrides/add_favorite_products_tab.rb
|
66
57
|
- app/overrides/add_link_to_mark_product_as_favorite.rb
|
67
58
|
- app/overrides/add_link_to_users_favorite_products.rb
|
@@ -82,46 +73,35 @@ files:
|
|
82
73
|
- script/rails
|
83
74
|
- spec/controllers/spree/admin/favorite_products_controller_spec.rb
|
84
75
|
- spec/controllers/spree/favorite_products_controller_spec.rb
|
85
|
-
- spec/models/spree/app_configuration_decorator_spec.rb
|
86
76
|
- spec/models/spree/favorite_spec.rb
|
87
77
|
- spec/models/spree/product_decorator_spec.rb
|
88
78
|
- spec/models/spree/user_decorator_spec.rb
|
89
79
|
- spec/spec_helper.rb
|
90
80
|
- spree_favorite_products.gemspec
|
91
81
|
homepage: http://vinsol.com
|
92
|
-
licenses:
|
82
|
+
licenses:
|
93
83
|
- MIT
|
94
84
|
post_install_message:
|
95
85
|
rdoc_options: []
|
96
|
-
|
97
|
-
require_paths:
|
86
|
+
require_paths:
|
98
87
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
89
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
hash: 53
|
105
|
-
segments:
|
106
|
-
- 1
|
107
|
-
- 9
|
108
|
-
- 3
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
109
93
|
version: 1.9.3
|
110
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
95
|
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
|
117
|
-
- 0
|
118
|
-
version: "0"
|
119
|
-
requirements:
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements:
|
120
101
|
- none
|
121
102
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.25
|
123
104
|
signing_key:
|
124
105
|
specification_version: 3
|
125
106
|
summary: users can mark product as favorite
|
126
107
|
test_files: []
|
127
|
-
|
@@ -1,16 +0,0 @@
|
|
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
|
-
)
|