oveits / ProvisioningEngine

Ruby on Rails based ProvisioningEngine Frontend for provisioning of legacy systems via Apache Camel Backend (SOAP/XML+SPML+File import)
3 stars 6 forks source link

rake db:seed returns ActiveRecord::RecordInvalid: Validation failed: Password can't be blank #25

Closed oveits closed 8 years ago

oveits commented 8 years ago
$ rake db:seed
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Password can't be blank
/home/provisioningengine/ProvisioningEnginev0.5.15_testfolder/db/seeds.rb:2:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
oveits commented 8 years ago

The encryptes stored password seems to be empty in the db/seeds.rb:

if AdminUser.count == 0
  AdminUser.create!([
    {email: "admin@example.com", encrypted_password: "$2a$10$lBmG9eNLLxS1GyCEBS6dcu/AtStbUdzmZKd2NN3k2tAkEAZWS8nyu", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-02-03 18:23:09", last_sign_in_at: "2016-02-03 18:23:09", current_sign_in_ip: "93.104.170.126", last_sign_in_ip: "93.104.170.126"}
  ])
end
(...)

Therefore, I have re-created the entry by:

rails console
AdminUser.create :email => 'admin@example.com', :password => 'password', :password_confirmation => 'password'

Let us save the old (wrong) seeds.rb:

$ mv db/seeds.rb db/seeds.rb.bak1_empty_password

then dumb the database:

$ rake db:seed:dump

this is creating the new seeds.rb file, which has an entry

AdminUser.create!([
  {email: "admin@example.com", encrypted_password: "$2a$10$xPFzctyt2spAMinwS58fs.LZNXjtIr2dSc0fIiIgDz1ouMNHqheoi", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-02-10 17:58:50", last_sign_in_at: "2016-02-10 17:58:50", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1"}
])

Now I have replaced the corresponding entry in the original seeds.rb by this one and removed the current admin@example.com. Now let us try again:

$ rake db:seed
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Password can't be blank
/home/provisioningengine/ProvisioningEnginev0.5.15_testfolder/db/seeds.rb:2:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

Same again. It seems like AdminUser.create expects a password and password_confirmation. :-(

oveits commented 8 years ago

Why not creating the entry as in the rails console?

Note: seeds.rb is just plain ruby code, so in db/seeds.rb I have replaced the entry just by:

if AdminUser.count == 0
  AdminUser.create! :email => 'admin@example.com', :password => 'password', :password_confirmation => 'password'
end

The plain password does not matter, since this is for initialization only and needs to be changed manually anyway. And because of the if clause the admin user is created only, if there is no other admin defined.

Let us try again:

$ rake db:seed
rake aborted!
NameError: uninitialized constant Config
/home/provisioningengine/ProvisioningEnginev0.5.15_testfolder/db/seeds.rb:5:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

Okay, the ActiveAdmin entry has worked, but there is an obsolete Config entry, which I had to rename Config->SystemSetting (next comment).

oveits commented 8 years ago

Resolving the SystemSetting seed:

$ rake db:seed
rake aborted!
ActiveRecord::StatementInvalid: Could not find table 'system_settings'
/home/provisioningengine/ProvisioningEnginev0.5.15_testfolder/db/seeds.rb:5:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

Okay, it looks like I need to migrate first?

$ rake db:migrate
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 12 models...
Warning: Ignoring invalid model SystemSetting (table system_settings does not exist)
Warning: Ignoring invalid association :resource on ActiveAdmin::Comment (polymorphic interface Resource does not exist)
Warning: Ignoring invalid association :author on ActiveAdmin::Comment (polymorphic interface Author does not exist)
Done! Saved diagram to erd.pdf.

Hm. Why is the system_settings table not be created?

I know: I have introduced a bug, when I have changed .gitignore: now the db migrations are excluded now. I need to open a new bug for this. I have not recognized the problem, because the active admin System Settings pages are not yet tested.

oveits commented 8 years ago

Closed by https://github.com/oveits/ProvisioningEngine/commit/fe5c556a269264ce9e8bdc99463a01748218b05c, which changes

$ git diff 
...
db/seeds.rb
@@ -1,14 +1,12 @@
  if AdminUser.count == 0
 -  AdminUser.create!([
 -    {email: "admin@example.com", encrypted_password: "$2a$10$lBmG9eNLLxS1GyCEBS6dcu/AtStbUdzmZKd2NN3k2tAkEAZWS8nyu", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-02-03 18:23:09", last_sign_in_at: "2016-02-03 18:23:09", current_sign_in_ip: "93.104.170.126", last_sign_in_ip: "93.104.170.126"}
 -  ])
 +  AdminUser.create! :email => 'admin@example.com', :password => 'password', :password_confirmation => 'password'
  end