I'm trying to finish writing unit and integration tests for my app, but when I ran rake test, I see a lot of errors, all of them caused by the system trying to delete a sql view which is read only. Why is it trying to delete the view when the tests are simply to validate data creation and how do I get my tests past this? The application is working perfectly fine, but I can't get the tests to run properly. (all tests were running fine before sql views got added).
This is the error I see:
Finished in 0.779585s, 39.7647 runs/s, 0.0000 assertions/s.
1) Error:
UsersControllerTest#test_should_get_new:
ActiveRecord::StatementInvalid: PG::ObjectNotInPrerequisiteState: ERROR: cannot delete from view "playabilitysummary"
DETAIL: Views that do not select from a single table or view are not automatically updatable.
HINT: To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.
: DELETE FROM "playabilitysummary"
Error:
UsersControllerTest#test_should_get_new:
NoMethodError: undefined method `each' for nil:NilClass
2) Error:
StaticPagesControllerTest#test_should_get_contactus:
ActiveRecord::StatementInvalid: PG::ObjectNotInPrerequisiteState: ERROR: cannot delete from view "playabilitysummary"
DETAIL: Views that do not select from a single table or view are not automatically updatable.
HINT: To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.
: DELETE FROM "playabilitysummary"
PlayabilitySummary model:
class PlayabilitySummary < ActiveRecord::Base
self.table_name = 'playabilitysummary'
after_initialize :readonly!
end
Playability Summary migration:
class CreatePlayabilitySummaries < ActiveRecord::Migration
def up
execute <<-SQL
CREATE VIEW PlayabilitySummary AS
SELECT date,user_id,speed,firmness,moisture FROM (((SELECT distinct(schedules.date) as date, speed.user_id as user_id, speed.speed as speed FROM schedules
join
(SELECT user_id, measure_date as speed_date, avg(speed) as speed FROM greens group by user_id, measure_date order by user_id, measure_date asc) as speed
on schedules.date = speed.speed_date) as avg1
JOIN
(SELECT user_id as fuser_id, measure_date as firm_date, avg(firmness) as firmness FROM greens group by user_id, measure_date order by user_id, measure_date asc) as firmness
ON avg1.user_id = firmness.fuser_id AND avg1.date = firmness.firm_date) as avg2
JOIN
(SELECT user_id as muser_id, measure_date as moist_date, avg(moisture) as moisture FROM greens group by user_id, measure_date order by user_id, measure_date asc) as moisture
ON avg2.fuser_id = moisture.muser_id AND avg2.date = moisture.moist_date)
SQL
end
def down
execute 'DROP VIEW PlayabilitySummary'
end
end
Sample test (user_controller):
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
Aucun commentaire:
Enregistrer un commentaire