From 3bdc57f0a710b3769381ecad7ea4098223ecff56 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Sat, 16 Apr 2016 21:09:08 +0200 Subject: Create table for award emoji --- spec/models/award_emoji_spec.rb | 31 ++++++++++++++++++++++++++++ spec/models/concerns/issuable_spec.rb | 14 ------------- spec/models/note_spec.rb | 39 ----------------------------------- 3 files changed, 31 insertions(+), 53 deletions(-) create mode 100644 spec/models/award_emoji_spec.rb (limited to 'spec/models') diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb new file mode 100644 index 00000000000..fd3712b7d43 --- /dev/null +++ b/spec/models/award_emoji_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe AwardEmoji, models: true do + describe 'Associations' do + it { is_expected.to belong_to(:awardable) } + it { is_expected.to belong_to(:user) } + end + + describe 'modules' do + it { is_expected.to include_module(Participable) } + end + + describe "validations" do + it { is_expected.to validate_presence_of(:awardable) } + it { is_expected.to validate_presence_of(:user) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_presence_of(:awardable) } + + # To circumvent a bug in the shoulda matchers + describe "scoped uniqueness validation" do + it "rejects duplicate award emoji" do + user = create(:user) + issue = create(:issue) + create(:award_emoji, user: user, awardable: issue) + new_award = AwardEmoji.new(user: user, awardable: issue, name: "thumbsup") + + expect(new_award).not_to be_valid + end + end + end +end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index b16ccc6e305..d5435916ea1 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -198,18 +198,4 @@ describe Issue, "Issuable" do to eq({ 'Author' => 'Robert', 'Assignee' => 'Douwe' }) end end - - describe "votes" do - before do - author = create :user - project = create :empty_project - issue.notes.awards.create!(note: "thumbsup", author: author, project: project) - issue.notes.awards.create!(note: "thumbsdown", author: author, project: project) - end - - it "returns correct values" do - expect(issue.upvotes).to eq(1) - expect(issue.downvotes).to eq(1) - end - end end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 6b18936edb1..bb591e9cb53 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -152,23 +152,6 @@ describe Note, models: true do end end - describe '.grouped_awards' do - before do - create :note, note: "smile", is_award: true - create :note, note: "smile", is_award: true - end - - it "returns grouped hash of notes" do - expect(Note.grouped_awards.keys.size).to eq(3) - expect(Note.grouped_awards["smile"]).to match_array(Note.all) - end - - it "returns thumbsup and thumbsdown always" do - expect(Note.grouped_awards["thumbsup"]).to match_array(Note.none) - expect(Note.grouped_awards["thumbsdown"]).to match_array(Note.none) - end - end - describe '#active?' do it 'is always true when the note has no associated diff' do note = build(:note) @@ -239,11 +222,6 @@ describe Note, models: true do note = build(:note, system: true) expect(note.editable?).to be_falsy end - - it "returns false" do - note = build(:note, is_award: true, note: "smiley") - expect(note.editable?).to be_falsy - end end describe "cross_reference_not_visible_for?" do @@ -270,23 +248,6 @@ describe Note, models: true do end end - describe "set_award!" do - let(:merge_request) { create :merge_request } - - it "converts aliases to actual name" do - note = create(:note, note: ":+1:", noteable: merge_request) - expect(note.reload.note).to eq("thumbsup") - end - - it "is not an award emoji when comment is on a diff" do - note = create(:note, note: ":blowfish:", noteable: merge_request, line_code: "11d5d2e667e9da4f7f610f81d86c974b146b13bd_0_2") - note = note.reload - - expect(note.note).to eq(":blowfish:") - expect(note.is_award?).to be_falsy - end - end - describe 'clear_blank_line_code!' do it 'clears a blank line code before validation' do note = build(:note, line_code: ' ') -- cgit v1.2.1 From dccf8a9fc8d4dde91942944f6b47387bfb13c380 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Mon, 25 Apr 2016 20:10:20 +0200 Subject: Add tests on Awardables and Award Emoji --- spec/models/concerns/awardable_spec.rb | 49 ++++++++++++++++++++++++++++++++++ spec/models/concerns/issuable_spec.rb | 4 +++ spec/models/user_spec.rb | 1 + 3 files changed, 54 insertions(+) create mode 100644 spec/models/concerns/awardable_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb new file mode 100644 index 00000000000..6851d068367 --- /dev/null +++ b/spec/models/concerns/awardable_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Issue, "Awardable" do + let!(:issue) { create(:issue) } + let!(:award_emoji) { create(:award_emoji, :downvote, awardable: issue) } + + describe "Associations" do + it { is_expected.to have_many(:award_emoji).dependent(:destroy) } + end + + describe "ClassMethods" do + let!(:issue2) { create(:issue) } + + before do + create(:award_emoji, awardable: issue2) + end + + it "orders on upvotes" do + expect(Issue.order_upvotes_desc.to_a).to eq [issue2, issue] + end + + it "orders on downvotes" do + expect(Issue.order_downvotes_desc.to_a).to eq [issue, issue2] + end + end + + describe "#upvotes" do + it "counts the number of upvotes" do + expect(issue.upvotes).to be 0 + end + end + + describe "#downvotes" do + it "counts the number of downvotes" do + expect(issue.downvotes).to be 1 + end + end + + describe "#toggle_award_emoji" do + it "adds an emoji if it isn't awarded yet" do + expect { issue.toggle_award_emoji("thumbsup", award_emoji.user) }.to change { AwardEmoji.count }.by 1 + end + + it "toggles already awarded emoji" do + + expect { issue.toggle_award_emoji("thumbsdown", award_emoji.user) }.to change { AwardEmoji.count }.by -1 + end + end +end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index d5435916ea1..86ad9de883f 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -12,6 +12,10 @@ describe Issue, "Issuable" do it { is_expected.to have_many(:todos).dependent(:destroy) } end + describe 'Included modules' do + it { is_expected.to include_module(Awardable) } + end + describe "Validation" do before do allow(subject).to receive(:set_iid).and_return(false) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8b2fb77e28e..de1a233dfff 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -93,6 +93,7 @@ describe User, models: true do it { is_expected.to have_one(:abuse_report) } it { is_expected.to have_many(:spam_logs).dependent(:destroy) } it { is_expected.to have_many(:todos).dependent(:destroy) } + it { is_expected.to have_many(:award_emoji).dependent(:destroy) } end describe 'validations' do -- cgit v1.2.1 From 4558b5b9fe9f648903ad0dc01089e6118fe0af34 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 11 May 2016 22:43:58 +0200 Subject: Incorporate feedback --- spec/models/concerns/issuable_spec.rb | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 568bf4c9324..ebc3968023d 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -203,11 +203,10 @@ describe Issue, "Issuable" do end end - # TODO ZJ describe "votes" do before do - create!(:award_emoji, :upvote, awardable: issue) - create!(:award_emoji, :downvote, awardable: issue) + create(:award_emoji, :upvote, awardable: issue) + create(:award_emoji, :downvote, awardable: issue) end it "returns correct values" do @@ -215,34 +214,4 @@ describe Issue, "Issuable" do expect(issue.downvotes).to eq(1) end end - - describe ".with_label" do - let(:project) { create(:project, :public) } - let(:bug) { create(:label, project: project, title: 'bug') } - let(:feature) { create(:label, project: project, title: 'feature') } - let(:enhancement) { create(:label, project: project, title: 'enhancement') } - let(:issue1) { create(:issue, title: "Bugfix1", project: project) } - let(:issue2) { create(:issue, title: "Bugfix2", project: project) } - let(:issue3) { create(:issue, title: "Feature1", project: project) } - - before(:each) do - issue1.labels << bug - issue1.labels << feature - issue2.labels << bug - issue2.labels << enhancement - issue3.labels << feature - end - - it 'finds the correct issue containing just enhancement label' do - expect(Issue.with_label(enhancement.title)).to match_array([issue2]) - end - - it 'finds the correct issues containing the same label' do - expect(Issue.with_label(bug.title)).to match_array([issue1, issue2]) - end - - it 'finds the correct issues containing only both labels' do - expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2]) - end - end end -- cgit v1.2.1 From 7a4e7ad04e1fc96953d9159e8e1a2208990d34f7 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 12 May 2016 09:23:21 +0200 Subject: Fix tests and wrong choices during merge --- spec/models/concerns/issuable_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index ebc3968023d..424b6f5e27f 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -214,4 +214,34 @@ describe Issue, "Issuable" do expect(issue.downvotes).to eq(1) end end + + describe ".with_label" do + let(:project) { create(:project, :public) } + let(:bug) { create(:label, project: project, title: 'bug') } + let(:feature) { create(:label, project: project, title: 'feature') } + let(:enhancement) { create(:label, project: project, title: 'enhancement') } + let(:issue1) { create(:issue, title: "Bugfix1", project: project) } + let(:issue2) { create(:issue, title: "Bugfix2", project: project) } + let(:issue3) { create(:issue, title: "Feature1", project: project) } + + before(:each) do + issue1.labels << bug + issue1.labels << feature + issue2.labels << bug + issue2.labels << enhancement + issue3.labels << feature + end + + it 'finds the correct issue containing just enhancement label' do + expect(Issue.with_label(enhancement.title)).to match_array([issue2]) + end + + it 'finds the correct issues containing the same label' do + expect(Issue.with_label(bug.title)).to match_array([issue1, issue2]) + end + + it 'finds the correct issues containing only both labels' do + expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2]) + end + end end -- cgit v1.2.1 From 6523002267e63e301693c141f6de2c6bbf6e2e73 Mon Sep 17 00:00:00 2001 From: ZJ van de Weg Date: Wed, 25 May 2016 15:43:07 +0200 Subject: Remove old tests, and use right factories --- spec/models/note_spec.rb | 60 ------------------------------------------------ 1 file changed, 60 deletions(-) (limited to 'spec/models') diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 4448eefad00..a3ab1b796be 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -113,66 +113,6 @@ describe Note, models: true do end end - describe '#active?' do - it 'is always true when the note has no associated diff' do - note = build(:note) - - expect(note).to receive(:diff).and_return(nil) - - expect(note).to be_active - end - - it 'is never true when the note has no noteable associated' do - note = build(:note) - - expect(note).to receive(:diff).and_return(double) - expect(note).to receive(:noteable).and_return(nil) - - expect(note).not_to be_active - end - - it 'returns the memoized value if defined' do - note = build(:note) - - expect(note).to receive(:diff).and_return(double) - expect(note).to receive(:noteable).and_return(double) - - note.instance_variable_set(:@active, 'foo') - expect(note).not_to receive(:find_noteable_diff) - - expect(note.active?).to eq 'foo' - end - - context 'for a merge request noteable' do - it 'is false when noteable has no matching diff' do - merge = build_stubbed(:merge_request, :simple) - note = build(:note, noteable: merge) - - allow(note).to receive(:diff).and_return(double) - expect(note).to receive(:find_noteable_diff).and_return(nil) - - expect(note).not_to be_active - end - - it 'is true when noteable has a matching diff' do - merge = create(:merge_request, :simple) - - # Generate a real line_code value so we know it will match. We use a - # random line from a random diff just for funsies. - diff = merge.diffs.to_a.sample - line = Gitlab::Diff::Parser.new.parse(diff.diff.each_line).to_a.sample - code = Gitlab::Diff::LineCode.generate(diff.new_path, line.new_pos, line.old_pos) - - # We're persisting in order to trigger the set_diff callback - note = create(:note, noteable: merge, line_code: code) - - # Make sure we don't get a false positive from a guard clause - expect(note).to receive(:find_noteable_diff).and_call_original - expect(note).to be_active - end - end - end - describe "editable?" do it "returns true" do note = build(:note) -- cgit v1.2.1 From d287315dbf1a1493e3f2c2511e559204cc914ff8 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Thu, 19 May 2016 13:55:25 -0500 Subject: Upgrade attr_encrypted and encryptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit attr_encrypted (1.3.4 => 3.0.1) Changelog: https://github.com/attr-encrypted/attr_encrypted/blob/master/CHANGELOG.m d attr_encrypted 2.x included a vulnerability, so that major version is skipped. 3.x requires that the algorithm and mode used by each encrypted attribute is specified explicitly. `nil` is no longer a valid value for the encrypted_value_iv field, so it’s changed to a randomly generated string. --- spec/models/ci/variable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index c712d211b0f..98f60087cf5 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -23,7 +23,7 @@ describe Ci::Variable, models: true do end it 'fails to decrypt if iv is incorrect' do - subject.encrypted_value_iv = nil + subject.encrypted_value_iv = SecureRandom.hex subject.instance_variable_set(:@value, nil) expect { subject.value }. to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt') -- cgit v1.2.1 From 91a7b9333b660abc866e52e1a614151cb529413d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 1 Jun 2016 11:23:09 +0200 Subject: Incorportate feedback --- spec/models/award_emoji_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb index fd3712b7d43..cb3c592f8cd 100644 --- a/spec/models/award_emoji_spec.rb +++ b/spec/models/award_emoji_spec.rb @@ -14,7 +14,6 @@ describe AwardEmoji, models: true do it { is_expected.to validate_presence_of(:awardable) } it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_presence_of(:awardable) } # To circumvent a bug in the shoulda matchers describe "scoped uniqueness validation" do @@ -22,7 +21,7 @@ describe AwardEmoji, models: true do user = create(:user) issue = create(:issue) create(:award_emoji, user: user, awardable: issue) - new_award = AwardEmoji.new(user: user, awardable: issue, name: "thumbsup") + new_award = build(:award_emoji, user: user, awardable: issue) expect(new_award).not_to be_valid end -- cgit v1.2.1 From 30aa64202b073e33834241589595a58a14080107 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 1 Jun 2016 09:56:06 -0700 Subject: Fix note validation spec failures --- spec/models/commit_range_spec.rb | 5 +++-- spec/models/note_spec.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb index 6bc496414a3..384a38ebc69 100644 --- a/spec/models/commit_range_spec.rb +++ b/spec/models/commit_range_spec.rb @@ -151,9 +151,10 @@ describe CommitRange, models: true do issue = create(:issue) create(:note_on_issue, - noteable_id: issue.id, + noteable: issue, system: true, - note: commit1.revert_description) + note: commit1.revert_description, + project: issue.project) expect_any_instance_of(Commit).to receive(:reverts_commit?). with(commit1). diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index b25150f7055..e9d89c9a847 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -154,7 +154,7 @@ describe Note, models: true do context "confidential issues" do let(:user) { create :user } let(:confidential_issue) { create(:issue, :confidential, author: user) } - let(:confidential_note) { create :note, note: "Random", noteable: confidential_issue } + let(:confidential_note) { create :note, note: "Random", noteable: confidential_issue, project: confidential_issue.project } it "returns notes with matching content if user can see the issue" do expect(described_class.search(confidential_note.note, as_user: user)).to eq([confidential_note]) -- cgit v1.2.1 From 6e58e7ff7ce151fb7a8329faef69cd3a42194216 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 1 Jun 2016 20:43:33 +0200 Subject: Use downcased path to container repository as this is expected path by Docker --- spec/models/project_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6c1b0393682..65f06b51794 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -792,6 +792,13 @@ describe Project, models: true do subject { project.container_registry_repository } it { is_expected.not_to be_nil } + + context 'for uppercase project path' do + let(:project) { create(:empty_project, path: 'PROJECT') } + + it { expect(subject.path).not_to end_with(project.path) } + it { expect(subject.path).to end_with(project.path.downcase) } + end end describe '#container_registry_repository_url' do @@ -810,6 +817,13 @@ describe Project, models: true do end it { is_expected.not_to be_nil } + + context 'for uppercase project path' do + let(:project) { create(:empty_project, path: 'PROJECT') } + + it { is_expected.not_to end_with(project.path) } + it { is_expected.to end_with(project.path.downcase) } + end end context 'for disabled registry' do -- cgit v1.2.1 From 77cb8ec4d14e3a8b03164423176b3b95977ee809 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 1 Jun 2016 22:57:50 +0200 Subject: Introduce container_registry_path_with_namespace --- spec/models/project_spec.rb | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 65f06b51794..338a4c3d3f0 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -784,6 +784,15 @@ describe Project, models: true do end end + describe '#container_registry_path_with_namespace' do + let(:project) { create(:empty_project, path: 'PROJECT') } + + subject { project.container_registry_path_with_namespace } + + it { is_expected.not_to eq(project.path_with_namespace) } + it { is_expected.to eq(project.path_with_namespace.downcase) } + end + describe '#container_registry_repository' do let(:project) { create(:empty_project) } @@ -792,13 +801,6 @@ describe Project, models: true do subject { project.container_registry_repository } it { is_expected.not_to be_nil } - - context 'for uppercase project path' do - let(:project) { create(:empty_project, path: 'PROJECT') } - - it { expect(subject.path).not_to end_with(project.path) } - it { expect(subject.path).to end_with(project.path.downcase) } - end end describe '#container_registry_repository_url' do @@ -817,13 +819,6 @@ describe Project, models: true do end it { is_expected.not_to be_nil } - - context 'for uppercase project path' do - let(:project) { create(:empty_project, path: 'PROJECT') } - - it { is_expected.not_to end_with(project.path) } - it { is_expected.to end_with(project.path.downcase) } - end end context 'for disabled registry' do -- cgit v1.2.1 From 0f3df62e1a42982ffb635dc5a9b201ed2520b0f4 Mon Sep 17 00:00:00 2001 From: Josh Frye Date: Thu, 2 Jun 2016 09:25:40 -0400 Subject: Update specs. Add CHANGELOG entry --- spec/models/issue_spec.rb | 17 +++++++++++++++++ spec/models/merge_request_spec.rb | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'spec/models') diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 87b3d8d650a..b87d68283e6 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -269,4 +269,21 @@ describe Issue, models: true do end end end + + describe 'cached counts' do + it 'updates when assignees change' do + user1 = create(:user) + user2 = create(:user) + issue = create(:issue, assignee: user1) + + expect(user1.assigned_open_issues_count).to eq(1) + expect(user2.assigned_open_issues_count).to eq(0) + + issue.assignee = user2 + issue.save + + expect(user1.assigned_open_issues_count).to eq(0) + expect(user2.assigned_open_issues_count).to eq(1) + end + end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 118e1e22a78..a4c55cc2fd0 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -438,4 +438,21 @@ describe MergeRequest, models: true do expect(mr.participants).to include(note1.author, note2.author) end end + + describe 'cached counts' do + it 'updates when assignees change' do + user1 = create(:user) + user2 = create(:user) + mr = create(:merge_request, assignee: user1) + + expect(user1.assigned_open_merge_request_count).to eq(1) + expect(user2.assigned_open_merge_request_count).to eq(0) + + mr.assignee = user2 + mr.save + + expect(user1.assigned_open_merge_request_count).to eq(0) + expect(user2.assigned_open_merge_request_count).to eq(1) + end + end end -- cgit v1.2.1 From 078ba8c090dd30cb4cad7ef6dc5380e2036e2e6a Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Thu, 2 Jun 2016 13:17:54 +0200 Subject: issuable#labels_array explicitly load the labels This will be useful when you want to ask for the number of items and later iterate over them, without needing to ask if the association is load or not. So you avoid extra database queries --- spec/models/concerns/issuable_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index fb20578d8d3..e9f827e9f50 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -227,6 +227,20 @@ describe Issue, "Issuable" do end end + describe '#labels_array' do + let(:project) { create(:project) } + let(:bug) { create(:label, project: project, title: 'bug') } + let(:issue) { create(:issue, project: project) } + + before(:each) do + issue.labels << bug + end + + it 'loads the association and returns it as an array' do + expect(issue.reload.labels_array).to eq([bug]) + end + end + describe "votes" do let(:project) { issue.project } -- cgit v1.2.1 From b75945e9e4718eb7c2b029b7fb7884eb2006fab1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 6 Jun 2016 07:42:12 +0200 Subject: Fix rubocop offense in awardable specs --- spec/models/concerns/awardable_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb index 6851d068367..a371c4a18a9 100644 --- a/spec/models/concerns/awardable_spec.rb +++ b/spec/models/concerns/awardable_spec.rb @@ -38,12 +38,11 @@ describe Issue, "Awardable" do describe "#toggle_award_emoji" do it "adds an emoji if it isn't awarded yet" do - expect { issue.toggle_award_emoji("thumbsup", award_emoji.user) }.to change { AwardEmoji.count }.by 1 + expect { issue.toggle_award_emoji("thumbsup", award_emoji.user) }.to change { AwardEmoji.count }.by(1) end it "toggles already awarded emoji" do - - expect { issue.toggle_award_emoji("thumbsdown", award_emoji.user) }.to change { AwardEmoji.count }.by -1 + expect { issue.toggle_award_emoji("thumbsdown", award_emoji.user) }.to change { AwardEmoji.count }.by(-1) end end end -- cgit v1.2.1 From 791cc9138be6ea1783e3c3853370cf0290f4d41e Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Mon, 6 Jun 2016 10:08:42 +0530 Subject: Add a `U2fRegistrations` table/model. - To hold registrations from U2F devices, and to authenticate them. - Previously, `User#two_factor_enabled` was aliased to the `otp_required_for_login` column on `users`. - This commit changes things a bit: - `User#two_factor_enabled` is not a method anymore - `User#two_factor_enabled?` checks both the `otp_required_for_login` column, as well as `U2fRegistration`s - Change all instances of `User#two_factor_enabled` to `User#two_factor_enabled?` - Add the `u2f` gem, and implement registration/authentication at the model level. --- spec/models/user_spec.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 528a79bf221..6ea8bf9bbe1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -121,6 +121,66 @@ describe User, models: true do end end + describe "scopes" do + describe ".with_two_factor" do + it "returns users with 2fa enabled via OTP" do + user_with_2fa = create(:user, :two_factor_via_otp) + user_without_2fa = create(:user) + users_with_two_factor = User.with_two_factor.pluck(:id) + + expect(users_with_two_factor).to include(user_with_2fa.id) + expect(users_with_two_factor).not_to include(user_without_2fa.id) + end + + it "returns users with 2fa enabled via U2F" do + user_with_2fa = create(:user, :two_factor_via_u2f) + user_without_2fa = create(:user) + users_with_two_factor = User.with_two_factor.pluck(:id) + + expect(users_with_two_factor).to include(user_with_2fa.id) + expect(users_with_two_factor).not_to include(user_without_2fa.id) + end + + it "returns users with 2fa enabled via OTP and U2F" do + user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) + user_without_2fa = create(:user) + users_with_two_factor = User.with_two_factor.pluck(:id) + + expect(users_with_two_factor).to eq([user_with_2fa.id]) + expect(users_with_two_factor).not_to include(user_without_2fa.id) + end + end + + describe ".without_two_factor" do + it "excludes users with 2fa enabled via OTP" do + user_with_2fa = create(:user, :two_factor_via_otp) + user_without_2fa = create(:user) + users_without_two_factor = User.without_two_factor.pluck(:id) + + expect(users_without_two_factor).to include(user_without_2fa.id) + expect(users_without_two_factor).not_to include(user_with_2fa.id) + end + + it "excludes users with 2fa enabled via U2F" do + user_with_2fa = create(:user, :two_factor_via_u2f) + user_without_2fa = create(:user) + users_without_two_factor = User.without_two_factor.pluck(:id) + + expect(users_without_two_factor).to include(user_without_2fa.id) + expect(users_without_two_factor).not_to include(user_with_2fa.id) + end + + it "excludes users with 2fa enabled via OTP and U2F" do + user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) + user_without_2fa = create(:user) + users_without_two_factor = User.without_two_factor.pluck(:id) + + expect(users_without_two_factor).to include(user_without_2fa.id) + expect(users_without_two_factor).not_to include(user_with_2fa.id) + end + end + end + describe "Respond to" do it { is_expected.to respond_to(:is_admin?) } it { is_expected.to respond_to(:name) } -- cgit v1.2.1