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

Commit

Permalink
data loads now, do: git submodule update ... then: rake lordsqna
Browse files Browse the repository at this point in the history
  • Loading branch information
robmckinnon committed Apr 24, 2008
1 parent dedc03f commit 899a3be
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class Subject < ActiveRecord::Base
has_many :answer_groups

def self.from_name name
name ? find_or_create_from_name(name) : nil
name ? Subject.find_or_create_by_name(name) : nil
end
end
13 changes: 10 additions & 3 deletions lib/tasks/lordsqna.rake
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ namespace :lordsqna do
task :clean => [:migrate_down, :migrate_up, :clone_structure] do
end

task :load_answers do
desc 'loads example data'
task :load_answers => :environment do
puts 'Loading example data'
Dir["#{RAILS_ROOT}/data/*"].each do |file|
puts 'todo: load '+file
groups_data = AnswerGroups.from_url(file)
data_hashs = groups_data.collect(&:morph_attributes)
data_hashs.each do |data_hash|
group = AnswerGroup.create_from(data_hash)
group.save!
end
end
end

desc 'does a clean sweep and loads xml, reindexes with solr'
task :regenerate => [:migrate_down, :migrate_up, :load_answers] do
puts 'Regenerated all data'
puts "Loaded #{AnswerGroup.count} answer groups"
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/answer_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@

it 'should associate with subject' do
subject_name, subject = mock('subject'), mock_model(Subject)
Subject.should_receive(:find_or_create_from_name).with(subject_name).and_return subject
Subject.should_receive(:from_name).with(subject_name).and_return subject
group = AnswerGroup.create_from(:subject => subject_name)
group.subject.should == subject
end

it 'should associate with minor subject, when minor subject present' do
subject_name, subject = mock('subject'), mock_model(Subject)
Subject.should_receive(:find_or_create_from_name).with(subject_name).and_return subject
Subject.should_receive(:from_name).with(subject_name).and_return subject
group = AnswerGroup.create_from(:minor_subject => subject_name)
group.minor_subject.should == subject
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

it 'should find or create from name' do
name, subject = 'name', mock_model(Subject)
Subject.should_receive(:find_or_create_from_name).with(name).and_return subject
Subject.should_receive(:find_or_create_by_name).with(name).and_return subject
Subject.from_name(name).should == subject

Subject.from_name(nil).should == nil
Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/morph
Submodule morph updated 2 files
+8 −0 lib/morph.rb
+21 −1 spec/morph_spec.rb

0 comments on commit 899a3be

Please sign in to comment.