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

admin section doesn't work on clean install - I think because seeds.rb didn't execute #2112

Closed
marcamillion opened this Issue Oct 18, 2012 · 18 comments

Comments

Projects
None yet
4 participants
@marcamillion

marcamillion commented Oct 18, 2012

When it got to rake db:seed - in the intial setup - of a relatively new app (all I did was setup Devise, CanCan and a few other gems before setting up Spree) this is the message that returned:

rake  db:seed 
CREATING ROLES
SETTING UP DEFAULT USER LOGIN
rake aborted!
Validation failed: Email has already been taken

Tasks: TOP => db:seed
(See full trace by running task with --trace)
     loading  sample data

As a result of that, when I go to /admin in my Spree App, it just redirects to home and this is what I see in the log:

Started GET "/admin" for 127.0.0.1 at 2012-10-18 15:44:50 -0500
Processing by Spree::Admin::OverviewController#index as HTML
  Spree::Preference Exists (0.2ms)  SELECT 1 AS one FROM "spree_preferences" WHERE "spree_preferences"."key" = 'spree/app_configuration/allow_ssl_in_development_and_test' LIMIT 1
  Spree::Preference Load (0.1ms)  SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = 'allow_ssl_in_development_and_test' 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" IS NULL AND "spree_roles"."name" = 'admin'
Redirected to http://localhost:3000/
Completed 302 Found in 585ms (ActiveRecord: 11.1ms)

I have a user that is already assigned the role of admin:

 u
 => #<User id: 1, email: "user@example.com", encrypted_password: "$6CjAuPU3i1F1sHxFB6TC...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-10-18 08:50:41", last_sign_in_at: "2012-10-18 08:50:41", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2012-10-18 06:44:12", updated_at: "2012-10-18 08:50:41", name: "First User"> 
1.9.3p194 :017 > u.has_role?(:admin)
   (13.2ms)  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = 1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))
 => true 

How do I fix this?

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Oct 18, 2012

Member

I'm going to need the information from this section of the Contributing guide before I can determine what is wrong. Please provide it so I can investigate. Thanks.

Member

radar commented Oct 18, 2012

I'm going to need the information from this section of the Contributing guide before I can determine what is wrong. Please provide it so I can investigate. Thanks.

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 18, 2012

Exact steps to reproduce issue:

  • Create a new app using Rails_Apps_Composer like this:
    rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T

Here is a list of all the recipes used in my app:

Recipes:
["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"]

