dfb5da9da3
Used the built-in observer enable/disable feature in ActiveModel[1]. ActiveRecord::Base includes ActiveModel::Observing which provides this behavior. Simple wraps to enable the observer under test were added to the specs for: ActivityObserver, IssueObserver, Admin::Users and Issues. The spec for Project.last_activity was refactored to separate the tests for #last_activity and #last_activity_date. Each had doubles added to isolate the spec from the hidden dependency on the ActivityObserver action to create an Event for the project when an Issue is created. This ActivityObserver behavior is already tested by its spec. [1] http://api.rubyonrails.org/classes/ActiveModel/ObserverArray.html
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe ActivityObserver do
|
|
let(:project) { Factory :project }
|
|
|
|
def self.it_should_be_valid_event
|
|
it { @event.should_not be_nil }
|
|
it { @event.project.should == project }
|
|
end
|
|
|
|
describe "Merge Request created" do
|
|
before do
|
|
MergeRequest.observers.enable :activity_observer do
|
|
@merge_request = Factory :merge_request, :project => project
|
|
@event = Event.last
|
|
end
|
|
end
|
|
|
|
it_should_be_valid_event
|
|
it { @event.action.should == Event::Created }
|
|
it { @event.target.should == @merge_request }
|
|
end
|
|
|
|
describe "Issue created" do
|
|
before do
|
|
Issue.observers.enable :activity_observer do
|
|
@issue = Factory :issue, :project => project
|
|
@event = Event.last
|
|
end
|
|
end
|
|
|
|
it_should_be_valid_event
|
|
it { @event.action.should == Event::Created }
|
|
it { @event.target.should == @issue }
|
|
end
|
|
|
|
#describe "Issue commented" do
|
|
#before do
|
|
#@issue = Factory :issue, :project => project
|
|
#@note = Factory :note, :noteable => @issue, :project => project
|
|
#@event = Event.last
|
|
#end
|
|
|
|
#it_should_be_valid_event
|
|
#it { @event.action.should == Event::Commented }
|
|
#it { @event.target.should == @note }
|
|
#end
|
|
end
|