discourse/spec/controllers/admin/staff_action_logs_controller_spec.rb
Sam 946f25098f Refactor theme fields so they support custom theme defined vars
This paves the way to allowing themes to specify uploads and so on.
2017-05-02 16:02:14 -04:00

43 lines
1.2 KiB
Ruby

require 'rails_helper'
describe Admin::StaffActionLogsController do
it "is a subclass of AdminController" do
expect(Admin::StaffActionLogsController < Admin::AdminController).to eq(true)
end
let!(:user) { log_in(:admin) }
context '.index' do
it 'works' do
xhr :get, :index
expect(response).to be_success
expect(::JSON.parse(response.body)).to be_a(Array)
end
end
context '.diff' do
it 'can generate diffs for theme changes' do
theme = Theme.new(user_id: -1, name: 'bob')
theme.set_field(target: :mobile, name: :scss, value: 'body {.up}')
theme.set_field(target: :common, name: :scss, value: 'omit-dupe')
original_json = ThemeSerializer.new(theme, root: false).to_json
theme.set_field(target: :mobile, name: :scss, value: 'body {.down}')
record = StaffActionLogger.new(Discourse.system_user)
.log_theme_change(original_json, theme)
xhr :get, :diff, id: record.id
expect(response).to be_success
parsed = JSON.parse(response.body)
expect(parsed["side_by_side"]).to include("up")
expect(parsed["side_by_side"]).to include("down")
expect(parsed["side_by_side"]).not_to include("omit-dupe")
end
end
end