Im sorry if this might be long but would appreciate your help on this.
I'm getting error when running test on my home controller.
This is my home controller which just basically renders the view.
class HomeController < ApplicationController
def index
end
end
And in my test/controllers/home_controller_test.rb
require 'test_helper'
class HomeControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get home_index_url
assert_response :success
end
end
When i run bin/rails test test/controllers/home_controller_test.rb in the terminal, im getting this error as a result
Running via Spring preloader in process 27352
Run options: --seed 1283
# Running:
E
Error:
HomeControllerTest#test_should_get_index:
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: NOT NULL
constraint failed: addresses.full_address: INSERT INTO "addresses"
("created_at", "updated_at", "id") VALUES ('2017-07-31 11:49:24.912600',
'2017-07-31 11:49:24.912600', 980190962)
bin/rails test test/controllers/home_controller_test.rb:4
Finished in 0.595890s, 1.6782 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
I have a model called Address but it's not used in the home controller. Here is how my Address migration file looks like
class CreateAddresses < ActiveRecord::Migration[5.0]
def change
create_table :addresses do |t|
t.string :full_address, null: false
t.string :formatted_address
t.string :sub_locality
t.string :city
t.string :postal_code
t.string :state
t.decimal :latitude, precision: 9, scale:6
t.decimal :longitude, precision: 9, scale:6
t.references :user
t.references :order
t.references :merchant
t.timestamps
end
end
end
From my understanding, the test result would return success if the http response is 200. In my browser, i can load my home page without any errors in my log.
Im confused as to why i'm getting Address model related error when i'm testing my home controller even though i did not access it in my home controller or view.
Any help on this would be appreciated!
Aucun commentaire:
Enregistrer un commentaire