From 4d2f36118a3b21b6bb4ee702b98d032967ba463a Mon Sep 17 00:00:00 2001 From: Joel Koglin Date: Tue, 21 Jul 2015 14:03:26 -0700 Subject: Issue #993: Fixed login failure when extern_uid changes --- spec/lib/gitlab/ldap/user_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb index 7cfca96f4e0..84d9fb54b61 100644 --- a/spec/lib/gitlab/ldap/user_spec.rb +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -47,6 +47,28 @@ describe Gitlab::LDAP::User do expect(existing_user.ldap_identity.provider).to eql 'ldapmain' end + it 'connects to existing ldap user if the extern_uid changes' do + existing_user = create(:omniauth_user, email: 'john@example.com', extern_uid: 'old-uid', provider: 'ldapmain') + expect{ ldap_user.save }.not_to change{ User.count } + + existing_user.reload + expect(existing_user.ldap_identity.extern_uid).to eql 'my-uid' + expect(existing_user.ldap_identity.provider).to eql 'ldapmain' + expect(existing_user.id).to eql ldap_user.gl_user.id + end + + it 'maintains an identity per provider' do + existing_user = create(:omniauth_user, email: 'john@example.com', provider: 'twitter') + expect(existing_user.identities.count).to eql(1) + + ldap_user.save + expect(ldap_user.gl_user.identities.count).to eql(2) + + # Expect that find_by provider only returns a single instance of an identity and not an Enumerable + expect(ldap_user.gl_user.identities.find_by(provider: 'twitter')).to be_instance_of Identity + expect(ldap_user.gl_user.identities.find_by(provider: auth_hash.provider)).to be_instance_of Identity + end + it "creates a new user if not found" do expect{ ldap_user.save }.to change{ User.count }.by(1) end -- cgit v1.2.1 From 4344b8d2d4367b19c6849c3cab0d02d17ddf2304 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Aug 2015 14:31:33 -0700 Subject: Add Gitlab::ColorSchemes module Very similar to Gitlab::Theme, this contains all of the definitions for our syntax highlighting schemes. --- spec/lib/gitlab/color_schemes_spec.rb | 45 +++++++++++++++++++++++++++++++++++ spec/lib/gitlab/themes_spec.rb | 3 --- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 spec/lib/gitlab/color_schemes_spec.rb (limited to 'spec') diff --git a/spec/lib/gitlab/color_schemes_spec.rb b/spec/lib/gitlab/color_schemes_spec.rb new file mode 100644 index 00000000000..c7be45dbcd3 --- /dev/null +++ b/spec/lib/gitlab/color_schemes_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Gitlab::ColorSchemes do + describe '.body_classes' do + it 'returns a space-separated list of class names' do + css = described_class.body_classes + + expect(css).to include('white') + expect(css).to include(' solarized-light ') + expect(css).to include(' monokai') + end + end + + describe '.by_id' do + it 'returns a scheme by its ID' do + expect(described_class.by_id(1).name).to eq 'White' + expect(described_class.by_id(4).name).to eq 'Solarized Dark' + end + end + + describe '.default' do + it 'returns the default scheme' do + expect(described_class.default.id).to eq 1 + end + end + + describe '.each' do + it 'passes the block to the SCHEMES Array' do + ids = [] + described_class.each { |scheme| ids << scheme.id } + expect(ids).not_to be_empty + end + end + + describe '.for_user' do + it 'returns default when user is nil' do + expect(described_class.for_user(nil).id).to eq 1 + end + + it "returns user's preferred color scheme" do + user = double(color_scheme_id: 5) + expect(described_class.for_user(user).id).to eq 5 + end + end +end diff --git a/spec/lib/gitlab/themes_spec.rb b/spec/lib/gitlab/themes_spec.rb index 9c6c3fd8104..e554458e41c 100644 --- a/spec/lib/gitlab/themes_spec.rb +++ b/spec/lib/gitlab/themes_spec.rb @@ -43,9 +43,6 @@ describe Gitlab::Themes do ids = [] described_class.each { |theme| ids << theme.id } expect(ids).not_to be_empty - - # TODO (rspeicher): RSpec 3.x - # expect(described_class.each).to yield_with_arg(described_class::Theme) end end end -- cgit v1.2.1 From 2c3e42e4a44e2f40e521cbafc8144e5d7c366b76 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Aug 2015 15:24:53 -0700 Subject: Remove user_color_scheme_class Instead of rendering this value server-side, we use Javascript and Gon to apply the user's color scheme (or the default) to any syntax highlighted code blocks. This will make it easier to cache these blocks in the future because they're no longer state-dependent. --- spec/features/markdown_spec.rb | 4 ---- spec/helpers/preferences_helper_spec.rb | 21 --------------------- 2 files changed, 25 deletions(-) (limited to 'spec') diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 3da4dfc2b23..d32bd4adb52 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -224,8 +224,4 @@ describe 'GitLab Markdown', feature: true do def current_user @feat.user end - - def user_color_scheme_class - :white - end end diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index d814b562113..b4dee272bfd 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -48,25 +48,4 @@ describe PreferencesHelper do ] end end - - describe 'user_color_scheme_class' do - context 'with current_user is nil' do - it 'should return a string' do - allow(self).to receive(:current_user).and_return(nil) - expect(user_color_scheme_class).to be_kind_of(String) - end - end - - context 'with a current_user' do - (1..5).each do |color_scheme_id| - context "with color_scheme_id == #{color_scheme_id}" do - it 'should return a string' do - current_user = double(color_scheme_id: color_scheme_id) - allow(self).to receive(:current_user).and_return(current_user) - expect(user_color_scheme_class).to be_kind_of(String) - end - end - end - end - end end -- cgit v1.2.1 From c401543d02487888a71966518fa8cb4f17de1397 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Aug 2015 15:57:55 -0700 Subject: Fix failing spec --- spec/features/markdown_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index d32bd4adb52..4fe019f8342 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -64,8 +64,8 @@ describe 'GitLab Markdown', feature: true do it 'parses fenced code blocks' do aggregate_failures do - expect(doc).to have_selector('pre.code.highlight.white.c') - expect(doc).to have_selector('pre.code.highlight.white.python') + expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.c') + expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.python') end end -- cgit v1.2.1 From d6a145d4b0b8d2baa63f2c1699ba44ea203a4ae8 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Aug 2015 16:26:20 -0700 Subject: Fix two more failing specs --- spec/helpers/events_helper_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index da58ab98462..e68a5ec29ab 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -28,8 +28,7 @@ describe EventsHelper do it 'should display the first line of a code block' do input = "```\nCode block\nwith two lines\n```" - expected = '
' \
-               'Code block...
' + expected = %r{Code block\.\.\.} expect(event_note(input)).to match(expected) end @@ -55,7 +54,7 @@ describe EventsHelper do it 'should preserve code color scheme' do input = "```ruby\ndef test\n 'hello world'\nend\n```" - expected = '
' \
+    expected = '
' \
       "def test\n" \
       "  \'hello world\'\n" \
       "end" \
-- 
cgit v1.2.1


