Hot questions for Using Spree in solidus

Question:

So Solidus is a fork of Spree and Spree is no longer maintained. Am following the instructions on the Solidus's Github page (https://github.com/solidusio/solidus) to install it. And am stuck at this command bundle exec rails g spree:install this command raises the following error:

/Users/user1/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/handlebars_assets-0.19.1/lib/handlebars_assets.rb:20:in 'block in register_extensions': undefined method 'register_engine' for nil:NilClass (NoMethodError)

Not sure if this might help but before trying to install Solidus I was working on a Spree project.

Also, here is my Gemfile:

  source 'https://rubygems.org'
  # Solidus E-Commerce
  gem 'solidus'
  gem 'solidus_auth_devise'

  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.2.4'
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
  # Use SCSS for stylesheets
  gem 'sass-rails', '~> 5.0'
  # Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '>= 1.3.0'
  # Use CoffeeScript for .coffee assets and views
  gem 'coffee-rails', '~> 4.1.0'
  # See https://github.com/rails/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby

  # Use jquery as the JavaScript library
  gem 'jquery-rails'
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
  gem 'turbolinks'
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
  gem 'jbuilder', '~> 2.0'
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', '~> 0.4.0', group: :doc

  # Use ActiveModel has_secure_password
  # gem 'bcrypt', '~> 3.1.7'

  # Use Unicorn as the app server
  # gem 'unicorn'

  # Use Capistrano for deployment
  # gem 'capistrano-rails', group: :development

  group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug'
  end

  group :development do
    # Access an IRB console on exception pages or by using <%= console %> in views
    gem 'web-console', '~> 2.0'

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    gem 'spring'
  end

Any help is really appreciated.


Answer:

Update:

This is a known bug with handlebars-assets gem, which is resolved in master.

Adding the line :

gem 'handlebars_assets', github: 'leshill/handlebars_assets'

to your Gemfile will solve your problem until a new version contains the relevant fix.


Move the lines :

gem 'solidus'
gem 'solidus_auth_devise'

below gem 'rails', '4.2.4' because the former depends on the latter.

Question:

I use Rails 4 and Solidus 1.2 How does one format the price to have a currency symbol with a space before the number like "€ 99"?

Spree/Solidus use Ruby Money Gem to handle currencies and I see in https://github.com/RubyMoney/money/blob/master/lib/money/money/formatting.rb that there is a config option

Spree::Money.default_formatting_rules[:symbol_before_without_space] = true 

but no Spree::Money.default_formatting_rules[:symbol_before_with_space] = true

In my initializer:

# config/initializers/spree.rb

Money::Currency.register({
  :priority        => 1,
  :iso_code        => "EUR",
  :iso_numeric     => "978",
  :name            => "Euro",
  :symbol          => "€",
  :subunit         => "Cent",
  :subunit_to_unit => 100,
  :separator       => ".",
  :delimiter       => ","
})

And I tried also to format within my localization files like in de.yml:

---
de:
  number:
    currency:
      format: "%u %n"

But the price format is still "104,90 €" instead of "€ 104,90".

I don't want to do String Interpolation to format the currency. Is there an config option that I'm missing?


Answer:

ok, it's embarrassing but i just had to set

Spree::Money.default_formatting_rules[:symbol_before_without_space] = false

to get my desired format.

Question:

I am trying to add login/logout/sign up links to the front page of a solidus app. In the _login_bar_items partial I put this:

 <% if spree_current_user %>
 <li>
     <%= link_to "Logout", destroy_spree_user_session_path, method: :delete %>
   </li>
 <% else %>
   <li>
     <%= link_to "Login", new_spree_user_session_path %>
   </li>
   <li>
     <%= link_to "Register", new_spree_user_registration_path %>
   </li>
 <% end %>

And I get the error

No route matches [DELETE] "/user/spree_user/logout"

when I click on logout button. The paths are as displayed when I run rails routes.

I also tried if current_user but that didn't work either.

Any suggestions are appreciated.

