spec: once-ler spec/models/{b,c}*

in rails3, reduce runtime by >25% (25.5min -> 18.5min locally)

Change-Id: If2980f721f59fc04cff8d77857bb8554190c1935
Reviewed-on: https://gerrit.instructure.com/37072
Reviewed-by: Dave Donahue <ddonahue@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Jon Jensen <jon@instructure.com>
QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
Jon Jensen 2014-06-30 05:34:00 -06:00
parent ed757833de
commit fc9161d3f8
18 changed files with 478 additions and 461 deletions

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe BookmarkService do
before do
before :once do
bookmark_service_model
end

View File

@ -31,7 +31,7 @@ describe CalendarEvent do
end
describe "default_values" do
before(:each) do
before(:once) do
course_model
@original_start_at = Time.at(1220443500) # 3 Sep 2008 12:05pm (UTC)
@original_end_at = @original_start_at + 2.hours
@ -229,7 +229,7 @@ describe CalendarEvent do
end
context "for_user_and_context_codes" do
before do
before :once do
course_with_student(:active_all => true)
@student = @user
@e1 = @course.calendar_events.create!
@ -292,7 +292,7 @@ describe CalendarEvent do
end
context "notifications" do
before do
before :once do
Notification.create(:name => 'New Event Created', :category => "TestImmediately")
Notification.create(:name => 'Event Date Changed', :category => "TestImmediately")
course_with_student(:active_all => true)
@ -358,7 +358,7 @@ describe CalendarEvent do
end
context "appointments" do
before do
before :once do
course_with_student(:active_all => true)
@student1 = @user
@other_section = @course.course_sections.create!
@ -676,7 +676,7 @@ describe CalendarEvent do
end
context "bulk updating" do
before do
before :once do
course_with_teacher
end

View File

@ -51,7 +51,7 @@ describe Collaboration do
end
context "parsed data" do
before do
before :once do
google_docs_collaboration_model
end
@ -72,7 +72,7 @@ describe Collaboration do
end
context "a collaboration with collaborators" do
before(:each) do
before :each do
PluginSetting.create!(:name => "etherpad", :settings => {})
@users = (1..4).map { user_with_pseudonym(:active_all => true) }
@groups = [group_model]

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe Collaborator do
before do
before :once do
@notification = Notification.create!(:name => 'Collaboration Invitation')
@author = user_with_pseudonym(:active_all => true)
@collaboration = Collaboration.new(:title => 'Test collaboration')

View File

@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentExport do
context "export_object?" do
before do
before :once do
@ce = ContentExport.new(course: Account.default.courses.create!)
end
@ -61,7 +61,7 @@ describe ContentExport do
end
context "add_item_to_export" do
before do
before :once do
@ce = ContentExport.new(course: Account.default.courses.create!)
end
@ -96,7 +96,7 @@ describe ContentExport do
end
context "notifications" do
before(:each) do
before :once do
course_with_teacher(:active_all => true)
@ce = ContentExport.create! { |ce| ce.user = @user; ce.course = @course }

View File

@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentMigration do
context "course copy" do
before do
before :once do
course_with_teacher(:course_name => "from course", :active_all => true)
@copy_from = @course
@ -2176,7 +2176,7 @@ equation: <img class="equation_image" title="Log_216" src="/equation_images/Log_
end
context "copying frozen assignments" do
append_before (:each) do
before :once do
@setting = PluginSetting.create!(:name => "assignment_freezer", :settings => {"no_copying" => "yes"})
@asmnt = @copy_from.assignments.create!(:title => 'lock locky')
@ -2252,7 +2252,7 @@ equation: <img class="equation_image" title="Log_216" src="/equation_images/Log_
end
context "external tools" do
append_before do
before :once do
@tool_from = @copy_from.context_external_tools.create!(:name => "new tool", :consumer_key => "key", :shared_secret => "secret", :custom_fields => {'a' => '1', 'b' => '2'}, :url => "http://www.example.com")
@tool_from.settings[:course_navigation] = {:url => "http://www.example.com", :text => "Example URL"}
@tool_from.save!
@ -2405,7 +2405,7 @@ equation: <img class="equation_image" title="Log_216" src="/equation_images/Log_
end
context "import_object?" do
before do
before :once do
course
@cm = ContentMigration.new(context: @course)
end

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentParticipationCount do
before do
before :once do
course_with_teacher(:active_all => true)
student_in_course(:active_all => true)
@ -29,7 +29,7 @@ describe ContentParticipationCount do
end
describe "create_or_update" do
before do
before :once do
@submission = @assignment.grade_student(@student, { :grade => 3 }).first
end
@ -63,7 +63,7 @@ describe ContentParticipationCount do
end
describe "unread_count_for" do
before do
before :once do
@submission = @assignment.grade_student(@student, { :grade => 3 }).first
end

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentParticipation do
before do
before :once do
course_with_teacher(:active_all => true)
student_in_course(:active_all => true)
assignment_model(:course => @course)

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ConversationMessageParticipant do
before do
before :once do
teacher_in_course
student_in_course
@student1 = @student
@ -28,7 +28,7 @@ describe ConversationMessageParticipant do
end
describe "scopes" do
before do
before :once do
@conv = conversation(@teacher, @student1, @student2)
@msg = @conv.messages.first
end

View File