From 7a81dc65d9013dff4d8bf36cf78e027693703990 Mon Sep 17 00:00:00 2001
From: Robert Speicher 
Date: Wed, 26 Aug 2015 11:33:44 -0700
Subject: Re-add user_color_scheme helper

Update PreferencesHelper specs
---
 spec/helpers/preferences_helper_spec.rb | 77 +++++++++++++++++++++++----------
 1 file changed, 54 insertions(+), 23 deletions(-)

(limited to 'spec')

diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb
index b4dee272bfd..06f69262b71 100644
--- a/spec/helpers/preferences_helper_spec.rb
+++ b/spec/helpers/preferences_helper_spec.rb
@@ -1,51 +1,82 @@
 require 'spec_helper'
 
 describe PreferencesHelper do
+  describe 'dashboard_choices' do
+    it 'raises an exception when defined choices may be missing' do
+      expect(User).to receive(:dashboards).and_return(foo: 'foo')
+      expect { helper.dashboard_choices }.to raise_error(RuntimeError)
+    end
+
+    it 'raises an exception when defined choices may be using the wrong key' do
+      expect(User).to receive(:dashboards).and_return(foo: 'foo', bar: 'bar')
+      expect { helper.dashboard_choices }.to raise_error(KeyError)
+    end
+
+    it 'provides better option descriptions' do
+      expect(helper.dashboard_choices).to match_array [
+        ['Your Projects (default)', 'projects'],
+        ['Starred Projects',        'stars']
+      ]
+    end
+  end
+
   describe 'user_application_theme' do
     context 'with a user' do
       it "returns user's theme's css_class" do
-        user = double('user', theme_id: 3)
-        allow(self).to receive(:current_user).and_return(user)
-        expect(user_application_theme).to eq 'ui_green'
+        stub_user(theme_id: 3)
+
+        expect(helper.user_application_theme).to eq 'ui_green'
       end
 
       it 'returns the default when id is invalid' do
-        user = double('user', theme_id: Gitlab::Themes::THEMES.size + 5)
+        stub_user(theme_id: Gitlab::Themes.count + 5)
 
         allow(Gitlab.config.gitlab).to receive(:default_theme).and_return(2)
-        allow(self).to receive(:current_user).and_return(user)
 
-        expect(user_application_theme).to eq 'ui_charcoal'
+        expect(helper.user_application_theme).to eq 'ui_charcoal'
       end
     end
 
     context 'without a user' do
-      before do
-        allow(self).to receive(:current_user).and_return(nil)
-      end
-
       it 'returns the default theme' do
-        expect(user_application_theme).to eq Gitlab::Themes.default.css_class
+        stub_user
+
+        expect(helper.user_application_theme).to eq Gitlab::Themes.default.css_class
       end
     end
   end
 
-  describe 'dashboard_choices' do
-    it 'raises an exception when defined choices may be missing' do
-      expect(User).to receive(:dashboards).and_return(foo: 'foo')
-      expect { dashboard_choices }.to raise_error(RuntimeError)
+  describe 'user_color_scheme' do
+    context 'with a user' do
+      it "returns user's scheme's css_class" do
+        allow(helper).to receive(:current_user).
+          and_return(double(color_scheme_id: 3))
+
+        expect(helper.user_color_scheme).to eq 'solarized-light'
+      end
+
+      it 'returns the default when id is invalid' do
+        allow(helper).to receive(:current_user).
+          and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5))
+      end
     end
 
-    it 'raises an exception when defined choices may be using the wrong key' do
-      expect(User).to receive(:dashboards).and_return(foo: 'foo', bar: 'bar')
-      expect { dashboard_choices }.to raise_error(KeyError)
+    context 'without a user' do
+      it 'returns the default theme' do
+        stub_user
+
+        expect(helper.user_color_scheme).
+          to eq Gitlab::ColorSchemes.default.css_class
+      end
     end
+  end
 
-    it 'provides better option descriptions' do
-      expect(dashboard_choices).to match_array [
-        ['Your Projects (default)', 'projects'],
-        ['Starred Projects',        'stars']
-      ]
+  def stub_user(messages = {})
+    if messages.empty?
+      allow(helper).to receive(:current_user).and_return(nil)
+    else
+      allow(helper).to receive(:current_user).
+        and_return(double('user', messages))
     end
   end
 end
-- 
cgit v1.2.1


From ea5da30326a0515f98d7276c9cff239232cafed4 Mon Sep 17 00:00:00 2001
From: Douwe Maan 
Date: Wed, 26 Aug 2015 17:23:22 -0700
Subject: Don't notify users without access to the project when they are
 (accidentally) mentioned in a note.

---
 spec/services/notification_service_spec.rb | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'spec')

diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 9da6c9dc949..8865335d0d1 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -31,13 +31,16 @@ describe NotificationService do
 
   describe 'Notes' do
     context 'issue note' do
-      let(:project) { create(:empty_project, :public) }
+      let(:project) { create(:empty_project, :private) }
       let(:issue) { create(:issue, project: project, assignee: create(:user)) }
       let(:mentioned_issue) { create(:issue, assignee: issue.assignee) }
-      let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@mention referenced') }
+      let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @outsider also') }
 
       before do
         build_team(note.project)
