From c8ba5c2d58b882fd7cd5342a42158bb5f810fd60 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 25 Dec 2012 06:14:05 +0300 Subject: Fix routing issues when navigating over tree, commits etc --- spec/lib/extracts_path_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index cf4220175a7..8773d77f5a5 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -8,6 +8,7 @@ describe ExtractsPath do before do @project = project project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']) + project.stub(path_with_namespace: 'gitlab/gitlab-ci') end describe '#extract_ref' do @@ -53,5 +54,24 @@ describe ExtractsPath do extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG'] end end + + context "with a fullpath" do + it "extracts a valid branch" do + extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG'] + end + + it "extracts a valid tag" do + extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG'] + end + + it "extracts a valid commit SHA" do + extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should == + ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG'] + end + + it "extracts a timestamp" do + extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG'] + end + end end end -- cgit v1.2.1 From ccf0686b01160e4a61bf8fb4b26f43d1486af9c2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 19:46:06 +0200 Subject: Fix api specs. Use id instead path --- spec/lib/project_mover_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/lib') diff --git a/spec/lib/project_mover_spec.rb b/spec/lib/project_mover_spec.rb index 2362bc2667b..28323b24ef6 100644 --- a/spec/lib/project_mover_spec.rb +++ b/spec/lib/project_mover_spec.rb @@ -5,6 +5,7 @@ describe Gitlab::ProjectMover do before do FileUtils.rm_rf base_path if File.exists? base_path + FileUtils.mkdir_p base_path Gitlab.config.gitolite.stub(repos_path: base_path) -- cgit v1.2.1 From cac7723451e575ce39a6930990178450a2a972f0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 23:35:11 +0200 Subject: Get rid of roles --- spec/lib/issue_commonality_spec.rb | 70 ++++++++++++++++++++ spec/lib/votes_spec.rb | 132 +++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 spec/lib/issue_commonality_spec.rb create mode 100644 spec/lib/votes_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/issue_commonality_spec.rb b/spec/lib/issue_commonality_spec.rb new file mode 100644 index 00000000000..11f278dea10 --- /dev/null +++ b/spec/lib/issue_commonality_spec.rb @@ -0,0 +1,70 @@ +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) } + it { should validate_presence_of(:author) } + it { should validate_presence_of(:title) } + it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) } + it { should ensure_inclusion_of(:closed).in_array([true, false]) } + 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 diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb new file mode 100644 index 00000000000..98666022a8f --- /dev/null +++ b/spec/lib/votes_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +describe Issue do + let(:issue) { create(:issue) } + + describe "#upvotes" do + 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 + + describe "#downvotes" do + it "with no notes has a 0/0 score" do + issue.downvotes.should == 0 + end + + it "should recognize non--1 notes" do + issue.notes << create(:note, note: "Almost got a -1") + issue.should have(1).note + issue.notes.first.downvote?.should be_false + issue.downvotes.should == 0 + end + + it "should recognize a single -1 note" do + issue.notes << create(:note, note: "-1 This is bad") + issue.downvotes.should == 1 + end + + it "should recognize multiple -1 notes" do + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "-1 Away with this") + issue.downvotes.should == 2 + end + end + + describe "#votes_count" do + it "with no notes has a 0/0 score" do + issue.votes_count.should == 0 + end + + it "should recognize non notes" do + issue.notes << create(:note, note: "No +1 here") + issue.should have(1).note + issue.votes_count.should == 0 + end + + it "should recognize a single +1 note" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.votes_count.should == 1 + end + + it "should recognize a single -1 note" do + issue.notes << create(:note, note: "-1 This is bad") + issue.votes_count.should == 1 + end + + it "should recognize multiple notes" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 I want this") + issue.votes_count.should == 3 + end + end + + describe "#upvotes_in_percent" do + it "with no notes has a 0% score" do + issue.upvotes_in_percent.should == 0 + end + + it "should count a single 1 note as 100%" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.upvotes_in_percent.should == 100 + end + + it "should count multiple +1 notes as 100%" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.upvotes_in_percent.should == 100 + end + + it "should count fractions for multiple +1 and -1 notes correctly" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 me too") + issue.upvotes_in_percent.should == 75 + end + end + + describe "#downvotes_in_percent" do + it "with no notes has a 0% score" do + issue.downvotes_in_percent.should == 0 + end + + it "should count a single -1 note as 100%" do + issue.notes << create(:note, note: "-1 This is bad") + issue.downvotes_in_percent.should == 100 + end + + it "should count multiple -1 notes as 100%" do + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "-1 Away with this") + issue.downvotes_in_percent.should == 100 + end + + it "should count fractions for multiple +1 and -1 notes correctly" do + issue.notes << create(:note, note: "+1 This is awesome") + issue.notes << create(:note, note: "+1 I want this") + issue.notes << create(:note, note: "-1 This is bad") + issue.notes << create(:note, note: "+1 me too") + issue.downvotes_in_percent.should == 25 + end + end +end -- cgit v1.2.1 From e65731bb7ebf58366c185a10e50ec1db6eb495c4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 3 Jan 2013 09:12:24 +0200 Subject: Add concerns to autoload --- spec/lib/issue_commonality_spec.rb | 70 -------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 spec/lib/issue_commonality_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/issue_commonality_spec.rb b/spec/lib/issue_commonality_spec.rb deleted file mode 100644 index 11f278dea10..00000000000 --- a/spec/lib/issue_commonality_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -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) } - it { should validate_presence_of(:author) } - it { should validate_presence_of(:title) } - it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) } - it { should ensure_inclusion_of(:closed).in_array([true, false]) } - 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 -- cgit v1.2.1 From e16cebac3eaadc0df93576358f60ae4a498ce15f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Jan 2013 00:35:38 +0200 Subject: Fixed styles, ProjectHook specs etc --- spec/lib/extracts_path_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index 8773d77f5a5..deb6499e008 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -7,7 +7,7 @@ describe ExtractsPath do before do @project = project - project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']) + project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])) project.stub(path_with_namespace: 'gitlab/gitlab-ci') end -- cgit v1.2.1