Commit 9d4d40de authored by Robert Speicher's avatar Robert Speicher

Move IssueCommonality and Upvote specs out of models and into their own specs

parent 14daf2e2
...@@ -19,6 +19,11 @@ describe Issue do ...@@ -19,6 +19,11 @@ describe Issue do
it { Issue.should respond_to :opened } it { Issue.should respond_to :opened }
end end
describe 'modules' do
it { should include_module(IssueCommonality) }
it { should include_module(Upvote) }
end
subject { Factory.create(:issue) } subject { Factory.create(:issue) }
describe '#is_being_reassigned?' do describe '#is_being_reassigned?' do
...@@ -61,40 +66,6 @@ describe Issue do ...@@ -61,40 +66,6 @@ describe Issue do
subject.is_being_reopened?.should be_false subject.is_being_reopened?.should be_false
end end
end end
describe "plus 1" do
subject { Factory.create(:issue) }
it "with no notes has a 0/0 score" do
subject.upvotes.should == 0
end
it "should recognize non-+1 notes" do
subject.notes << Factory(:note, note: "No +1 here")
subject.should have(1).note
subject.notes.first.upvote?.should be_false
subject.upvotes.should == 0
end
it "should recognize a single +1 note" do
subject.notes << Factory(:note, note: "+1 This is awesome")
subject.upvotes.should == 1
end
it "should recognize a multiple +1 notes" do
subject.notes << Factory(:note, note: "+1 This is awesome")
subject.notes << Factory(:note, note: "+1 I want this")
subject.upvotes.should == 2
end
end
describe ".search" do
let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
it "matches by title" do
Issue.search('able').all.should == [issue]
end
end
end end
# == Schema Information # == Schema Information
# #
......
...@@ -20,38 +20,9 @@ describe MergeRequest do ...@@ -20,38 +20,9 @@ describe MergeRequest do
it { MergeRequest.should respond_to :opened } it { MergeRequest.should respond_to :opened }
end end
describe "plus 1" do describe 'modules' do
subject { Factory.create(:merge_request) } it { should include_module(IssueCommonality) }
it { should include_module(Upvote) }
it "with no notes has a 0/0 score" do
subject.upvotes.should == 0
end
it "should recognize non-+1 notes" do
subject.notes << Factory(:note, note: "No +1 here")
subject.should have(1).note
subject.notes.first.upvote?.should be_false
subject.upvotes.should == 0
end
it "should recognize a single +1 note" do
subject.notes << Factory(:note, note: "+1 This is awesome")
subject.upvotes.should == 1
end
it "should recognize a multiple +1 notes" do
subject.notes << Factory(:note, note: "+1 This is awesome")
subject.notes << Factory(:note, note: "+1 I want this")
subject.upvotes.should == 2
end
end
describe ".search" do
let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
it "matches by title" do
Issue.search('able').all.should == [issue]
end
end end
end end
# == Schema Information # == Schema Information
......
require 'spec_helper'
describe Issue, "IssueCommonality" do
let(:issue) { create(:issue) }
describe "Associations" do
it { should belong_to(:project) }
it { should belong_to(:author) }
it { should belong_to(:assignee) }
it { should have_many(:notes).dependent(:destroy) }
end
describe "Validation" do
it { should validate_presence_of(:project_id) }
it { should validate_presence_of(:author_id) }
it { should validate_presence_of(:title) }
it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
end
describe "Scope" do
it { described_class.should respond_to(:opened) }
it { described_class.should respond_to(:closed) }
it { described_class.should respond_to(:assigned) }
end
it "has an :author_id_of_changes accessor" do
issue.should respond_to(:author_id_of_changes)
issue.should respond_to(:author_id_of_changes=)
end
describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
it "matches by title" do
described_class.search('able').all.should == [searchable_issue]
end
end
describe "#today?" do
it "returns true when created today" do
# Avoid timezone differences and just return exactly what we want
Date.stub(:today).and_return(issue.created_at.to_date)
issue.today?.should be_true
end
it "returns false when not created today" do
Date.stub(:today).and_return(Date.yesterday)
issue.today?.should be_false
end
end
describe "#new?" do
it "returns true when created today and record hasn't been updated" do
issue.stub(:today?).and_return(true)
issue.new?.should be_true
end
it "returns false when not created today" do
issue.stub(:today?).and_return(false)
issue.new?.should be_false
end
it "returns false when record has been updated" do
issue.stub(:today?).and_return(true)
issue.touch
issue.new?.should be_false
end
end
end
require 'spec_helper'
describe Issue, "Upvote" do
let(:issue) { create(:issue) }
it "with no notes has a 0/0 score" do
issue.upvotes.should == 0
end
it "should recognize non-+1 notes" do
issue.notes << create(:note, note: "No +1 here")
issue.should have(1).note
issue.notes.first.upvote?.should be_false
issue.upvotes.should == 0
end
it "should recognize a single +1 note" do
issue.notes << create(:note, note: "+1 This is awesome")
issue.upvotes.should == 1
end
it "should recognize multiple +1 notes" do
issue.notes << create(:note, note: "+1 This is awesome")
issue.notes << create(:note, note: "+1 I want this")
issue.upvotes.should == 2
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment