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

Commit

Permalink
generated models for question, answer, answer_group and subject
Browse files Browse the repository at this point in the history
  • Loading branch information
robmckinnon committed Apr 24, 2008
1 parent 939c411 commit 0909a29
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/models/answer_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AnswerGroup < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Subject < ActiveRecord::Base
end
6 changes: 6 additions & 0 deletions db/development_structure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE "answer_groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "anchor" varchar(255) DEFAULT NULL, "date" date DEFAULT NULL, "minor_subject_id" integer DEFAULT NULL, "subject_id" integer DEFAULT NULL, "url" varchar(255) DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at" datetime DEFAULT NULL);
CREATE TABLE "answers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "member" varchar(255) DEFAULT NULL, "answer_group_id" integer DEFAULT NULL, "role" varchar(255) DEFAULT NULL, "text" varchar(255) DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at" datetime DEFAULT NULL);
CREATE TABLE "questions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "member" varchar(255) DEFAULT NULL, "text" varchar(255) DEFAULT NULL, "uin" varchar(255) DEFAULT NULL, "answer_id" integer DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at" datetime DEFAULT NULL);
CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
CREATE TABLE "subjects" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255) DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at" datetime DEFAULT NULL);
CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
17 changes: 17 additions & 0 deletions db/migrate/20080424150649_create_answer_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateAnswerGroups < ActiveRecord::Migration
def self.up
create_table :answer_groups do |t|
t.string :anchor
t.date :date
t.integer :minor_subject_id
t.integer :subject_id
t.string :url

t.timestamps
end
end

def self.down
drop_table :answer_groups
end
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
class CreateAnswers < ActiveRecord::Migration
def self.up
create_table :answers do |t|
t.date :date
t.string :major_subject
t.string :member
t.string :minor_subject
t.integer :answer_group_id
t.string :role
t.string :text
t.string :title

t.timestamps
end
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20080424150658_create_subjects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateSubjects < ActiveRecord::Migration
def self.up
create_table :subjects do |t|
t.string :name

t.timestamps
end
end

def self.down
drop_table :subjects
end
end
25 changes: 19 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20080423170543) do
ActiveRecord::Schema.define(:version => 20080424150658) do

create_table "answer_groups", :force => true do |t|
t.string "anchor"
t.date "date"
t.integer "minor_subject_id"
t.integer "subject_id"
t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "answers", :force => true do |t|
t.string "date"
t.string "major_subject"
t.string "member"
t.string "minor_subject"
t.string "questions"
t.integer "answer_group_id"
t.string "role"
t.string "text"
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand All @@ -28,6 +34,13 @@
t.string "member"
t.string "text"
t.string "uin"
t.integer "answer_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "subjects", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down
11 changes: 10 additions & 1 deletion lib/answer_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def self.from_url url
from_doc doc, url
end

def self.ar_script_generate
generate = []
generate << AnswerGroups.script_generate.gsub('AnswerGroups','AnswerGroup').sub('date:string','date:date').gsub(/(answers|title):string /,'').gsub('subject:string','subject_id:integer')
generate << Answers.script_generate.gsub('Answers','Answer').sub('questions:string','answer_group_id:integer')
generate << Questions.script_generate.gsub('Questions','Question')+' answer_id:integer'
generate << 'ruby script/destroy rspec_model Subject; ruby script/generate rspec_model Subject name:string'
puts generate.join("\n")
end

def initialize attributes
morph(attributes)
end
Expand All @@ -27,7 +36,7 @@ def self.from_doc doc, url
:url => url,
:anchor => find_title_anchor_name(title_element),
:date => date,
:major_subject => find_major_title_text(title),
:subject => find_major_title_text(title),
:minor_subject => find_minor_title_text(title),
:answers => Answers.create_answers(title_element)
})
Expand Down
2 changes: 1 addition & 1 deletion spec/answer_groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
group.anchor.should == @title_anchor
group.date.should == Date.parse(@date_text)
group.title.should == @title_text
group.major_subject.should == @major_title
group.subject.should == @major_title
group.minor_subject.should == @minor_title
group.answers.size.should == 2
group.answers[0].should == answer1
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/answer_groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
anchor: MyString
date: 2008-04-24
minor_subject_id: 1
subject_id: 1
url: MyString

two:
anchor: MyString
date: 2008-04-24
minor_subject_id: 1
subject_id: 1
url: MyString
10 changes: 2 additions & 8 deletions spec/fixtures/answers.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
date: 2008-04-23
major_subject: MyString
member: MyString
minor_subject: MyString
answer_group_id: 1
role: MyString
text: MyString
title: MyString

two:
date: 2008-04-23
major_subject: MyString
member: MyString
minor_subject: MyString
answer_group_id: 1
role: MyString
text: MyString
title: MyString
7 changes: 7 additions & 0 deletions spec/fixtures/subjects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString

two:
name: MyString
11 changes: 11 additions & 0 deletions spec/models/answer_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe AnswerGroup do
before(:each) do
@answer_group = AnswerGroup.new
end

it "should be valid" do
@answer_group.should be_valid
end
end
7 changes: 7 additions & 0 deletions spec/models/answer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Answer do
before(:each) do
@answer = Answer.new
end

it "should be valid" do
@answer.should be_valid
end
end
7 changes: 7 additions & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Question do
before(:each) do
@question = Question.new
end

it "should be valid" do
@question.should be_valid
end
end
11 changes: 11 additions & 0 deletions spec/models/subject_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Subject do
before(:each) do
@subject = Subject.new
end

it "should be valid" do
@subject.should be_valid
end
end

0 comments on commit 0909a29

Please sign in to comment.