2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-08-07 16:04:12 -04:00
|
|
|
|
|
|
|
describe Admin::StaffActionLogsController do
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Admin::StaffActionLogsController < Admin::AdminController).to eq(true)
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
describe '#index' do
|
2017-05-30 11:25:42 -04:00
|
|
|
it 'generates logs' do
|
|
|
|
topic = Fabricate(:topic)
|
2018-06-11 00:37:06 -04:00
|
|
|
StaffActionLogger.new(Discourse.system_user).log_topic_delete_recover(topic, "delete_topic")
|
2017-05-30 11:25:42 -04:00
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
get "/admin/logs/staff_action_logs.json", params: { action_id: UserHistory.actions[:delete_topic] }
|
2017-05-30 11:25:42 -04:00
|
|
|
|
|
|
|
json = JSON.parse(response.body)
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-05-30 11:25:42 -04:00
|
|
|
|
|
|
|
expect(json["staff_action_logs"].length).to eq(1)
|
|
|
|
expect(json["staff_action_logs"][0]["action_name"]).to eq("delete_topic")
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
expect(json["user_history_actions"]).to include("id" => UserHistory.actions[:delete_topic], "name" => 'delete_topic')
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
describe '#diff' do
|
2017-04-12 10:52:52 -04:00
|
|
|
it 'can generate diffs for theme changes' do
|
2018-08-08 00:46:34 -04:00
|
|
|
theme = Fabricate(:theme)
|
2017-05-02 16:01:01 -04:00
|
|
|
theme.set_field(target: :mobile, name: :scss, value: 'body {.up}')
|
|
|
|
theme.set_field(target: :common, name: :scss, value: 'omit-dupe')
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
original_json = ThemeSerializer.new(theme, root: false).to_json
|
|
|
|
|
2017-05-02 16:01:01 -04:00
|
|
|
theme.set_field(target: :mobile, name: :scss, value: 'body {.down}')
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
record = StaffActionLogger.new(Discourse.system_user)
|
|
|
|
.log_theme_change(original_json, theme)
|
|
|
|
|
2018-06-11 00:37:06 -04:00
|
|
|
get "/admin/logs/staff_action_logs/#{record.id}/diff.json"
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
expect(parsed["side_by_side"]).to include("up")
|
|
|
|
expect(parsed["side_by_side"]).to include("down")
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
expect(parsed["side_by_side"]).not_to include("omit-dupe")
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|