+        project.team << [issue.author, :master]
+        project.team << [issue.assignee, :master]
+        project.team << [note.author, :master]
       end
 
       describe :new_note do
@@ -53,6 +56,7 @@ describe NotificationService do
           should_not_email(@u_participating.id)
           should_not_email(@u_disabled.id)
           should_not_email(@unsubscriber.id)
+          should_not_email(@u_outsider_mentioned)
 
           notification.new_note(note)
         end
@@ -444,12 +448,15 @@ describe NotificationService do
     @u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_MENTION)
     @u_committer = create(:user, username: 'committer')
     @u_not_mentioned = create(:user, username: 'regular', notification_level: Notification::N_PARTICIPATING)
+    @u_outsider_mentioned = create(:user, username: 'outsider')
 
     project.team << [@u_watcher, :master]
     project.team << [@u_participating, :master]
+    project.team << [@u_participant_mentioned, :master]
     project.team << [@u_disabled, :master]
     project.team << [@u_mentioned, :master]
     project.team << [@u_committer, :master]
+    project.team << [@u_not_mentioned, :master]
   end
 
   def add_users_with_subscription(project, issuable)
-- 
cgit v1.2.1


From 4340dd3eeb6fdda83b729c16cba29239b8ed9f43 Mon Sep 17 00:00:00 2001
From: Robert Speicher 
Date: Thu, 27 Aug 2015 13:09:01 -0700
Subject: Decouple Gitlab::Markdown from the GitlabMarkdownHelper

This module is now the sole source of knowledge for *how* we render
Markdown (and GFM).
---
 spec/features/markdown_spec.rb              |  2 +-
 spec/helpers/gitlab_markdown_helper_spec.rb | 22 ++++++----------------
 2 files changed, 7 insertions(+), 17 deletions(-)

(limited to 'spec')

diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb
index 4fe019f8342..c557a1061af 100644
--- a/spec/features/markdown_spec.rb
+++ b/spec/features/markdown_spec.rb
@@ -179,7 +179,7 @@ describe 'GitLab Markdown', feature: true do
     before(:all) do
       @feat = MarkdownFeature.new
 
-      # `gfm` helper depends on a `@project` variable
+      # `markdown` helper expects a `@project` variable
       @project = @feat.project
 
       @html = markdown(@feat.raw_markdown)
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index a42ccb9b501..d1ca2337a9b 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -19,10 +19,10 @@ describe GitlabMarkdownHelper do
     @project = project
   end
 
-  describe "#gfm" do
+  describe "#markdown" do
     it "should forward HTML options to links" do
-      expect(gfm("Fixed in #{commit.id}", { project: @project }, class: 'foo')).
-        to have_selector('a.gfm.foo')
+      expect(markdown("Fixed in #{commit.id}", project: @project)).
+        to have_selector('a.gfm')
     end
 
     describe "referencing multiple objects" do
@@ -30,17 +30,17 @@ describe GitlabMarkdownHelper do
 
       it "should link to the merge request" do
         expected = namespace_project_merge_request_path(project.namespace, project, merge_request)
-        expect(gfm(actual)).to match(expected)
+        expect(markdown(actual)).to match(expected)
       end
 
       it "should link to the commit" do
         expected = namespace_project_commit_path(project.namespace, project, commit)
-        expect(gfm(actual)).to match(expected)
+        expect(markdown(actual)).to match(expected)
       end
 
       it "should link to the issue" do
         expected = namespace_project_issue_path(project.namespace, project, issue)
-        expect(gfm(actual)).to match(expected)
+        expect(markdown(actual)).to match(expected)
       end
     end
   end
@@ -79,16 +79,6 @@ describe GitlabMarkdownHelper do
       expect(doc.css('a')[4].text).to eq ' for real'
     end
 
-    it 'should forward HTML options' do
-      actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo')
-      doc = Nokogiri::HTML.parse(actual)
-
-      expect(doc.css('a')).to satisfy do |v|
-        # 'foo' gets added to all links
-        v.all? { |a| a.attr('class').match(/foo$/) }
-      end
-    end
-
     it "escapes HTML passed in as the body" do
       actual = "This is a 

test

- see #{issues[0].to_reference}" expect(link_to_gfm(actual, commit_path)). -- cgit v1.2.1 From a4e4fde3e68a5c27e0424bdbe0dbd87d33a9e020 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 27 Aug 2015 14:28:45 -0700 Subject: Restore the forwarded HTML options in link_to_gfm --- spec/helpers/gitlab_markdown_helper_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index d1ca2337a9b..0f9c587432d 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -79,6 +79,16 @@ describe GitlabMarkdownHelper do expect(doc.css('a')[4].text).to eq ' for real' end + it 'should forward HTML options' do + actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') + doc = Nokogiri::HTML.parse(actual) + + expect(doc.css('a')).to satisfy do |v| + # 'foo' gets added to all links + v.all? { |a| a.attr('class').match(/foo$/) } + end + end + it "escapes HTML passed in as the body" do actual = "This is a

test

