Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
question loads its data
Browse files Browse the repository at this point in the history
  • Loading branch information
robmckinnon committed Apr 24, 2008
1 parent 94e9327 commit dedc03f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/answer_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def self.create_from data
end

def title
minor_subject ? "#{subject.name}: #{minor_subject.name}" : subject.name
(specifics = minor_subject) ? "#{subject.name}: #{specifics.name}" : subject.name
end
end
5 changes: 5 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ class Question < ActiveRecord::Base

belongs_to :answer

def self.create_from data
attributes = data.slice(:uin, :member, :text)
Question.new(attributes)
end

end
2 changes: 1 addition & 1 deletion spec/models/answer_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
it 'should use subject name only, if has no minor subject' do
specifics = 'specifics'
minor_subject = mock_model(Subject, :name => specifics)
@group.should_receive(:minor_subject).twice.and_return minor_subject
@group.should_receive(:minor_subject).and_return minor_subject
@group.title.should == "#{@topic}: #{specifics}"
end
end
24 changes: 24 additions & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/model_spec_helper'

describe Question do

it 'should belong to an answer' do
assert_model_belongs_to Question, :answer
end

end

describe Question, 'when loading' do

include ModelSpecHelper

it 'should ignore unneeded attribute' do
lambda { Question.create_from(:title => 'title') }.should_not raise_error
end

it 'should load member' do
assert_loads_attribute Question, :member
end

it 'should load uin' do
assert_loads_attribute Question, :uin
end

it 'should load text' do
assert_loads_attribute Question, :text
end

end
1 change: 0 additions & 1 deletion spec/spec_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ def assert_association_exists model, association_macro, association_name, model_

assert model_with_foreign_key.column_names.include?(association.primary_key_name), "Could not find foreign key '#{association.primary_key_name}' for the association '#{association_name}' in the table for model '#{model_with_foreign_key}'."
end

0 comments on commit dedc03f

Please sign in to comment.