@ -20,7 +20,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ConversationMessage do
context "notifications" do
before(:each) do
before :once do
Notification.create(:name => "Conversation Message", :category => "TestImmediately")
Notification.create(:name => "Added To Conversation", :category => "TestImmediately")
@ -228,7 +228,7 @@ describe ConversationMessage do
end
context "infer_defaults" do
before do
before :once do
course_with_teacher(:active_all => true)
student_in_course(:active_all => true)
end

View File

@ -177,7 +177,7 @@ describe ConversationParticipant do
end
context "for_masquerading_user scope" do
before do
before :once do
@a1 = Account.create
@a2 = Account.create
@a3 = Account.create
@ -217,7 +217,7 @@ describe ConversationParticipant do
end
context "participants" do
before do
before :once do
@me = course_with_student(:active_all => true).user
@u1 = student_in_course(:active_all => true).user
@u2 = student_in_course(:active_all => true).user
@ -264,7 +264,7 @@ describe ConversationParticipant do
end
context "move_to_user" do
before do
before :once do
@user1 = user_model
@user2 = user_model
end
@ -427,22 +427,27 @@ describe ConversationParticipant do
@user2.reload.unread_conversations_count.should eql 1
other_guy.reload.unread_conversations_count.should eql 1
end
end
context "sharding" do
specs_require_sharding
context "move_to_user with sharding" do
specs_require_sharding
it "should be able to move to a user on a different shard" do
u1 = User.create!
cp = u1.initiate_conversation([u1])
@shard1.activate do
u2 = User.create!
cp.move_to_user(u2)
cp.reload
cp.user.should == u2
cp2 = u2.all_conversations.first
cp2.should_not == cp
cp2.shard.should == @shard1
end
before do
@user1 = user_model
@user2 = user_model
end
it "should be able to move to a user on a different shard" do
u1 = User.create!
cp = u1.initiate_conversation([u1])
@shard1.activate do
u2 = User.create!
cp.move_to_user(u2)
cp.reload
cp.user.should == u2
cp2 = u2.all_conversations.first
cp2.should_not == cp
cp2.shard.should == @shard1
end
end
end

View File

@ -824,7 +824,7 @@ describe Conversation do
end
context "migration" do
before do
before :once do
@u1 = student_in_course(:active_all => true).user
@u2 = student_in_course(:active_all => true, :course => @course).user
@course1 = @course
@ -867,7 +867,7 @@ describe Conversation do
end
context 'tag updates' do
before(:each) do
before :once do
@teacher = teacher_in_course(:active_all => true).user
@student = student_in_course(:active_all => true, :course => @course).user
@old_course = @course

View File

@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe CourseProgress do
let(:progress_error) { {:error=>{:message=>'no progress available because this course is not module based (has modules and module completion requirements) or the user is not enrolled as a student in this course'}} }
before do
before :each do
class CourseProgress
def course_context_modules_item_redirect_url(opts = {})
"course_context_modules_item_redirect_url(:course_id => #{opts[:course_id]}, :id => #{opts[:id]}, :host => HostUrl.context_host(Course.find(#{opts[:course_id]}))"
@ -29,7 +29,7 @@ describe CourseProgress do
end
end
before(:each) do
before :once do
course_with_teacher(:active_all => true)
end
@ -47,7 +47,7 @@ describe CourseProgress do
end
context "module based and for student" do
before do
before :once do
@module = @course.context_modules.create!(:name => "some module", :require_sequential_progress => true)
@module2 = @course.context_modules.create!(:name => "another module", :require_sequential_progress => true)
@module3 = @course.context_modules.create!(:name => "another module again", :require_sequential_progress => true)

View File

@ -248,7 +248,7 @@ describe CourseSection, "moving to new course" do
end
describe 'validation' do
before(:each) do
before :once do
course = Course.create_unique
@section = CourseSection.create(course: course)
@long_string = 'qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm'
@ -272,7 +272,7 @@ describe CourseSection, "moving to new course" do
end
describe 'deletable?' do
before do
before :once do
course_with_teacher
@section = course.course_sections.create!
end
@ -295,7 +295,7 @@ describe CourseSection, "moving to new course" do
context 'permissions' do
context ':read and section_visibilities' do
before do
before :once do
RoleOverride.create!({
:context => Account.default,
:permission => 'manage_students',

File diff suppressed because it is too large Load Diff

View File

@ -19,21 +19,27 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'CrocodocDocument' do
before do
before :once do
Setting.set 'crocodoc_counter', 0
PluginSetting.create! :name => 'crocodoc',
:settings => { :api_key => "blahblahblahblahblah" }
end
before :each do
Crocodoc::API.any_instance.stubs(:upload).returns 'uuid' => '1234567890'
end
context 'permissions_for_user' do
before do
before :once do
teacher_in_course(:active_all => true)
student_in_course
@submitter = @student
student_in_course
@other_student = @student
submission_model :course => @course, :user => @submitter
end
before :each do
attachment = attachment_model(:context => @submitter)
attachment.associate_with(@submission)
attachment.save!

View File

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe CustomData do
before do
before :once do
custom_data_model
end

View File

@ -20,7 +20,8 @@ module Onceler
%w{let_once subject_once let_each let_each! subject_each subject_each!}.each do |method|
define_method(method) do |*args, &block|
frd_method = method.sub(/_[^!]+/, '')
# make _once behave like !, because that's essentially what onceler is doing
frd_method = method.sub(/_each!?\z/, '').sub(/_once!?\z/, '!')
send frd_method, args.first, &block
end
end