- see #{issues[0].to_reference}" expect(link_to_gfm(actual, commit_path)). -- cgit v1.2.1 From 8e7111f79de43ea5c8471f3e0bf6ac0c76dd3117 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 27 Aug 2015 15:36:26 -0700 Subject: Reference filters no longer take a custom class context option --- spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/commit_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/issue_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/label_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb | 5 ----- spec/lib/gitlab/markdown/user_reference_filter_spec.rb | 5 ----- 8 files changed, 40 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb index 58155284486..3c6c84a0416 100644 --- a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb @@ -75,11 +75,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-commit_range' end - it 'includes an optional custom class' do - doc = filter("See #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("See #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb index 05a02de4669..9ed438252b3 100644 --- a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb @@ -71,11 +71,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-commit' end - it 'includes an optional custom class' do - doc = filter("See #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("See #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb b/spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb index f16095bc2b2..d8c2970b6bd 100644 --- a/spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb @@ -68,11 +68,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue' end - it 'includes an optional custom class' do - doc = filter("Issue #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'supports an :only_path context' do doc = filter("Issue #{reference}", only_path: true) link = doc.css('a').first.attr('href') diff --git a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb index 35b1ba5f132..1dd54f58588 100644 --- a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb @@ -68,11 +68,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue' end - it 'includes an optional custom class' do - doc = filter("Issue #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("Issue #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb index fabe0411e46..e32089de376 100644 --- a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb @@ -25,11 +25,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-label' end - it 'includes an optional custom class' do - doc = filter("Label #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("Label #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb index 5cef52b1916..66616b93368 100644 --- a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb @@ -56,11 +56,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-merge_request' end - it 'includes an optional custom class' do - doc = filter("Merge #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("Merge #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb index 678b171e99e..fd3f0d20fad 100644 --- a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb @@ -55,11 +55,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-snippet' end - it 'includes an optional custom class' do - doc = filter("Snippet #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'includes a data-project-id attribute' do doc = filter("Snippet #{reference}") link = doc.css('a').first diff --git a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb index 02d923b036c..b2155fab59b 100644 --- a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb @@ -130,11 +130,6 @@ module Gitlab::Markdown expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project_member' end - it 'includes an optional custom class' do - doc = filter("Hey #{reference}", reference_class: 'custom') - expect(doc.css('a').first.attr('class')).to include 'custom' - end - it 'supports an :only_path context' do doc = filter("Hey #{reference}", only_path: true) link = doc.css('a').first.attr('href') -- cgit v1.2.1 From 39ee52f1b168f3c6d2c9f27a3311aa7c785a0b20 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 28 Aug 2015 10:23:56 +0200 Subject: Expire cache when merge request source branch was removed Signed-off-by: Dmitriy Zaporozhets --- spec/workers/merge_worker_spec.rb | 28 ++++++++++++++++++++++++++++ spec/workers/post_receive_spec.rb | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/workers/merge_worker_spec.rb (limited to 'spec') diff --git a/spec/workers/merge_worker_spec.rb b/spec/workers/merge_worker_spec.rb new file mode 100644 index 00000000000..b11c5de94e3 --- /dev/null +++ b/spec/workers/merge_worker_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe MergeWorker do + describe "remove source branch" do + let!(:merge_request) { create(:merge_request, source_branch: "markdown") } + let!(:source_project) { merge_request.source_project } + let!(:project) { merge_request.project } + let!(:author) { merge_request.author } + + before do + source_project.team << [author, :master] + source_project.repository.expire_branch_names + end + + it 'clears cache of source repo after removing source branch' do + expect(source_project.repository.branch_names).to include('markdown') + + MergeWorker.new.perform( + merge_request.id, merge_request.author_id, + commit_message: 'wow such merge', + should_remove_source_branch: true) + + merge_request.reload + expect(merge_request).to be_merged + expect(source_project.repository.branch_names).not_to include('markdown') + end + end +end diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 46eae9ab081..e4151b9bb6a 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -4,7 +4,7 @@ describe PostReceive do let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" } let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") } let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) } - + context "as a resque worker" do it "reponds to #perform" do expect(PostReceive.new).to respond_to(:perform) -- cgit v1.2.1 From 805693bfea900ed656524abeeb7dd2fb06520123 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 31 Aug 2015 16:22:14 -0400 Subject: Remove invalid spec for GitlabMarkdownHelper --- spec/helpers/gitlab_markdown_helper_spec.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'spec') diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 0f9c587432d..5639b3db913 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -20,11 +20,6 @@ describe GitlabMarkdownHelper do end describe "#markdown" do - it "should forward HTML options to links" do - expect(markdown("Fixed in #{commit.id}", project: @project)). - to have_selector('a.gfm') - end - describe "referencing multiple objects" do let(:actual) { "#{merge_request.to_reference} -> #{commit.to_reference} -> #{issue.to_reference}" } -- cgit v1.2.1 From 2930041886fb616bd98ba31627d0ce53e0f7603a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 31 Aug 2015 18:09:18 -0400 Subject: Make sure the `gfm` helper passes the required options This adds some duplication, but this helper is temporary. --- spec/features/gitlab_flavored_markdown_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/features/gitlab_flavored_markdown_spec.rb b/spec/features/gitlab_flavored_markdown_spec.rb index 0c1bc53cdb5..7852c39fee2 100644 --- a/spec/features/gitlab_flavored_markdown_spec.rb +++ b/spec/features/gitlab_flavored_markdown_spec.rb @@ -77,7 +77,7 @@ describe "GitLab Flavored Markdown", feature: true do it "should render details in issues#show" do visit namespace_project_issue_path(project.namespace, project, @issue) - expect(page).to have_link("@#{fred.username}") + expect(page).to have_link(fred.to_reference) end end -- cgit v1.2.1 From 2e9c922dd17d13e2cb20b214f00eb875c673dfdf Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 31 Aug 2015 17:03:09 -0700 Subject: Fix bug where only the first 15 Bitbucket issues would be imported. Also fix a number of issues where author/reporter names were not available. --- spec/lib/gitlab/bitbucket_import/client_spec.rb | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/bitbucket_import/client_spec.rb b/spec/lib/gitlab/bitbucket_import/client_spec.rb index dd450e9967b..dfe58637eee 100644 --- a/spec/lib/gitlab/bitbucket_import/client_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/client_spec.rb @@ -14,4 +14,38 @@ describe Gitlab::BitbucketImport::Client do expect(key).to be_kind_of(Symbol) end end + + context 'issues' do + let(:per_page) { 50 } + let(:count) { 95 } + let(:sample_issues) do + issues = [] + + count.times do |i| + issues << { local_id: i } + end + + issues + end + let(:first_sample_data) { { count: count, issues: sample_issues[0..per_page - 1] } } + let(:second_sample_data) { { count: count, issues: sample_issues[per_page..count] } } + let(:project_id) { 'namespace/repo' } + + it 'retrieves issues over a number of pages' do + stub_request(:get, + "https://bitbucket.org/api/1.0/repositories/#{project_id}/issues?limit=50&sort=utc_created_on&start=0"). + to_return(status: 200, + body: first_sample_data.to_json, + headers: {}) + + stub_request(:get, + "https://bitbucket.org/api/1.0/repositories/#{project_id}/issues?limit=50&sort=utc_created_on&start=50"). + to_return(status: 200, + body: second_sample_data.to_json, + headers: {}) + + issues = client.issues(project_id) + expect(issues.count).to eq(95) + end + end end -- cgit v1.2.1 From 263abda3fd7ddfb826cd17ae88fb47d0e1d67fae Mon Sep 17 00:00:00 2001 From: Kirilll Zaitsev Date: Thu, 27 Aug 2015 02:58:49 +0300 Subject: Drone CI service --- .../project_services/drone_ci_service_spec.rb | 107 +++++++++++++++++++++ spec/requests/api/services_spec.rb | 99 ++++++++----------- spec/support/services_shared_context.rb | 21 ++++ 3 files changed, 169 insertions(+), 58 deletions(-) create mode 100644 spec/models/project_services/drone_ci_service_spec.rb create mode 100644 spec/support/services_shared_context.rb (limited to 'spec') diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb new file mode 100644 index 00000000000..bad9a9e6e1a --- /dev/null +++ b/spec/models/project_services/drone_ci_service_spec.rb @@ -0,0 +1,107 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# template :boolean default(FALSE) +# push_events :boolean default(TRUE) +# issues_events :boolean default(TRUE) +# merge_requests_events :boolean default(TRUE) +# tag_push_events :boolean default(TRUE) +# note_events :boolean default(TRUE), not null +# + +require 'spec_helper' + +describe DroneCiService do + describe 'associations' do + it { is_expected.to belong_to(:project) } + it { is_expected.to have_one(:service_hook) } + end + + describe 'validations' do + context 'active' do + before { allow(subject).to receive(:activated?).and_return(true) } + + it { is_expected.to validate_presence_of(:token) } + it { is_expected.to validate_presence_of(:drone_url) } + it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) } + it { is_expected.to allow_value('http://ci.example.com').for(:drone_url) } + it { is_expected.not_to allow_value('token with spaces').for(:token) } + it { is_expected.not_to allow_value('token/with%spaces').for(:token) } + it { is_expected.not_to allow_value('this is not url').for(:drone_url) } + it { is_expected.not_to allow_value('http//noturl').for(:drone_url) } + it { is_expected.not_to allow_value('ftp://ci.example.com').for(:drone_url) } + end + + context 'inactive' do + before { allow(subject).to receive(:activated?).and_return(false) } + + it { is_expected.not_to validate_presence_of(:token) } + it { is_expected.not_to validate_presence_of(:drone_url) } + it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) } + it { is_expected.to allow_value('http://drone.example.com').for(:drone_url) } + it { is_expected.to allow_value('token with spaces').for(:token) } + it { is_expected.to allow_value('ftp://drone.example.com').for(:drone_url) } + end + end + + shared_context :drone_ci_service do + let(:drone) { DroneCiService.new } + let(:project) { create(:project, name: 'project') } + let(:path) { "#{project.namespace.path}/#{project.path}" } + let(:drone_url) { 'http://drone.example.com' } + let(:sha) { '2ab7834c' } + let(:branch) { 'dev' } + let(:token) { 'secret' } + let(:iid) { rand(1..9999) } + + before(:each) do + allow(drone).to receive_messages( + project_id: project.id, + project: project, + active: true, + drone_url: drone_url, + token: token + ) + end + end + + describe "service page/path methods" do + include_context :drone_ci_service + + # URL's + let(:commit_page) { "#{drone_url}/gitlab/#{path}/redirect/commits/#{sha}?branch=#{branch}" } + let(:merge_request_page) { "#{drone_url}/gitlab/#{path}/redirect/pulls/#{iid}" } + let(:commit_status_path) { "#{drone_url}/gitlab/#{path}/commits/#{sha}?branch=#{branch}&access_token=#{token}" } + let(:merge_request_status_path) { "#{drone_url}/gitlab/#{path}/pulls/#{iid}?access_token=#{token}" } + + it { expect(drone.build_page(sha, branch)).to eq(commit_page) } + it { expect(drone.commit_page(sha, branch)).to eq(commit_page) } + it { expect(drone.merge_request_page(iid, sha, branch)).to eq(merge_request_page) } + it { expect(drone.commit_status_path(sha, branch)).to eq(commit_status_path) } + it { expect(drone.merge_request_status_path(iid, sha, branch)).to eq(merge_request_status_path) } + end + + describe "execute" do + include_context :drone_ci_service + + let(:user) { create(:user, username: 'username') } + let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + + it do + service_hook = double + expect(service_hook).to receive(:execute) + expect(drone).to receive(:service_hook).and_return(service_hook) + + drone.execute(push_sample_data) + end + end +end diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 6d29a28580a..c297904614a 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -5,64 +5,47 @@ describe API::API, api: true do let(:user) { create(:user) } let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } - describe "POST /projects/:id/services/gitlab-ci" do - it "should update gitlab-ci settings" do - put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secrettoken', project_url: "http://ci.example.com/projects/1" - - expect(response.status).to eq(200) - end - - it "should return if required fields missing" do - put api("/projects/#{project.id}/services/gitlab-ci", user), project_url: "http://ci.example.com/projects/1", active: true - - expect(response.status).to eq(400) - end - - it "should return if the format of token is invalid" do - put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "http://ci.example.com/projects/1", active: true - - expect(response.status).to eq(404) - end - - it "should return if the format of token is invalid" do - put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "ftp://ci.example/projects/1", active: true - - expect(response.status).to eq(404) - end - end - - describe "DELETE /projects/:id/services/gitlab-ci" do - it "should update gitlab-ci settings" do - delete api("/projects/#{project.id}/services/gitlab-ci", user) - - expect(response.status).to eq(200) - expect(project.gitlab_ci_service).to be_nil - end - end - - describe 'PUT /projects/:id/services/hipchat' do - it 'should update hipchat settings' do - put api("/projects/#{project.id}/services/hipchat", user), - token: 'secret-token', room: 'test' - - expect(response.status).to eq(200) - expect(project.hipchat_service).not_to be_nil - end - - it 'should return if required fields missing' do - put api("/projects/#{project.id}/services/gitlab-ci", user), - token: 'secret-token', active: true - - expect(response.status).to eq(400) - end - end - - describe 'DELETE /projects/:id/services/hipchat' do - it 'should delete hipchat settings' do - delete api("/projects/#{project.id}/services/hipchat", user) - - expect(response.status).to eq(200) - expect(project.hipchat_service).to be_nil + Service.available_services_names.each do |service| + describe "PUT /projects/:id/services/#{service.dasherize}" do + include_context service + + it "should update #{service} settings" do + put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs + + expect(response.status).to eq(200) + end + + it "should return if required fields missing" do + attrs = service_attrs + + required_attributes = service_attrs_list.select do |attr| + service_klass.validators_on(attr).any? do |v| + v.class == ActiveRecord::Validations::PresenceValidator + end + end + + if required_attributes.empty? + expected_code = 200 + else + attrs.delete(required_attributes.shuffle.first) + expected_code = 400 + end + + put api("/projects/#{project.id}/services/#{dashed_service}", user), attrs + + expect(response.status).to eq(expected_code) + end + end + + describe "DELETE /projects/:id/services/#{service.dasherize}" do + include_context service + + it "should delete #{service}" do + delete api("/projects/#{project.id}/services/#{dashed_service}", user) + + expect(response.status).to eq(200) + expect(project.send(service_method).activated?).to be_falsey + end end end end diff --git a/spec/support/services_shared_context.rb b/spec/support/services_shared_context.rb new file mode 100644 index 00000000000..4d007ae55ee --- /dev/null +++ b/spec/support/services_shared_context.rb @@ -0,0 +1,21 @@ +Service.available_services_names.each do |service| + shared_context service do + let(:dashed_service) { service.dasherize } + let(:service_method) { "#{service}_service".to_sym } + let(:service_klass) { "#{service}_service".classify.constantize } + let(:service_attrs_list) { service_klass.new.fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } } + let(:service_attrs) do + service_attrs_list.inject({}) do |hash, k| + if k =~ /^(token*|.*_token|.*_key)/ + hash.merge!(k => 'secrettoken') + elsif k =~ /^(.*_url|url|webhook)/ + hash.merge!(k => "http://example.com") + elsif service == 'irker' && k == :recipients + hash.merge!(k => 'irc://irc.network.net:666/#channel') + else + hash.merge!(k => "someword") + end + end + end + end +end -- cgit v1.2.1 From 551157960e70363d35a9b24d79780c9b98c9ef3b Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 1 Sep 2015 23:28:48 -0700 Subject: Remove the filename argument from Content-Disposition header to avoid RFC 5987 and RFC 6266 encoding issues. This change allows the browser to determine the filename based on the URL. See: http://greenbytes.de/tech/tc2231/ Closes https://github.com/gitlabhq/gitlabhq/issues/9595 Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/1829 --- spec/controllers/projects/raw_controller_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/controllers/projects/raw_controller_spec.rb (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb new file mode 100644 index 00000000000..1f921d5f05d --- /dev/null +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Projects::RawController do + let(:public_project) { create(:project, :public) } + + describe "#show" do + context 'regular filename' do + let(:id) { 'master/README.md' } + + it 'delivers ASCII file' do + get(:show, + namespace_id: public_project.namespace.to_param, + project_id: public_project.to_param, + id: id) + + expect(response.status).to eq(200) + expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') + expect(response.header['Content-Disposition']). + to eq("inline") + end + end + end +end -- cgit v1.2.1 From 8ec59bd18bcacf13c012a34b3e37c2c9167bcc65 Mon Sep 17 00:00:00 2001 From: "Artem V. Navrotskiy" Date: Sat, 29 Aug 2015 12:52:21 +0300 Subject: Add API method for get user by ID of an SSH key --- spec/requests/api/keys_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/requests/api/keys_spec.rb (limited to 'spec') diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb new file mode 100644 index 00000000000..d2b87f88712 --- /dev/null +++ b/spec/requests/api/keys_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:admin) { create(:admin) } + let(:key) { create(:key, user: user) } + let(:email) { create(:email, user: user) } + + describe 'GET /keys/:uid' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + get api("/keys/#{key.id}") + expect(response.status).to eq(401) + end + end + + context 'when authenticated' do + it 'should return 404 for non-existing key' do + get api('/keys/999999', admin) + expect(response.status).to eq(404) + expect(json_response['message']).to eq('404 Not found') + end + + it 'should return single ssh key with user information' do + user.keys << key + user.save + get api("/keys/#{key.id}", admin) + expect(response.status).to eq(200) + expect(json_response['title']).to eq(key.title) + expect(json_response['user']['id']).to eq(user.id) + expect(json_response['user']['username']).to eq(user.username) + end + end + end +end -- cgit v1.2.1 From 6bd3d72bbdf288ecf2eee718f2943821c1401a22 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Thu, 3 Sep 2015 18:44:58 +0300 Subject: added spinach for glabal labels --- spec/services/projects/create_service_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index 66cdfd5d758..ff4ed2dd484 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -17,6 +17,14 @@ describe Projects::CreateService do expect(project.services).not_to be_empty end + it 'creates labels on Project creation if there are templates' do + Label.create(title: "bug", template: true) + project = create_project(@user, @opts) + project.reload + + expect(project.labels).not_to be_empty + end + context 'user namespace' do before do @project = create_project(@user, @opts) -- cgit v1.2.1 From 4144c59941e8e91bbaff2c68e757af0f01f7997d Mon Sep 17 00:00:00 2001 From: pilsner Date: Thu, 3 Sep 2015 18:55:43 +0900 Subject: add Content-Type header of raw image file Add Content-Type header to fix a bug which IE can't show image in markdown when the image is from raw. modified: CHANGELOG modified: app/controllers/projects/raw_controller.rb modified: spec/controllers/projects/raw_controller_spec.rb --- spec/controllers/projects/raw_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 1f921d5f05d..c114f342021 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -19,5 +19,19 @@ describe Projects::RawController do to eq("inline") end end + + context 'image header' do + let(:id) { 'master/files/images/6049019_460s.jpg' } + + it 'set image content type header' do + get(:show, + namespace_id: public_project.namespace.to_param, + project_id: public_project.to_param, + id: id) + + expect(response.status).to eq(200) + expect(response.header['Content-Type']).to eq('image/jpeg') + end + end end end -- cgit v1.2.1 From 38f1d571fe17725d437dae2f6c4f18006117ef9d Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 4 Sep 2015 16:35:01 -0400 Subject: Remove style attribute from textarea during ZenMode activation Closes internal https://dev.gitlab.org/gitlab/gitlabhq/issues/2466 --- spec/javascripts/zen_mode_spec.js.coffee | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/javascripts/zen_mode_spec.js.coffee b/spec/javascripts/zen_mode_spec.js.coffee index 1f4ea58ad48..4cb3836755f 100644 --- a/spec/javascripts/zen_mode_spec.js.coffee +++ b/spec/javascripts/zen_mode_spec.js.coffee @@ -29,6 +29,11 @@ describe 'ZenMode', -> enterZen() expect(Mousetrap.pause).toHaveBeenCalled() + it 'removes textarea styling', -> + $('textarea').attr('style', 'height: 400px') + enterZen() + expect('textarea').not.toHaveAttr('style') + describe 'in use', -> beforeEach -> enterZen() -- cgit v1.2.1 From d7812a95cf518dfa1565a0514b87fb40f86949e5 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 6 Sep 2015 07:48:48 -0700 Subject: Re-annotate models --- spec/factories/abuse_reports.rb | 12 ++++ spec/factories/merge_requests.rb | 1 + spec/factories/notes.rb | 1 + spec/models/abuse_report_spec.rb | 12 ++++ spec/models/application_setting_spec.rb | 1 + spec/models/issue_spec.rb | 27 ++++---- spec/models/merge_request_spec.rb | 1 + spec/models/note_spec.rb | 1 + spec/models/user_spec.rb | 108 +++++++++++++++----------------- 9 files changed, 95 insertions(+), 69 deletions(-) (limited to 'spec') diff --git a/spec/factories/abuse_reports.rb b/spec/factories/abuse_reports.rb index 29fcbc5e197..8d287ded292 100644 --- a/spec/factories/abuse_reports.rb +++ b/spec/factories/abuse_reports.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: abuse_reports +# +# id :integer not null, primary key +# reporter_id :integer +# user_id :integer +# message :text +# created_at :datetime +# updated_at :datetime +# + # Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 3b7adfe4398..6080d0ccdef 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -19,6 +19,7 @@ # description :text # position :integer default(0) # locked_at :datetime +# updated_by_id :integer # FactoryGirl.define do diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index e1009d5916e..9d777ddfccd 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -15,6 +15,7 @@ # noteable_id :integer # system :boolean default(FALSE), not null # st_diff :text +# updated_by_id :integer # require_relative '../support/repo_helpers' diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index d83004a8388..635a6e2518c 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: abuse_reports +# +# id :integer not null, primary key +# reporter_id :integer +# user_id :integer +# message :text +# created_at :datetime +# updated_at :datetime +# + require 'rails_helper' RSpec.describe AbuseReport, type: :model do diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index bc14ff98fd8..de0b2ef4cda 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -22,6 +22,7 @@ # user_oauth_applications :boolean default(TRUE) # after_sign_out_path :string(255) # session_expire_delay :integer default(10080), not null +# import_sources :text # require 'spec_helper' diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 9bac451c28c..cf336d82957 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -2,19 +2,20 @@ # # Table name: issues # -# id :integer not null, primary key -# title :string(255) -# assignee_id :integer -# author_id :integer -# project_id :integer -# created_at :datetime -# updated_at :datetime -# position :integer default(0) -# branch_name :string(255) -# description :text -# milestone_id :integer -# state :string(255) -# iid :integer +# id :integer not null, primary key +# title :string(255) +# assignee_id :integer +# author_id :integer +# project_id :integer +# created_at :datetime +# updated_at :datetime +# position :integer default(0) +# branch_name :string(255) +# description :text +# milestone_id :integer +# state :string(255) +# iid :integer +# updated_by_id :integer # require 'spec_helper' diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index b91687bc09f..17a49013d25 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -19,6 +19,7 @@ # description :text # position :integer default(0) # locked_at :datetime +# updated_by_id :integer # require 'spec_helper' diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 331505a01b3..3a0b194ba1e 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -15,6 +15,7 @@ # noteable_id :integer # system :boolean default(FALSE), not null # st_diff :text +# updated_by_id :integer # require 'spec_helper' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a46e789eab4..eeb9069aa17 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,62 +2,58 @@ # # Table name: users # -# id :integer not null, primary key -# email :string(255) default(""), not null -# encrypted_password :string(255) default(""), not null -# reset_password_token :string(255) -# reset_password_sent_at :datetime -# remember_created_at :datetime -# sign_in_count :integer default(0) -# current_sign_in_at :datetime -# last_sign_in_at :datetime -# current_sign_in_ip :string(255) -# last_sign_in_ip :string(255) -# created_at :datetime -# updated_at :datetime -# name :string(255) -# admin :boolean default(FALSE), not null -# projects_limit :integer default(10) -# skype :string(255) default(""), not null -# linkedin :string(255) default(""), not null -# twitter :string(255) default(""), not null -# authentication_token :string(255) -# theme_id :integer default(1), not null -# bio :string(255) -# failed_attempts :integer default(0) -# locked_at :datetime -# username :string(255) -# can_create_group :boolean default(TRUE), not null -# can_create_team :boolean default(TRUE), not null -# state :string(255) -# color_scheme_id :integer default(1), not null -# notification_level :integer default(1), not null -# password_expires_at :datetime -# created_by_id :integer -# last_credential_check_at :datetime -# avatar :string(255) -# confirmation_token :string(255) -# confirmed_at :datetime -# confirmation_sent_at :datetime -# unconfirmed_email :string(255) -# hide_no_ssh_key :boolean default(FALSE) -# website_url :string(255) default(""), not null -# github_access_token :string(255) -# gitlab_access_token :string(255) -# notification_email :string(255) -# hide_no_password :boolean default(FALSE) -# password_automatically_set :boolean default(FALSE) -# bitbucket_access_token :string(255) -# bitbucket_access_token_secret :string(255) -# location :string(255) -# encrypted_otp_secret :string(255) -# encrypted_otp_secret_iv :string(255) -# encrypted_otp_secret_salt :string(255) -# otp_required_for_login :boolean default(FALSE), not null -# otp_backup_codes :text -# public_email :string(255) default(""), not null -# dashboard :integer default(0) -# project_view :integer default(0) +# id :integer not null, primary key +# email :string(255) default(""), not null +# encrypted_password :string(255) default(""), not null +# reset_password_token :string(255) +# reset_password_sent_at :datetime +# remember_created_at :datetime +# sign_in_count :integer default(0) +# current_sign_in_at :datetime +# last_sign_in_at :datetime +# current_sign_in_ip :string(255) +# last_sign_in_ip :string(255) +# created_at :datetime +# updated_at :datetime +# name :string(255) +# admin :boolean default(FALSE), not null +# projects_limit :integer default(10) +# skype :string(255) default(""), not null +# linkedin :string(255) default(""), not null +# twitter :string(255) default(""), not null +# authentication_token :string(255) +# theme_id :integer default(1), not null +# bio :string(255) +# failed_attempts :integer default(0) +# locked_at :datetime +# username :string(255) +# can_create_group :boolean default(TRUE), not null +# can_create_team :boolean default(TRUE), not null +# state :string(255) +# color_scheme_id :integer default(1), not null +# notification_level :integer default(1), not null +# password_expires_at :datetime +# created_by_id :integer +# last_credential_check_at :datetime +# avatar :string(255) +# confirmation_token :string(255) +# confirmed_at :datetime +# confirmation_sent_at :datetime +# unconfirmed_email :string(255) +# hide_no_ssh_key :boolean default(FALSE) +# website_url :string(255) default(""), not null +# notification_email :string(255) +# hide_no_password :boolean default(FALSE) +# password_automatically_set :boolean default(FALSE) +# location :string(255) +# encrypted_otp_secret :string(255) +# encrypted_otp_secret_iv :string(255) +# encrypted_otp_secret_salt :string(255) +# otp_required_for_login :boolean default(FALSE), not null +# otp_backup_codes :text +# public_email :string(255) default(""), not null +# dashboard :integer default(0) +# project_view :integer default(0) # require 'spec_helper' -- cgit v1.2.1 From e156f42079ebf8247b6a39fa6314d4d5c6b73d12 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Tue, 4 Aug 2015 18:21:12 -0400 Subject: FogBugz project import --- spec/controllers/import/fogbugz_controller_spec.rb | 39 +++++++++++++ spec/services/projects/download_service_spec.rb | 65 ++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 spec/controllers/import/fogbugz_controller_spec.rb create mode 100644 spec/services/projects/download_service_spec.rb (limited to 'spec') diff --git a/spec/controllers/import/fogbugz_controller_spec.rb b/spec/controllers/import/fogbugz_controller_spec.rb new file mode 100644 index 00000000000..27b11267d2a --- /dev/null +++ b/spec/controllers/import/fogbugz_controller_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' +require_relative 'import_spec_helper' + +describe Import::FogbugzController do + include ImportSpecHelper + + let(:user) { create(:user) } + + before do + sign_in(user) + end + + describe 'GET status' do + before do + @repo = OpenStruct.new(name: 'vim') + stub_client(valid?: true) + end + + it 'assigns variables' do + @project = create(:project, import_type: 'fogbugz', creator_id: user.id) + stub_client(repos: [@repo]) + + get :status + + expect(assigns(:already_added_projects)).to eq([@project]) + expect(assigns(:repos)).to eq([@repo]) + end + + it 'does not show already added project' do + @project = create(:project, import_type: 'fogbugz', creator_id: user.id, import_source: 'vim') + stub_client(repos: [@repo]) + + get :status + + expect(assigns(:already_added_projects)).to eq([@project]) + expect(assigns(:repos)).to eq([]) + end + end +end diff --git a/spec/services/projects/download_service_spec.rb b/spec/services/projects/download_service_spec.rb new file mode 100644 index 00000000000..f12e09c58c3 --- /dev/null +++ b/spec/services/projects/download_service_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe Projects::DownloadService do + describe 'File service' do + before do + @user = create :user + @project = create :project, creator_id: @user.id, namespace: @user.namespace + end + + context 'for a URL that is not on whitelist' do + before do + url = 'https://code.jquery.com/jquery-2.1.4.min.js' + @link_to_file = download_file(@project, url) + end + + it { expect(@link_to_file).to eq(nil) } + end + + context 'for URLs that are on the whitelist' do + before do + sham_rack_app = ShamRack.at('mycompany.fogbugz.com').stub + sham_rack_app.register_resource('/rails_sample.jpg', File.read(Rails.root + 'spec/fixtures/rails_sample.jpg'), 'image/jpg') + sham_rack_app.register_resource('/doc_sample.txt', File.read(Rails.root + 'spec/fixtures/doc_sample.txt'), 'text/plain') + end + + after do + ShamRack.unmount_all + end + + context 'an image file' do + before do + url = 'http://mycompany.fogbugz.com/rails_sample.jpg' + @link_to_file = download_file(@project, url) + end + + it { expect(@link_to_file).to have_key('alt') } + it { expect(@link_to_file).to have_key('url') } + it { expect(@link_to_file).to have_key('is_image') } + it { expect(@link_to_file['is_image']).to be true } + it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file['url']).to match('rails_sample.jpg') } + it { expect(@link_to_file['alt']).to eq('rails_sample') } + end + + context 'a txt file' do + before do + url = 'http://mycompany.fogbugz.com/doc_sample.txt' + @link_to_file = download_file(@project, url) + end + + it { expect(@link_to_file).to have_key('alt') } + it { expect(@link_to_file).to have_key('url') } + it { expect(@link_to_file).to have_key('is_image') } + it { expect(@link_to_file['is_image']).to be false } + it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file['url']).to match('doc_sample.txt') } + it { expect(@link_to_file['alt']).to eq('doc_sample.txt') } + end + end + end + + def download_file(repository, url) + Projects::DownloadService.new(repository, url).execute + end +end -- cgit v1.2.1