diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-08-27 16:24:51 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-08-27 16:24:51 +0000 |
commit | 30555c1d24af25aca0c6e85f52234a8a570b7691 (patch) | |
tree | fd40fb02e465ae97db65d9e3fb89ba26bd8237ee /spec | |
parent | abb5b9f6e526195c4eb027d5b7c28e070d9ac3c1 (diff) | |
parent | ce0a0feff45b47b6c03b9ab01d815b651840a7b2 (diff) | |
download | gitlab-ce-30555c1d24af25aca0c6e85f52234a8a570b7691.tar.gz |
Merge branch 'rs-remove-user-color-scheme-class' into 'master'
Apply syntax highlighting to fenced code blocks client-side
Instead of applying the syntax highlighting scheme class to these blocks
server-side, we use Javascript and Gon to apply the user's color scheme
(or the default) client-side.
This will make it easier to cache these blocks in the future because
they're no longer state-dependent.
See merge request !1203
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/markdown_spec.rb | 8 | ||||
-rw-r--r-- | spec/helpers/events_helper_spec.rb | 5 | ||||
-rw-r--r-- | spec/helpers/preferences_helper_spec.rb | 92 | ||||
-rw-r--r-- | spec/lib/gitlab/color_schemes_spec.rb | 45 | ||||
-rw-r--r-- | spec/lib/gitlab/themes_spec.rb | 3 |
5 files changed, 100 insertions, 53 deletions
diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 3da4dfc2b23..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 @@ -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/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 = '<pre class="code highlight white plaintext"><code>' \ - 'Code block...</code></pre>' + expected = %r{<pre.+><code>Code block\.\.\.</code></pre>} 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 = '<pre class="code highlight white ruby">' \ + expected = '<pre class="code highlight js-syntax-highlight ruby">' \ "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \ " <span class=\"s1\">\'hello world\'</span>\n" \ "<span class=\"k\">end</span>" \ diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index d814b562113..06f69262b71 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -1,72 +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) - end + 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)) - 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) - end + expect(helper.user_color_scheme).to eq 'solarized-light' + end - it 'provides better option descriptions' do - expect(dashboard_choices).to match_array [ - ['Your Projects (default)', 'projects'], - ['Starred Projects', 'stars'] - ] + 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 - 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) + 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 - 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 + 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 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 |