Edit: Rails Routes output:

  Prefix Verb URI Pattern                                                                                    Controller#Action
                spree      /                                                                                        Spree::Core::Engine
   rails_service_blob GET  /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
  rails_blob_representation GET  /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format)             active_storage/representations#show
   rails_disk_service GET  /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
  update_rails_disk_service PUT  /rails/active_storage/disk/:encoded_token(.:format)                                                              active_storage/disk#update
       rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

  Routes for Spree::Core::Engine:
                                 new_spree_user_session GET    /user/spree_user/sign_in(.:format)                                                                       spree/user_sessions#new
                                     spree_user_session POST   /user/spree_user/sign_in(.:format)                                                                 spree/user_sessions#create
                             destroy_spree_user_session GET    /user/spree_user/logout(.:format)                                                                  spree/user_sessions#destroy
                                new_spree_user_password GET    /user/spree_user/password/new(.:format)                                                            spree/user_passwords#new
                               edit_spree_user_password GET    /user/spree_user/password/edit(.:format)                                                           spree/user_passwords#edit
                                    spree_user_password PATCH  /user/spree_user/password(.:format)                                                                spree/user_passwords#update
                                                        PUT    /user/spree_user/password(.:format)                                                                spree/user_passwords#update
                                                        POST   /user/spree_user/password(.:format)                                                                spree/user_passwords#create
                         cancel_spree_user_registration GET    /user/spree_user/cancel(.:format)                                                                  spree/user_registrations#cancel
                            new_spree_user_registration GET    /user/spree_user/sign_up(.:format)                                                                 spree/user_registrations#new
                           edit_spree_user_registration GET    /user/spree_user/edit(.:format)                                                                    spree/user_registrations#edit
                                spree_user_registration PATCH  /user/spree_user(.:format)                                                                         spree/user_registrations#update
                                                        PUT    /user/spree_user(.:format)                                                                         spree/user_registrations#update
                                                        DELETE /user/spree_user(.:format)                                                                         spree/user_registrations#destroy
                                                        POST   /user/spree_user(.:format)                                                                         spree/user_registrations#create
                            new_spree_user_confirmation GET    /user/spree_user/confirmation/new(.:format)                                                        spree/user_confirmations#new
                                spree_user_confirmation GET    /user/spree_user/confirmation(.:format)                                                            spree/user_confirmations#show
                                                        POST   /user/spree_user/confirmation(.:format)                                                            spree/user_confirmations#create
                                              edit_user GET    /users/:id/edit(.:format)                                                                          spree/users#edit
                                                   user PATCH  /users/:id(.:format)                                                                               spree/users#update
                                                        PUT    /users/:id(.:format)                                                                               spree/users#update
                                                  login GET    /login(.:format)                                                                                   spree/user_sessions#new
                                     create_new_session POST   /login(.:format)                                                                                   spree/user_sessions#create
                                                 logout GET    /logout(.:format)                                                                                  spree/user_sessions#destroy
                                                 signup GET    /signup(.:format)                                                                                  spree/user_registrations#new
                                           registration POST   /signup(.:format)                                                                                  spree/user_registrations#create
                                       recover_password GET    /password/recover(.:format)                                                                        spree/user_passwords#new
                                         reset_password POST   /password/recover(.:format)                                                                        spree/user_passwords#create
                                          edit_password GET    /password/change(.:format)                                                                         spree/user_passwords#edit
                                        update_password PUT    /password/change(.:format)                                                                         spree/user_passwords#update
                                           confirmation GET    /confirm(.:format)                                                                                 spree/user_confirmations#show
                                  checkout_registration GET    /checkout/registration(.:format)                                                                   spree/checkout#registration
                           update_checkout_registration PUT    /checkout/registration(.:format)                                                                   spree/checkout#update_registration
                                            new_account GET    /account/new(.:format)                                                                             spree/users#new
                                           edit_account GET    /account/edit(.:format)                                                                            spree/users#edit
                                                account GET    /account(.:format)                                                                                 spree/users#show
                                                        PATCH  /account(.:format)                                                                                 spree/users#update
                                                        PUT    /account(.:format)                                                                                 spree/users#update
                                                        DELETE /account(.:format)                                                                                 spree/users#destroy
                                                        POST   /account(.:format)                                                                                 spree/users#create
                                     admin_unauthorized GET    /admin/authorization_failure(.:format)                                                             spree/admin/user_sessions#authorization_failure
                                            admin_login GET    /admin/login(.:format)                                                                             spree/admin/user_sessions#new
                               admin_create_new_session POST   /admin/login(.:format)                                                                             spree/admin/user_sessions#create
                                           admin_logout GET    /admin/logout(.:format)                                                                            spree/admin/user_sessions#destroy
                                 admin_recover_password GET    /admin/password/recover(.:format)                                                                  spree/admin/user_passwords#new
                                   admin_reset_password POST   /admin/password/recover(.:format)                                                                  spree/admin/user_passwords#create
                                    admin_edit_password GET    /admin/password/change(.:format)                                                                   spree/admin/user_passwords#edit
                                  admin_update_password PUT    /admin/password/change(.:format)                                                                   spree/admin/user_passwords#update
                                                   root GET    /                                                                                                  spree/home#index
                                               products GET    /products(.:format)                                                                                spree/products#index
                                                product GET    /products/:id(.:format)                                                                            spree/products#show
                                             locale_set GET    /locale/set(.:format)                                                                              spree/locale#set
                                          select_locale POST   /locale/set(.:format)                                                                              spree/locale#set
                                        update_checkout PATCH  /checkout/update/:state(.:format)                                                                  spree/checkout#update
                                         checkout_state GET    /checkout/:state(.:format)                                                                         spree/checkout#edit
                                               checkout GET    /checkout(.:format)                                                                                spree/checkout#edit
                                        orders_populate GET    /orders/populate(.:format)                                                                         spree/orders#populate_redirect
                                            token_order GET    /orders/:id/token/:token(.:format)                                                                 spree/orders#show
                                        populate_orders POST   /orders/populate(.:format)                                                                         spree/orders#populate
                                             edit_order GET    /orders/:id/edit(.:format)                                                                         spree/orders#edit
                                                  order GET    /orders/:id(.:format)                                                                              spree/orders#show
                                                        PATCH  /orders/:id(.:format)                                                                              spree/orders#update
                                                        PUT    /orders/:id(.:format)                                                                              spree/orders#update
                                                   cart GET    /cart(.:format)                                                                                    spree/orders#edit
                                            update_cart PATCH  /cart(.:format)                                                                                    spree/orders#update
                                             empty_cart PUT    /cart/empty(.:format)                                                                              spree/orders#empty
                                          nested_taxons GET    /t/*id(.:format)                                                                                   spree/taxons#show
                                           unauthorized GET    /unauthorized(.:format)                                                                            spree/home#unauthorized
                                                    cvv GET    /content/cvv(.:format)                                                                             spree/content#cvv
                                              cart_link GET    /cart_link(.:format)                                                                               spree/store#cart_link
                                     admin_search_users GET    /admin/search/users(.:format)                                                                      spree/admin/search#users
                                  admin_search_products GET    /admin/search/products(.:format)                                                                   spree/admin/search#products
                                       admin_set_locale PUT    /admin/locale/set(.:format)                                                                        spree/admin/locale#set {:format=>:json}
                                  home_admin_dashboards GET    /admin/dashboards/home(.:format)                                                                   spree/admin/dashboards#home
                        admin_promotion_promotion_rules GET    /admin/promotions/:promotion_id/promotion_rules(.:format)                                          spree/admin/promotion_rules#index
                                                        POST   /admin/promotions/:promotion_id/promotion_rules(.:format)                                          spree/admin/promotion_rules#create
                     new_admin_promotion_promotion_rule GET    /admin/promotions/:promotion_id/promotion_rules/new(.:format)                                      spree/admin/promotion_rules#new
                    edit_admin_promotion_promotion_rule GET    /admin/promotions/:promotion_id/promotion_rules/:id/edit(.:format)                                 spree/admin/promotion_rules#edit
                         admin_promotion_promotion_rule GET    /admin/promotions/:promotion_id/promotion_rules/:id(.:format)                                      spree/admin/promotion_rules#show
                                                        PATCH  /admin/promotions/:promotion_id/promotion_rules/:id(.:format)                                      spree/admin/promotion_rules#update
                                                        PUT    /admin/promotions/:promotion_id/promotion_rules/:id(.:format)                                      spree/admin/promotion_rules#update
                                                        DELETE /admin/promotions/:promotion_id/promotion_rules/:id(.:format)                                      spree/admin/promotion_rules#destroy
                      admin_promotion_promotion_actions GET    /admin/promotions/:promotion_id/promotion_actions(.:format)                                        spree/admin/promotion_actions#index
                                                        POST   /admin/promotions/:promotion_id/promotion_actions(.:format)                                        spree/admin/promotion_actions#create
                   new_admin_promotion_promotion_action GET    /admin/promotions/:promotion_id/promotion_actions/new(.:format)                                    spree/admin/promotion_actions#new
                  edit_admin_promotion_promotion_action GET    /admin/promotions/:promotion_id/promotion_actions/:id/edit(.:format)                               spree/admin/promotion_actions#edit
                       admin_promotion_promotion_action GET    /admin/promotions/:promotion_id/promotion_actions/:id(.:format)                                    spree/admin/promotion_actions#show
                                                        PATCH  /admin/promotions/:promotion_id/promotion_actions/:id(.:format)                                    spree/admin/promotion_actions#update
                                                        PUT    /admin/promotions/:promotion_id/promotion_actions/:id(.:format)                                    spree/admin/promotion_actions#update
                                                        DELETE /admin/promotions/:promotion_id/promotion_actions/:id(.:format)                                    spree/admin/promotion_actions#destroy
                        admin_promotion_promotion_codes GET    /admin/promotions/:promotion_id/promotion_codes(.:format)                                          spree/admin/promotion_codes#index
          admin_promotion_promotion_code_batch_download GET    /admin/promotions/:promotion_id/promotion_code_batches/:promotion_code_batch_id/download(.:format) spree/admin/promotion_code_batches#download {:format=>"csv"}
                 admin_promotion_promotion_code_batches GET    /admin/promotions/:promotion_id/promotion_code_batches(.:format)                                   spree/admin/promotion_code_batches#index
                                                        POST   /admin/promotions/:promotion_id/promotion_code_batches(.:format)                                   spree/admin/promotion_code_batches#create
               new_admin_promotion_promotion_code_batch GET    /admin/promotions/:promotion_id/promotion_code_batches/new(.:format)                               spree/admin/promotion_code_batches#new
                                       admin_promotions GET    /admin/promotions(.:format)                                                                        spree/admin/promotions#index
                                                        POST   /admin/promotions(.:format)                                                                        spree/admin/promotions#create
                                    new_admin_promotion GET    /admin/promotions/new(.:format)                                                                    spree/admin/promotions#new
                                   edit_admin_promotion GET    /admin/promotions/:id/edit(.:format)                                                               spree/admin/promotions#edit
                                        admin_promotion GET    /admin/promotions/:id(.:format)                                                                    spree/admin/promotions#show
                                                        PATCH  /admin/promotions/:id(.:format)                                                                    spree/admin/promotions#update
                                                        PUT    /admin/promotions/:id(.:format)                                                                    spree/admin/promotions#update
                                                        DELETE /admin/promotions/:id(.:format)                                                                    spree/admin/promotions#destroy
                             admin_promotion_categories GET    /admin/promotion_categories(.:format)                                                              spree/admin/promotion_categories#index
                                                        POST   /admin/promotion_categories(.:format)                                                              spree/admin/promotion_categories#create
                           new_admin_promotion_category GET    /admin/promotion_categories/new(.:format)                                                          spree/admin/promotion_categories#new
                          edit_admin_promotion_category GET    /admin/promotion_categories/:id/edit(.:format)                                                     spree/admin/promotion_categories#edit
                               admin_promotion_category PATCH  /admin/promotion_categories/:id(.:format)                                                          spree/admin/promotion_categories#update
                                                        PUT    /admin/promotion_categories/:id(.:format)                                                          spree/admin/promotion_categories#update
                                                        DELETE /admin/promotion_categories/:id(.:format)                                                          spree/admin/promotion_categories#destroy
                                            admin_zones GET    /admin/zones(.:format)                                                                             spree/admin/zones#index
                                                        POST   /admin/zones(.:format)                                                                             spree/admin/zones#create
                                         new_admin_zone GET    /admin/zones/new(.:format)                                                                         spree/admin/zones#new
                                        edit_admin_zone GET    /admin/zones/:id/edit(.:format)                                                                    spree/admin/zones#edit
                                             admin_zone GET    /admin/zones/:id(.:format)                                                                         spree/admin/zones#show
                                                        PATCH  /admin/zones/:id(.:format)                                                                         spree/admin/zones#update
                                                        PUT    /admin/zones/:id(.:format)                                                                         spree/admin/zones#update
                                                        DELETE /admin/zones/:id(.:format)                                                                         spree/admin/zones#destroy
                                   admin_tax_categories GET    /admin/tax_categories(.:format)                                                                    spree/admin/tax_categories#index
                                                        POST   /admin/tax_categories(.:format)                                                                    spree/admin/tax_categories#create
                                 new_admin_tax_category GET    /admin/tax_categories/new(.:format)                                                                spree/admin/tax_categories#new
                                edit_admin_tax_category GET    /admin/tax_categories/:id/edit(.:format)                                                           spree/admin/tax_categories#edit
                                     admin_tax_category GET    /admin/tax_categories/:id(.:format)                                                                spree/admin/tax_categories#show
                                                        PATCH  /admin/tax_categories/:id(.:format)                                                                spree/admin/tax_categories#update
                                                        PUT    /admin/tax_categories/:id(.:format)                                                                spree/admin/tax_categories#update

Answer:

Try with

<%= link_to "Logout", destroy_spree_user_session_path %>

because your "/user/spree_user/logout" is not defined as DELETE request but as GET request route.

Question:

I have an integration/feature spec in my Spree Rails app that already VCR records the final payment request. However, I can notice still the external call to Braintree to calculate the client token.

I looked in the docs and I did not see a test object that I could use when it generates the token.

Is it possible to either have a test object that will provide a test Braintree client token? Or is it just better to VCR record that initial request?


Answer:

I found that when it came to integration tests, using VCR does record and prevent the external call to braintree.

I do with the gem did somehow logs that the request was never actually made externally when using VCR.

Question:

I'm trying to change the homepage product listing. So i'm trying to override the file in this path:

https://github.com/solidusio/solidus/blob/master/frontend/app/views/spree/shared/_products.html.erb

Deface::Override.new(:virtual_path => 'spree/shared/products',
                 :replace_contents => "li#product_",
                 :name => "product_new",
                 :text => "text")

However this code makes absolutely 0 change on the homepage.

The file in which this override is in is called product_override.rb and is in app/overrides

Any help would be appreciated. Thanks


Answer:

I have tested this code with a fresh install of Solidus and it worked. Note that I have added an underscore before "products" in :virtual_path => 'spree/shared/_products'. Also, I changed the selector to "li".

Deface::Override.new(:virtual_path => 'spree/shared/_products',
             :insert_after => "li",
             :name => "product_new",
             :text => "Override is working")

Question:

I'm using Solidus/Spree.

Normally when you use variables from the controller, you use instance variables that start with an @.

In my views, I have seen the use of current_spree_user which is not an instance variable, but it does work. I don't see this local variable 'current_spree_user' being assigned somewhere in my view.

Anybody knows how it is possible that current_spree_user is an valid variable within a view?


Answer:

It's not an controller instance variable, but controller helper method : https://github.com/spree/spree_auth_devise/blob/master/lib/spree/authentication_helpers.rb

Question:

I have built a module in Solidus and ruby on rails and now I try to create tests.

I am trying to create some integration tests and I have this error:

E Error: PrescriptionPhotosTest#test_/prescription_photos_post_endpoint_throws_an_error_when_wrong_params: ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true test/integration/prescription_photos_test.rb:6:in `block in '

I read this this and this, but it doesn't make any difference.

My code is returning this error on this line:

@user = FactoryGirl.create(:user)

Here is the code from my files.

prescription_photos_rest.rb

require 'test_helper'

class PrescriptionPhotosTest < ActionDispatch::IntegrationTest
  setup do
    Spree::Auth::Config[:confirmable] = false
    @user = FactoryGirl.create(:user)
  end

  def authenticated_header
    token = Knock::AuthToken.new(payload: { sub: @user.id }).token
    {
        'Authorization': "Bearer #{token}"
    }
  end

  test '/prescription_photos post endpoint throws an error when wrong params' do
     post '/api/prescription_photos', headers: authenticated_header, params: {
       something: {
           is: 'wrong'
       }
     }

    json = JSON.parse(body)

     assert_response 422
     assert json.has_key? 'exception'
     assert_equal 'param is missing or the value is empty: prescription', json['exception']
  end
end

factories.rb

FactoryGirl.define do
  factory :user, class: Spree::User do
    email 'test@test.nl'
    password 'test123'
    password_confirmation 'test123'
  end
end

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all
  # Add more helper methods to be used by all tests here...
end

test.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.
  config.action_controller.default_url_options = { host: 'localhost', port: 3000 }

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Do not eager load code on boot. This avoids loading your whole application
  # just for the purpose of running a single test. If you are using a tool that
  # preloads Rails for running tests, you may have to set it to true.
  config.eager_load = false

  # Configure public file server for tests with Cache-Control for performance.
  config.public_file_server.enabled = true
  config.public_file_server.headers = {
    'Cache-Control' => 'public, max-age=3600'
  }

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates.
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment.
  config.action_controller.allow_forgery_protection = false
  config.action_mailer.perform_caching = false

  # Add the host parameter
  config.action_mailer.default_url_options = { host: 'localhost' }

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

After running rake test:integration I got the error mentioned above.

I did a lot of googleing and I tried to fix this problem in the past 2 days, but I had no luck.


Answer:

Spree::Auth::Config[:confirmable] = false

This line of code from prescription_photos_rest.rb was overwritten buy a env value.