Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: refactor!: dependencies and decorators and bumped spree upper v… #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .generators
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Reorder generators
2. Remove generators
3. Add installed generators
To add new installed generators automatically delete this file and reload the project.
--><GeneratorsGroup><Generator name="controller" /><Generator name="integration_test" /><Generator name="mailer" /><Generator name="migration" /><Generator name="model" /><Generator name="observer" /><Generator name="plugin" /><Generator name="resource" /><Generator name="scaffold" /><Generator name="session_migration" /></GeneratorsGroup></Settings>
7 changes: 7 additions & 0 deletions .rakeTasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Remove rake task
2. Add existing rake tasks
To add existing rake tasks automatically delete this file and reload the project.
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
1 change: 0 additions & 1 deletion app/assets/javascripts/spree/frontend/spree_reviews.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//= require jquery.rating
//= require spree/frontend
//= require spree/frontend/spree_auth

// Navigating to a page with ratings via TurboLinks shows the radio buttons
$(document).on('page:load', function () {
Expand Down
24 changes: 16 additions & 8 deletions app/controllers/spree/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
Spree::ProductsController.class_eval do
helper Spree::ReviewsHelper

reviews_fields = [:avg_rating, :reviews_count]
reviews_fields.each { |attrib| Spree::PermittedAttributes.product_attributes << attrib }

Spree::Api::ApiHelpers.class_eval do
reviews_fields.each { |attrib| class_variable_set(:@@product_attributes, class_variable_get(:@@product_attributes).push(attrib)) }
module Spree::ProductsControllerDecorator
extend ActiveSupport::Concern
included do
helper Spree::ReviewsHelper

reviews_fields = [:avg_rating, :reviews_count]
reviews_fields.each { |attrib| Spree::PermittedAttributes.product_attributes << attrib }

Spree::Api::ApiHelpers.class_eval do
reviews_fields.each { |attrib| class_variable_set(:@@product_attributes, class_variable_get(:@@product_attributes).push(attrib)) }
end
end
end

if ::Spree::ProductsController.included_modules.exclude?(Spree::ProductsControllerDecorator)
::Spree::ProductsController.prepend Spree::ProductsControllerDecorator
end

2 changes: 2 additions & 0 deletions app/models/spree/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ def recalculate_rating
save
end
end

module Spree::ProductDecorator; end
9 changes: 8 additions & 1 deletion db/sample/reviews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ r1:
title: "more uses for this item"
review: <%= Faker::Lorem.paragraph %>
approved: true
show_identifier: true
r2:
product: ror_tote
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
Expand All @@ -17,6 +18,7 @@ r2:
title: "further comments"
review: <%= Faker::Lorem.paragraph %>
approved: false
show_identifier: true
r3:
product: ror_ringer
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
Expand All @@ -25,6 +27,7 @@ r3:
title: "essential wear"
review: <%= Faker::Lorem.paragraph %>
approved: false
show_identifier: true
r4:
product: apache_baseball_jersey
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
Expand All @@ -33,6 +36,7 @@ r4:
title: "not impressed"
review: <%= Faker::Lorem.paragraph %>
approved: true
show_identifier: true
r5:
product: ror_ringer
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
Expand All @@ -41,6 +45,7 @@ r5:
title: "I have one for every day of the week"
review: <%= Faker::Lorem.paragraph %>
approved: true
show_identifier: true
r6:
product: ror_ringer
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
Expand All @@ -49,11 +54,13 @@ r6:
title: "cooler than my toga"
review: <%= Faker::Lorem.paragraph %>
approved: true
show_identifier: true
r7:
product: ror_ringer
name: <%= Faker::Name.first_name %> <%= Faker::Name.last_name %>
location: emerald city
rating: 2
title: "my other half didn't like it"
review: <%= Faker::Lorem.paragraph %>
approved: false
approved: false
show_identifier: true
1 change: 1 addition & 0 deletions lib/spree_reviews.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'spree_extension'
require 'coffee_script'
require 'sass/rails'
require 'deface'

module Spree
module Reviews
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/feedback_review_factory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :feedback_review, class: Spree::FeedbackReview do
user
review
Expand Down
10 changes: 5 additions & 5 deletions spec/factories/review_factory.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FactoryGirl.define do
FactoryBot.define do
factory :review, class: Spree::Review do
name { generate(:random_email) }
title { generate(:random_string) }
review { generate(:random_description) }
rating { rand(1..5) }
approved false
show_identifier true
approved { false }
show_identifier { true }
user
product

trait :approved do
approved true
approved { true }
end

trait :hide_identifier do
show_identifier false
show_identifier { false }
end
end
end
7 changes: 7 additions & 0 deletions spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'factory_bot'

FactoryBot.find_definitions

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
7 changes: 0 additions & 7 deletions spec/support/factory_girl.rb

This file was deleted.

5 changes: 3 additions & 2 deletions spree_reviews.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

spree_version = '>= 3.1.0', '< 4.0'
spree_version = '>= 3.1.0', '< 5.0'
s.add_runtime_dependency 'spree_core', spree_version
s.add_runtime_dependency 'spree_auth_devise', spree_version
s.add_runtime_dependency 'spree_extension'
Expand All @@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'poltergeist'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'factory_girl'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'coffee-rails'
Expand All @@ -43,4 +43,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'appraisal'
s.add_development_dependency 'pg'
s.add_development_dependency 'mysql2'
s.add_dependency 'deface'
end