Skip to content

Commit

Permalink
Merge pull request mendicant-original#3 from wicz/factory_girl
Browse files Browse the repository at this point in the history
Factory girl
  • Loading branch information
wicz committed Mar 18, 2012
2 parents bffcdc8 + fe8476a commit 1e4ab28
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def find_course
rescue ActiveRecord::RecordNotFound
redirect_to(root_url, alert: "Couldn't find course")
end
end
end
20 changes: 11 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120316003602) do
ActiveRecord::Schema.define(:version => 20120316053737) do

create_table "course_memberships", :force => true do |t|
t.integer "course_id"
t.string "person_github_nickname"
Expand All @@ -27,13 +28,6 @@
t.datetime "updated_at", :null => false
end

create_table "tasks", :force => true do |t|
t.integer "course_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "discussions", :force => true do |t|
t.string "category"
t.text "subject"
Expand All @@ -42,4 +36,12 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end

create_table "tasks", :force => true do |t|
t.integer "course_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
8 changes: 8 additions & 0 deletions test/factories/course_memberships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do
factory :instructor, class: CourseMembership do
association :course, factory: 'webdev'
person_github_nickname 'instructor'
role 'Instructor'
end
end

6 changes: 6 additions & 0 deletions test/factories/courses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :webdev, class: Course do
name "Web Development"
description "MU's Web Development Course"
end
end
5 changes: 0 additions & 5 deletions test/fixtures/course_memberships.yml

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/courses.yml

This file was deleted.

11 changes: 6 additions & 5 deletions test/functional/tasks_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
require "test_helper"

class TasksControllerTest < ActionController::TestCase
fixtures :all

def setup
cm = Factory(:instructor)
@course = cm.course
@controller.current_person = clubhouse_person("instructor")
end

test "#new is not allowed to students" do
@controller.current_person = clubhouse_person("student")

get(:new, course_id: courses(:webdev).id)
assert_redirected_to(courses(:webdev))
get(:new, course_id: @course.id)
assert_redirected_to(@course)
assert flash[:alert]
end

test "#new is allowed to instructors" do
get(:new, course_id: courses(:webdev).id)
get(:new, course_id: @course.id)
assert_template "new"
end

Expand All @@ -25,4 +26,4 @@ def setup
assert_redirected_to(root_url)
assert flash[:alert]
end
end
end
2 changes: 0 additions & 2 deletions test/integration/tasks_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "test_helper"

class TasksTest < ActionDispatch::IntegrationTest
fixtures :all

test "an instructor can create a new course task" do
sign_in_as_instructor

Expand Down
5 changes: 2 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

require "capybara/rails"

Clubhouse::Client.test_mode = true
Expand All @@ -12,11 +11,11 @@ def clubhouse_person(github_nickname)
end

class ActiveSupport::TestCase
fixtures :all
end

class ActionDispatch::IntegrationTest
include Capybara::DSL
setup { Factory(:instructor) }
teardown { Capybara.reset_sessions! }

def sign_in_as_instructor
Expand All @@ -35,4 +34,4 @@ def sign_in(person)
click_button "Sign In"
assert_includes(page.body, "Welcome to Liskov")
end
end
end

0 comments on commit 1e4ab28

Please sign in to comment.