Preferences:
{:git=>true, :railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form", :quiet_assets=>true, :dev_webserver=>"thin", :prod_webserver=>"thin", :templates=>"erb", :rvmrc=>true}

If you are using the command I gave you earlier, as you are stepping through the prompts, just chose the same options I have above in 'Preferences'. i.e. when it asks for Authentication, choose Devise, Front-End => Twitter Bootstrap with SaSS, etc.

Then, once you have that setup - which should be straight forward and a vanilla Rails App, then you add spree to your Gemfile - gem 'spree', :git => 'git://github.com/spree/spree.git'

There is one gotcha, Rails_Apps_Composer installs CanCan v 1.6.8, but the latest build on the Master branch of Spree requires CanCan=1.6.7. So you have to make that change in your Gemfile and run bundle install.

I am using Rails 3.2.8 and Spree version: 1.3.0.

I am using whatever extensions come with the regular process of including that gem line in my Gemfile and running bundle install as of yesterday. I assume it's all the 6 gems that come standard.

I also loaded the spree_sample data and have not done any performance tweaks.

I have NOT enabled 'Dedicated Spree Devise Authentication`.

If you need any more log data (or if I have missed anything), let me know what else you may need. I think I got everything though.

Thanks.

marcamillion commented Oct 18, 2012

Exact steps to reproduce issue:

  • Create a new app using Rails_Apps_Composer like this:
    rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T

Here is a list of all the recipes used in my app:

Recipes:
["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"]

Preferences:
{:git=>true, :railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form", :quiet_assets=>true, :dev_webserver=>"thin", :prod_webserver=>"thin", :templates=>"erb", :rvmrc=>true}

If you are using the command I gave you earlier, as you are stepping through the prompts, just chose the same options I have above in 'Preferences'. i.e. when it asks for Authentication, choose Devise, Front-End => Twitter Bootstrap with SaSS, etc.

Then, once you have that setup - which should be straight forward and a vanilla Rails App, then you add spree to your Gemfile - gem 'spree', :git => 'git://github.com/spree/spree.git'

There is one gotcha, Rails_Apps_Composer installs CanCan v 1.6.8, but the latest build on the Master branch of Spree requires CanCan=1.6.7. So you have to make that change in your Gemfile and run bundle install.

I am using Rails 3.2.8 and Spree version: 1.3.0.

I am using whatever extensions come with the regular process of including that gem line in my Gemfile and running bundle install as of yesterday. I assume it's all the 6 gems that come standard.

I also loaded the spree_sample data and have not done any performance tweaks.

I have NOT enabled 'Dedicated Spree Devise Authentication`.

If you need any more log data (or if I have missed anything), let me know what else you may need. I think I got everything though.

Thanks.

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 18, 2012

I see you have closed this issue, does that mean that you fixed it in the latest commit?

Has it been accepted into the main branch for me to be able to re-run bundle install?

marcamillion commented Oct 18, 2012

I see you have closed this issue, does that mean that you fixed it in the latest commit?

Has it been accepted into the main branch for me to be able to re-run bundle install?

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Oct 19, 2012

Member

Oops, I tagged the wrong issue in a commit. This issue is not fixed yet.

Member

radar commented Oct 19, 2012

Oops, I tagged the wrong issue in a commit. This issue is not fixed yet.

@radar radar reopened this Oct 19, 2012

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Oct 19, 2012

Member

The composer template automatically runs rake db:seed, which is why your User record is claiming that the email is already taken.

Member

radar commented Oct 19, 2012

The composer template automatically runs rake db:seed, which is why your User record is claiming that the email is already taken.

@radar radar closed this Oct 19, 2012

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 19, 2012

Yes, I know that.

The issue is that I ran the composer first, then put the Spree gem into the
Gemfile - i.e. the seeds.rb was modified after it was run initially.

So shouldn't that be ok?

Also, the user that is created in the composer template is user@example.com.
Based on the docs for spree, it is trying to create spree@example.com.
That email address was not taken.

So the question is, now that I have done that - and I have the user@example.com already in my DB with the role of admin....how do I fix
it?

On Thu, Oct 18, 2012 at 11:16 PM, Ryan Bigg notifications@github.comwrote:

The composer template automatically runs rake db:seed, which is why your
User record is claiming that the email is already taken.


Reply to this email directly or view it on GitHubhttps://github.com/spree/spree/issues/2112#issuecomment-9589444.

marcamillion commented Oct 19, 2012

Yes, I know that.

The issue is that I ran the composer first, then put the Spree gem into the
Gemfile - i.e. the seeds.rb was modified after it was run initially.

So shouldn't that be ok?

Also, the user that is created in the composer template is user@example.com.
Based on the docs for spree, it is trying to create spree@example.com.
That email address was not taken.

So the question is, now that I have done that - and I have the user@example.com already in my DB with the role of admin....how do I fix
it?

On Thu, Oct 18, 2012 at 11:16 PM, Ryan Bigg notifications@github.comwrote:

The composer template automatically runs rake db:seed, which is why your
User record is claiming that the email is already taken.


Reply to this email directly or view it on GitHubhttps://github.com/spree/spree/issues/2112#issuecomment-9589444.

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Oct 19, 2012

Member

When you run rake db:seed it's attempting to recreate user@example.com, but it's already there. THIS IS THE PROBLEM. This is not a spree issue.

Member

radar commented Oct 19, 2012

When you run rake db:seed it's attempting to recreate user@example.com, but it's already there. THIS IS THE PROBLEM. This is not a spree issue.

@Spaceghost

This comment has been minimized.

Show comment
Hide comment
@Spaceghost

Spaceghost Oct 19, 2012

rake db:reset && rake db:seed

Woo...

Spaceghost commented Oct 19, 2012

rake db:reset && rake db:seed

Woo...

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 19, 2012

So I commented out the unnecessary things in the seeds.rb file for the user creation, this is the error message I am getting now.

/.rvm/gems/ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/countries.yml
rake aborted!
SQLite3::ConstraintException: PRIMARY KEY must be unique: INSERT INTO "spree_countries" ("name", "iso3", "iso", "iso_name", "id", "numcode") VALUES ('Chad', 'TCD', 'TD', 'CHAD', 39, 148)

Tasks: TOP => db:load_dir
(See full trace by running task with --trace) 

This seems like a SQLite & Spree issue.

P.S. Btw, thnx for that Spaceghost. rake db:reset did work.

marcamillion commented Oct 19, 2012

So I commented out the unnecessary things in the seeds.rb file for the user creation, this is the error message I am getting now.

/.rvm/gems/ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/countries.yml
rake aborted!
SQLite3::ConstraintException: PRIMARY KEY must be unique: INSERT INTO "spree_countries" ("name", "iso3", "iso", "iso_name", "id", "numcode") VALUES ('Chad', 'TCD', 'TD', 'CHAD', 39, 148)

Tasks: TOP => db:load_dir
(See full trace by running task with --trace) 

This seems like a SQLite & Spree issue.

P.S. Btw, thnx for that Spaceghost. rake db:reset did work.

@Spaceghost

This comment has been minimized.

Show comment
Hide comment
@Spaceghost

Spaceghost Oct 19, 2012

@marcamillion Clear your whole database.

Spaceghost commented Oct 19, 2012

@marcamillion Clear your whole database.

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Oct 19, 2012

Member

This is happening because your countries table already has data in it. Seed is supposed to only run on a fresh database, not one with data in it.

Member

radar commented Oct 19, 2012

This is happening because your countries table already has data in it. Seed is supposed to only run on a fresh database, not one with data in it.

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 19, 2012

Ok...before I drop my DB, this is my seeds.rb:

puts 'CREATING ROLES'
Role.create([
  { :name => 'admin' }, 
  { :name => 'user' }, 
  { :name => 'VIP' }
], :without_protection => true)

puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user.name
user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user2.name
user.add_role :admin
user2.add_role :VIP

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

Should I get rid of the manual user creation and the role creation and just leave the Spree stuff in there?

Or should I just move the Spree stuff above everything else?

Once I know what should work, I will drop my db and run it.

marcamillion commented Oct 19, 2012

Ok...before I drop my DB, this is my seeds.rb:

puts 'CREATING ROLES'
Role.create([
  { :name => 'admin' }, 
  { :name => 'user' }, 
  { :name => 'VIP' }
], :without_protection => true)

puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user.name
user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user2.name
user.add_role :admin
user2.add_role :VIP

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

Should I get rid of the manual user creation and the role creation and just leave the Spree stuff in there?

Or should I just move the Spree stuff above everything else?

Once I know what should work, I will drop my db and run it.

@Spaceghost

This comment has been minimized.

Show comment
Hide comment
@Spaceghost

Spaceghost Oct 19, 2012

Helpa has this trigger called !try. I'm sure you're familiar with it.

I suggest making use of your revision control software and trying. Explore. Learn. Have fun!

Spaceghost commented Oct 19, 2012

Helpa has this trigger called !try. I'm sure you're familiar with it.

I suggest making use of your revision control software and trying. Explore. Learn. Have fun!

@marcamillion

This comment has been minimized.

Show comment
Hide comment
@marcamillion

marcamillion Oct 19, 2012

Well I tried many permutations, even one with an empty db and the only thing in my seeds.rb is this:

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

And whenever I try to access /admin it still redirects me to localhost.

Started GET "/admin" for 127.0.0.1 at 2012-10-19 00:43:19 -0500
Processing by Spree::Admin::OverviewController#index as HTML
  Spree::Preference Exists (0.2ms)  SELECT 1 AS one FROM "spree_preferences" WHERE "spree_preferences"."key" = 'spree/app_configuration/allow_ssl_in_development_and_test' LIMIT 1
  Spree::Preference Load (0.1ms)  SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = 'allow_ssl_in_development_and_test' LIMIT 1
   (0.1ms)  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" IS NULL AND "spree_roles"."name" = 'admin'
Redirected to http://localhost:3000/

When I ran rake db:seed without anything else in my seeds.rb this is the output to the Terminal Window:

$ rake db:seed
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/countries.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/roles.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/states.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/zone_members.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/zones.yml

There are no more errors, but yet I still can't access /admin.

Something funky is clearly happening.

marcamillion commented Oct 19, 2012

Well I tried many permutations, even one with an empty db and the only thing in my seeds.rb is this:

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)

And whenever I try to access /admin it still redirects me to localhost.

Started GET "/admin" for 127.0.0.1 at 2012-10-19 00:43:19 -0500
Processing by Spree::Admin::OverviewController#index as HTML
  Spree::Preference Exists (0.2ms)  SELECT 1 AS one FROM "spree_preferences" WHERE "spree_preferences"."key" = 'spree/app_configuration/allow_ssl_in_development_and_test' LIMIT 1
  Spree::Preference Load (0.1ms)  SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = 'allow_ssl_in_development_and_test' LIMIT 1
   (0.1ms)  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" IS NULL AND "spree_roles"."name" = 'admin'
Redirected to http://localhost:3000/

When I ran rake db:seed without anything else in my seeds.rb this is the output to the Terminal Window:

$ rake db:seed
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/countries.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/roles.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/states.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/zone_members.yml
loading fixture /ruby-1.9.3-p194@myapp/bundler/gems/spree-6b5a77e00980/core/db/default/spree/zones.yml

There are no more errors, but yet I still can't access /admin.

Something funky is clearly happening.

@lmany

This comment has been minimized.

Show comment
Hide comment
@lmany

lmany Jun 15, 2013

I have the problem, could someone help?

lmany commented Jun 15, 2013

I have the problem, could someone help?

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Jun 15, 2013

Member

@lmany Could you please file a new issue about this? This issue is fairly old...

Make sure to include the info in the Contributing guide. Thanks!

Member

radar commented Jun 15, 2013

@lmany Could you please file a new issue about this? This issue is fairly old...

Make sure to include the info in the Contributing guide. Thanks!

@lmany

This comment has been minimized.

Show comment
Hide comment
@lmany

lmany Jun 15, 2013

Thank you four answer.
I'm trying to install spree 2.0.stable with other authenticated method based. I created a new application used rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T.
I followed all instructions gived spree/docs, and i configured intializers/spree with Spree.user_class = "User".
I can access to spree admin page

lmany commented Jun 15, 2013

Thank you four answer.
I'm trying to install spree 2.0.stable with other authenticated method based. I created a new application used rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T.
I followed all instructions gived spree/docs, and i configured intializers/spree with Spree.user_class = "User".
I can access to spree admin page

@radar

This comment has been minimized.

Show comment
Hide comment
@radar

radar Jun 20, 2013

Member

@lmany Please open a new issue about this. Click this link and fill in the details exactly as asked in the Contributing guide.

Thank you.

Member

radar commented Jun 20, 2013

@lmany Please open a new issue about this. Click this link and fill in the details exactly as asked in the Contributing guide.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment