spree-contrib / spree_drop_ship

Spree Drop Shipping Extension
BSD 3-Clause "New" or "Revised" License
104 stars 120 forks source link

Error: email is invalid #49

Closed james075 closed 10 years ago

james075 commented 10 years ago

On become a supplier I got this error:

screen shot 2014-10-01 at 11 44 34 am

Same when I want to create one from the admin back-end:

screen shot 2014-10-01 at 11 44 43 am

Note: I performed the install in this order and migrated on each step without any error:

1- rails g spree:install 2- rails g spree_drop_ship:install 3- rails g spree_marketplace:install

Here you can find schema.rb file

Gemfile:

gem 'spree', '2.3.2'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-3-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-3-stable'

gem 'spree_drop_ship', github: 'jdutil/spree_drop_ship', :branch => "2-3-stable"
gem 'spree_marketplace', github: 'jdutil/spree_marketplace'

Console logs:

Started POST "/admin/suppliers" for 127.0.0.1 at 2014-10-01 11:37:02 +0200
  ActiveRecord::SchemaMigration Load (0.3ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Spree::Admin::SuppliersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"LzPbQL6zxs5Hvbv6b+Pmzy/hkk5yZtpjngQ/0WgYDh0=", "supplier"=>{"address_attributes"=>{"firstname"=>"test", "lastname"=>"test", "address1"=>"22 test street", "address2"=>"", "city"=>"test", "zipcode"=>"91070", "country_id"=>"13", "state_name"=>"", "phone"=>"+33762771604"}, "name"=>"test test test", "email"=>"test@test.com", "url"=>"http://test.com", "tax_id"=>"123456789", "commission_flat_rate"=>"0.0", "commission_percentage"=>"0.0", "user_ids_string"=>"2", "active"=>"1"}, "button"=>""}
  Spree::Preference Load (0.1ms)  SELECT  "spree_preferences".* FROM "spree_preferences"  WHERE "spree_preferences"."key" = 'spree/backend_configuration/locale' LIMIT 1
  Spree::User Load (0.2ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."id" = 1  ORDER BY "spree_users"."id" ASC LIMIT 1
   (0.2ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = ? AND "spree_roles"."name" = 'admin'  [["user_id", 1]]
  Spree::User Load (0.2ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."id" = ? LIMIT 1  [["id", 2]]
   (0.1ms)  begin transaction
  Spree::Supplier Exists (0.1ms)  SELECT  1 AS one FROM "spree_suppliers"  WHERE ("spree_suppliers"."id" IS NOT NULL) AND "spree_suppliers"."slug" = 'test-test-test' LIMIT 1
  Spree::Country Load (0.1ms)  SELECT  "spree_countries".* FROM "spree_countries"  WHERE "spree_countries"."id" = ? LIMIT 1  [["id", 13]]
  Spree::Supplier Exists (0.1ms)  SELECT  1 AS one FROM "spree_suppliers"  WHERE "spree_suppliers"."email" = 'test@test.com' LIMIT 1
  Spree::Supplier Exists (0.1ms)  SELECT  1 AS one FROM "spree_suppliers"  WHERE "spree_suppliers"."name" = 'test test test' LIMIT 1
   (0.1ms)  rollback transaction
Deface: 1 overrides found for 'spree/layouts/admin'
Deface: 'add_stripe_js_to_head' matched 1 times with 'head'
Deface: [WARNING] No :original defined for 'add_stripe_js_to_head', you should change its definition to include:
 :original => 'defeb3149100cd8006fdbb70c8fcc36bc70b8fe3' 
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_core-2.3.2/app/views/spree/shared/_error_messages.html.erb (1.4ms)
  Spree::Preference Load (0.2ms)  SELECT  "spree_preferences".* FROM "spree_preferences"  WHERE "spree_preferences"."key" = 'spree/app_configuration/checkout_zone' LIMIT 1
  Spree::Zone Load (0.1ms)  SELECT  "spree_zones".* FROM "spree_zones"  WHERE "spree_zones"."name" IS NULL LIMIT 1
  Spree::Country Load (0.8ms)  SELECT "spree_countries".* FROM "spree_countries"
  Spree::State Exists (0.2ms)  SELECT  1 AS one FROM "spree_states"  WHERE "spree_states"."country_id" = ? LIMIT 1  [["country_id", 13]]
  CACHE (0.0ms)  SELECT  1 AS one FROM "spree_states"  WHERE "spree_states"."country_id" = ? LIMIT 1  [["country_id", 13]]
  Spree::State Load (0.1ms)  SELECT "spree_states".* FROM "spree_states"  WHERE "spree_states"."country_id" = ?  ORDER BY name ASC  [["country_id", 13]]
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_backend-2.3.2/app/views/spree/admin/shared/_address_form.html.erb (81.2ms)
  CACHE (0.0ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = ? AND "spree_roles"."name" = 'admin'  [["user_id", 1]]
  Rendered /Users/james/.bundler/ruby/2.0.0/spree_drop_ship-2c28ff9f6b73/app/views/spree/admin/suppliers/_form.html.erb (118.2ms)
  Rendered /Users/james/.bundler/ruby/2.0.0/spree_drop_ship-2c28ff9f6b73/app/views/spree/admin/suppliers/new.html.erb within spree/layouts/admin (171.5ms)
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_backend-2.3.2/app/views/spree/admin/shared/_translations.html.erb (2.8ms)
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_backend-2.3.2/app/views/spree/admin/shared/_head.html.erb (1271.5ms)
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_backend-2.3.2/app/views/spree/admin/shared/_alert.html.erb (0.0ms)
Deface: 1 overrides found for 'spree/admin/shared/_header'
Deface: 'auth_admin_login_navigation_bar' matched 1 times with '[data-hook='admin_login_navigation_bar'], #admin_login_navigation_bar[data-hook]'
  Rendered /Users/james/.bundler/ruby/2.0.0/spree_auth_devise-8e5f91e3808e/lib/views/backend/spree/layouts/admin/_login_nav.html.erb (1.9ms)
  Rendered /Library/Ruby/Gems/2.0.0/gems/spree_backend-2.3.2/app/views/spree/admin/shared/_header.html.erb (19.4ms)
Deface: 2 overrides found for 'spree/admin/shared/_menu'
Deface: 'add_profile_admin_tabs' matched 1 times with '[data-hook='admin_tabs']'
Deface: [WARNING] No :original defined for 'add_profile_admin_tabs', you should change its definition to include:
 :original => 'b5619c4418a841e8d9c641226616c5268ec85f61' 
Deface: 'converted_admin_tabs' matched 1 times with '[data-hook='admin_tabs']'
Deface: [WARNING] No :original defined for 'converted_admin_tabs', you should change its definition to include:
 :original => '7066c44ed406b6c954aeee86df29233f0dc331e7' 
Deface: 1 overrides found for 'spree/admin/shared/_tabs'
Deface: 'remove_overview_tab' matched 0 times with 'erb[loud]:contains('overview')'
damson commented 10 years ago

Since it's related to the mail validation a possible fix could be to temporarly disable the uniqueness validator.

class Spree::Supplier < Spree::Base ..... validates :email, presence: true, email: true, uniqueness: true

to

class Spree::Supplier < Spree::Base ..... validates :email, presence: true, email: true

For an unknown reason, It seems that when checking records for an already existing supplier, user records are also considered.

JDutil commented 10 years ago

That's really odd I expected the error message to be the {email: true} option, and would have thought uniqueness would be a different message like it's already been taken.

This might be related, but it's frontend not backend create: https://github.com/JDutil/spree_marketplace/blob/master/app/controllers/spree/suppliers_controller.rb#L14-L23

ronzalo commented 10 years ago

Is this issue related with this: https://github.com/spree/spree/issues/5368 ?

JDutil commented 10 years ago

I was thinking that may be the case, but I've since fixed that issue. I would make sure you're running the latest commits of spree 2-3-stable and see if that helps resolve the problem. I haven't reproduced this error yet it.

damson commented 10 years ago

Actually, it was because of the use of a wrong version of spree. The issue is not present anymore using spree 2-3-stable. Maybe compatibility related. Thanks.