mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
112 lines
2.9 KiB
Ruby
112 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "import_export"
|
|
|
|
RSpec.describe ImportExport::Importer do
|
|
|
|
before do
|
|
STDOUT.stubs(:write)
|
|
end
|
|
|
|
let(:import_data) do
|
|
import_file = Rack::Test::UploadedFile.new(file_from_fixtures("import-export.json", "json"))
|
|
ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(import_file.read))
|
|
end
|
|
|
|
def import(data)
|
|
ImportExport::Importer.new(data).perform
|
|
end
|
|
|
|
describe '.perform' do
|
|
|
|
it 'topics and users' do
|
|
data = import_data.dup
|
|
data[:categories] = nil
|
|
data[:groups] = nil
|
|
|
|
expect {
|
|
import(data)
|
|
}.to not_change { Category.count }
|
|
.and not_change { Group.count }
|
|
.and change { Topic.count }.by(2)
|
|
.and change { User.count }.by(2)
|
|
end
|
|
|
|
context 'categories and groups' do
|
|
it 'works' do
|
|
data = import_data.dup
|
|
data[:topics] = nil
|
|
data[:users] = nil
|
|
|
|
expect {
|
|
import(data)
|
|
}.to change { Category.count }.by(6)
|
|
.and change { Group.count }.by(2)
|
|
.and change { Topic.count }.by(6)
|
|
.and not_change { User.count }
|
|
end
|
|
|
|
it 'works with sub-sub-categories' do
|
|
data = import_data.dup
|
|
|
|
# 11 -> 10 -> 15
|
|
data[:categories].find { |c| c[:id] == 10 }[:parent_category_id] = 11
|
|
data[:categories].find { |c| c[:id] == 15 }[:parent_category_id] = 10
|
|
|
|
expect { import(data) }
|
|
.to change { Category.count }.by(6)
|
|
.and change { SiteSetting.max_category_nesting }.from(2).to(3)
|
|
end
|
|
|
|
it 'fixes permissions' do
|
|
data = import_data.dup
|
|
data[:categories].find { |c| c[:id] == 10 }[:permissions_params] = { custom_group: 1 }
|
|
data[:categories].find { |c| c[:id] == 15 }[:permissions_params] = { staff: 1 }
|
|
|
|
permissions = data[:categories].find { |c| c[:id] == 10 }[:permissions_params]
|
|
|
|
expect { import(data) }
|
|
.to change { Category.count }.by(6)
|
|
.and change { permissions[:staff] }.from(nil).to(1)
|
|
end
|
|
end
|
|
|
|
it 'categories, groups and users' do
|
|
data = import_data.dup
|
|
data[:topics] = nil
|
|
|
|
expect {
|
|
import(data)
|
|
}.to change { Category.count }.by(6)
|
|
.and change { Group.count }.by(2)
|
|
.and change { Topic.count }.by(6)
|
|
.and change { User.count }.by(2)
|
|
end
|
|
|
|
it 'groups' do
|
|
data = import_data.dup
|
|
data[:categories] = nil
|
|
data[:topics] = nil
|
|
data[:users] = nil
|
|
|
|
expect {
|
|
import(data)
|
|
}.to not_change { Category.count }
|
|
.and change { Group.count }.by(2)
|
|
.and not_change { Topic.count }
|
|
.and not_change { User.count }
|
|
end
|
|
|
|
it 'all' do
|
|
expect {
|
|
import(import_data)
|
|
}.to change { Category.count }.by(6)
|
|
.and change { Group.count }.by(2)
|
|
.and change { Topic.count }.by(8)
|
|
.and change { User.count }.by(2)
|
|
end
|
|
|
|
end
|
|
|
|
end
|