Created
May 9, 2016 19:00
-
-
Save sebastjan-hribar/9bad2102b1ad5d04ce208b78d8aba5c8 to your computer and use it in GitHub Desktop.
foreign_key issues with tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Web::Controllers::Conferences | |
class Create | |
include Web::Action | |
before :check_for_admin_role | |
expose :conference | |
params do | |
param :conference do | |
param :month, presence: true | |
param :day, presence: true | |
param :status, presence: true | |
param :teacher_id, presence: true | |
param :slot_id, presence: true | |
end | |
end | |
def call(params) | |
if params.valid? | |
month = params[:conference][:month] | |
day = params[:conference][:day] | |
status = params[:conference][:status] | |
teacher_id = params[:conference][:teacher_id] | |
slot_id = params[:conference][:slot_id] | |
parent_id = 0 | |
@conference = ConferenceRepository.create(Conference.new(month: month, day: day, status: status, | |
teacher_id: teacher_id, slot_id: slot_id, | |
parent_id: parent_id)) | |
flash[:success_notice] = "Govorilne ure so bile uspešno ustvarjene." | |
redirect_to '/conferences' | |
else | |
flash[:failed_notice] = "Prišlo je do napake pri vnosu podatkov. Preverite podatke in | |
poskusite ponovno." | |
redirect_to '/conferences/new' | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Spec for conference create action | |
require 'spec_helper' | |
require_relative '../../../../apps/web/controllers/conferences/create' | |
describe Web::Controllers::Conferences::Create do | |
#teacher | |
let(:teacher_create_action) { Web::Controllers::Teachers::Create.new } | |
let(:teacher_create_params) { Hash[teacher: {name: 'Great', surname: 'Teacher', | |
email: 'some334@mail.com', password: "456", password_confirmation: "456", role: "teacher"}]} | |
let(:teacher_id) {teacher_create_action.teacher.id} | |
let(:teacher) {teacher_create_action.teacher} | |
#slot | |
let(:slot_create_action) { Web::Controllers::Slots::Create.new } | |
let(:slot_create_params) { Hash[slot: {period: '17.00-17.10'}]} | |
let(:slot_id) {slot_create_action.slot.id} | |
#conference | |
let(:conference_create_action) { Web::Controllers::Conferences::Create.new } | |
let(:conference_create_params) { Hash[conference: {month: 'Februar', day: 12, | |
teacher_id: @teacher.id, slot_id: @slot.id, status: 'Aktiven'}]} | |
after do | |
ConferenceRepository.clear | |
TeacherRepository.clear | |
SlotRepository.clear | |
end | |
it 'creates a new conference' do | |
teacher_create_action.call(teacher_create_params) | |
slot_create_action.call(slot_create_params) | |
conference_create_action.call(conference_create_params) | |
conference_create_action.conference.id.wont_be_nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
collection :teachers do | |
entity Teacher | |
repository TeacherRepository | |
attribute :id, Integer | |
attribute :name, String | |
attribute :surname, String | |
attribute :email, String | |
attribute :role, String | |
attribute :password_hash, String | |
attribute :password_salt, String | |
attribute :password_reset_token, String | |
attribute :password_reset_sent_at, DateTime | |
end | |
collection :conferences do | |
entity Conference | |
repository ConferenceRepository | |
attribute :id, Integer | |
attribute :month, String | |
attribute :day, Integer | |
attribute :status, String | |
attribute :teacher_id, Integer | |
attribute :slot_id, Integer | |
attribute :parent_id, Integer | |
attribute :parent_comment, String | |
end | |
collection :slots do | |
entity Slot | |
repository SlotRepository | |
attribute :id, Integer | |
attribute :period, String | |
end | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE "conferences" ( | |
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, | |
`teacher_id` integer NOT NULL, | |
`slot_id` integer NOT NULL, | |
`parent_id` integer, | |
`month` varchar(255) NOT NULL, | |
`day` integer NOT NULL, | |
`status` varchar(255) NOT NULL, | |
`parent_comment` varchar(255), | |
FOREIGN KEY(`teacher_id`) REFERENCES `teachers`, | |
FOREIGN KEY(`slot_id`) REFERENCES `slots`, | |
FOREIGN KEY(`parent_id`) REFERENCES `parents` | |
) | |
CREATE TABLE `slots` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `period` varchar(255) NOT NULL) | |
CREATE TABLE `teachers` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, | |
`name` varchar(255) NOT NULL, | |
`surname` varchar(255) NOT NULL, | |
`email` varchar(255) NOT NULL UNIQUE, | |
`role` varchar(255) NOT NULL, | |
`password_hash` varchar(255) NOT NULL, | |
`password_salt` varchar(255) NOT NULL, | |
`password_reset_token` varchar(255), | |
`password_reset_sent_at` timestamp | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -Ispec spec/web/controllers/conferences/create_spec.rb | |
Run options: --seed 38151 | |
# Running: | |
E | |
Finished in 0.339831s, 2.9426 runs/s, 0.0000 assertions/s. | |
1) Error: | |
Web::Controllers::Conferences::Create#test_0001_creates a new conference: | |
NoMethodError: undefined method `id' for nil:NilClass | |
spec/web/controllers/conferences/create_spec.rb:21:in `block (2 levels) in <main>' | |
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment