discourse/spec/integrity/js_constants_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

28 lines
766 B
Ruby

# frozen_string_literal: true
describe "constants match ruby" do
let(:ctx) { MiniRacer::Context.new }
def parse(file)
# mini racer doesn't handle JS modules so we'll do this hack
source = File.read("#{Rails.root}/app/assets/javascripts/#{file}")
source.gsub!(/^export */, '')
ctx.eval(source)
end
it "has the correct values" do
parse("discourse/app/lib/constants.js")
parse("pretty-text/addon/emoji/version.js")
priorities = ctx.eval("SEARCH_PRIORITIES")
Searchable::PRIORITIES.each do |key, value|
expect(priorities[key.to_s]).to eq(value)
end
expect(ctx.eval("SEARCH_PHRASE_REGEXP")).to eq(Search::PHRASE_MATCH_REGEXP_PATTERN)
expect(ctx.eval("IMAGE_VERSION")).to eq(Emoji::EMOJI_VERSION)
end
end