|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "Settings Syntax Highlights", type: :request do |
| 4 | + let(:default_syntax_highlight) { Settings::SyntaxHighlight.default } |
| 5 | + |
| 6 | + def random_syntax_highlight |
| 7 | + (Settings::SyntaxHighlight.all - [default_syntax_highlight]).sample |
| 8 | + end |
| 9 | + |
| 10 | + describe "GET syntax_highlights#show" do |
| 11 | + it "renders the syntax highlight" do |
| 12 | + get settings_syntax_highlight_path |
| 13 | + |
| 14 | + expect(response).to have_http_status(:ok) |
| 15 | + end |
| 16 | + |
| 17 | + it "renders when session syntax highlight is set" do |
| 18 | + patch settings_syntax_highlight_path(settings: {syntax_highlight_name: random_syntax_highlight.name}) |
| 19 | + |
| 20 | + get settings_syntax_highlight_path |
| 21 | + |
| 22 | + expect(response).to have_http_status(:ok) |
| 23 | + end |
| 24 | + |
| 25 | + it "renders when preview params are set" do |
| 26 | + get settings_syntax_highlight_path(settings: {syntax_highlight_name: random_syntax_highlight.name}) |
| 27 | + |
| 28 | + expect(response).to have_http_status(:ok) |
| 29 | + end |
| 30 | + |
| 31 | + it "renders the syntax highlight for css format" do |
| 32 | + get settings_syntax_highlight_path(format: :css) |
| 33 | + |
| 34 | + aggregate_failures do |
| 35 | + expect(response).to have_http_status(:ok) |
| 36 | + expect(response.body).to match(%r{#{default_syntax_highlight.background_color}}i) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + it "renders for css format when session syntax highlight is set" do |
| 41 | + syntax_highlight = random_syntax_highlight |
| 42 | + patch settings_syntax_highlight_path(settings: {syntax_highlight_name: syntax_highlight.name}) |
| 43 | + |
| 44 | + get settings_syntax_highlight_path(format: :css) |
| 45 | + |
| 46 | + aggregate_failures do |
| 47 | + expect(response).to have_http_status(:ok) |
| 48 | + expect(response.body).to match(%r{#{syntax_highlight.background_color}}i) |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + it "renders for css format when preview params are set" do |
| 53 | + syntax_highlight = random_syntax_highlight |
| 54 | + get settings_syntax_highlight_path(settings: {syntax_highlight_name: syntax_highlight.name}, format: :css) |
| 55 | + |
| 56 | + aggregate_failures do |
| 57 | + expect(response).to have_http_status(:ok) |
| 58 | + expect(response.body).to match(%r{#{syntax_highlight.background_color}}i) |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + describe "PATCH syntax_highlights#update" do |
| 64 | + let(:syntax_highlight) { random_syntax_highlight } |
| 65 | + |
| 66 | + it "updates custom syntax highlight" do |
| 67 | + get settings_syntax_highlight_path(format: :css) |
| 68 | + |
| 69 | + aggregate_failures do |
| 70 | + expect(response.body).not_to match(%r{#{syntax_highlight.background_color}}i) |
| 71 | + expect(response.body).to match(%r{#{default_syntax_highlight.background_color}}i) |
| 72 | + end |
| 73 | + |
| 74 | + patch settings_syntax_highlight_path(settings: {syntax_highlight_name: syntax_highlight.name}) |
| 75 | + |
| 76 | + expect(response).to have_http_status(:see_other) |
| 77 | + |
| 78 | + get settings_syntax_highlight_path(format: :css) |
| 79 | + |
| 80 | + aggregate_failures do |
| 81 | + expect(response.body).to match(%r{#{syntax_highlight.background_color}}i) |
| 82 | + expect(response.body).not_to match(%r{#{default_syntax_highlight.background_color}}i) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + it "deletes custom syntax highlight when set to default" do |
| 87 | + patch settings_syntax_highlight_path(settings: {syntax_highlight_name: syntax_highlight.name}) |
| 88 | + |
| 89 | + get settings_syntax_highlight_path(format: :css) |
| 90 | + |
| 91 | + expect(response.body).to match(%r{#{syntax_highlight.background_color}}i) |
| 92 | + |
| 93 | + default_syntax_highlight = Settings::SyntaxHighlight.default |
| 94 | + |
| 95 | + patch settings_syntax_highlight_path(settings: {syntax_highlight_name: default_syntax_highlight.name}) |
| 96 | + |
| 97 | + get settings_syntax_highlight_path(format: :css) |
| 98 | + |
| 99 | + aggregate_failures do |
| 100 | + expect(response.body).not_to match(%r{#{syntax_highlight.background_color}}i) |
| 101 | + expect(response.body).to match(%r{#{default_syntax_highlight.background_color}}i) |
| 102 | + end |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments