Skip to content

Commit

Permalink
Created grade modules and consolidated lesson and exam models
Browse files Browse the repository at this point in the history
  • Loading branch information
gorrillamcd committed May 29, 2012
1 parent 6138d94 commit 17abbf2
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 36 deletions.
File renamed without changes.
@@ -1,3 +1,3 @@
// Place all the styles related to the Exams controller here.
// Place all the styles related to the grades controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
2 changes: 0 additions & 2 deletions app/controllers/exams_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/grades_controller.rb
@@ -0,0 +1,2 @@
class GradesController < ApplicationController
end
2 changes: 0 additions & 2 deletions app/helpers/exams_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/helpers/grades_helper.rb
@@ -0,0 +1,2 @@
module GradesHelper
end
4 changes: 0 additions & 4 deletions app/models/exam.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/grade.rb
@@ -0,0 +1,4 @@
class Grade < ActiveRecord::Base
belongs_to :subscription
belongs_to :lesson
end
5 changes: 4 additions & 1 deletion app/models/lesson.rb
@@ -1,7 +1,10 @@
class Lesson < ActiveRecord::Base
attr_accessible :name, :description, :teaching#, :course_id
attr_accessible :name, :description, :teaching
belongs_to :course

has_many :questions
has_many :grades

has_attached_file :teaching

end
4 changes: 3 additions & 1 deletion app/models/question.rb
@@ -1,4 +1,6 @@
class Question < ActiveRecord::Base
belongs_to :lesson
belongs_to :exam
has_many :answers

accepts_nested_attributes_for :answers, :allow_destroy => :true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
2 changes: 1 addition & 1 deletion app/models/subscription.rb
Expand Up @@ -2,7 +2,7 @@ class Subscription < ActiveRecord::Base

belongs_to :course
belongs_to :user
#has_many :grades
has_many :grades

validates_presence_of :course_id, :user_id, :state
validates_uniqueness_of :user_id, :scope => :course_id
Expand Down
14 changes: 0 additions & 14 deletions app/views/.ignore/layouts/application.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions config/locales/es.yml
@@ -0,0 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

es:
hello: "Hola Mundo"
1 change: 0 additions & 1 deletion config/routes.rb
Expand Up @@ -14,7 +14,6 @@

resources :courses do
resources :lessons
resources :exams
resources :books
end

Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20120528222412_create_grades.rb
@@ -0,0 +1,13 @@
class CreateGrades < ActiveRecord::Migration
def change
create_table :grades do |t|
t.integer :average_grade
t.references :subscription
t.references :lesson

t.timestamps
end
add_index :grades, :subscription_id
add_index :grades, :lesson_id
end
end
13 changes: 13 additions & 0 deletions db/migrate/20120528223348_remove_examid_from_question.rb
@@ -0,0 +1,13 @@
class RemoveExamidFromQuestion < ActiveRecord::Migration

def up
remove_index :questions, :exam_id
remove_column :questions, :exam_id
end

def down
add_column :questions, :exam_id, :integer
add_index :questions, :exam_id
end

end
18 changes: 9 additions & 9 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120514221909) do
ActiveRecord::Schema.define(:version => 20120528223348) do

create_table "answers", :force => true do |t|
t.string "text"
Expand Down Expand Up @@ -44,14 +44,16 @@
t.integer "credits"
end

create_table "exams", :force => true do |t|
t.string "name"
t.integer "course_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
create_table "grades", :force => true do |t|
t.integer "average_grade"
t.integer "subscription_id"
t.integer "lesson_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "exams", ["course_id"], :name => "index_exams_on_course_id"
add_index "grades", ["lesson_id"], :name => "index_grades_on_lesson_id"
add_index "grades", ["subscription_id"], :name => "index_grades_on_subscription_id"

create_table "lessons", :force => true do |t|
t.string "name"
Expand All @@ -70,12 +72,10 @@
create_table "questions", :force => true do |t|
t.string "text"
t.integer "lesson_id"
t.integer "exam_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "questions", ["exam_id"], :name => "index_questions_on_exam_id"
add_index "questions", ["lesson_id"], :name => "index_questions_on_lesson_id"

create_table "subscriptions", :force => true do |t|
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/grades_controller_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe GradesController do

end
9 changes: 9 additions & 0 deletions spec/factories/grades.rb
@@ -0,0 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :grade do
average_grade 1
subscription nil
lesson nil
end
end
15 changes: 15 additions & 0 deletions spec/helpers/grades_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the GradesHelper. For example:
#
# describe GradesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe GradesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/grade_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Grade do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 17abbf2

Please sign in to comment.