mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
remove old import/export code
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'export/export'
|
||||
|
||||
describe Export do
|
||||
describe '#current_schema_version' do
|
||||
it "should return the latest migration version" do
|
||||
Export.current_schema_version.should == User.exec_sql("select max(version) as max from schema_migrations")[0]["max"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "models_included_in_export" do
|
||||
it "should include the user model" do
|
||||
Export.models_included_in_export.map(&:name).should include('User')
|
||||
end
|
||||
|
||||
it "should not include the message bus model" do
|
||||
Export.models_included_in_export.map(&:name).should_not include('MessageBus')
|
||||
end
|
||||
end
|
||||
|
||||
describe "is_export_running?" do
|
||||
it "should return true when an export is in progress" do
|
||||
$redis.stubs(:get).with(Export.export_running_key).returns('1')
|
||||
Export.is_export_running?.should be_true
|
||||
end
|
||||
|
||||
it "should return false when an export is not happening" do
|
||||
$redis.stubs(:get).with(Export.export_running_key).returns('0')
|
||||
Export.is_export_running?.should be_false
|
||||
end
|
||||
|
||||
it "should return false when an export has never been run" do
|
||||
$redis.stubs(:get).with(Export.export_running_key).returns(nil)
|
||||
Export.is_export_running?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,143 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'export/json_encoder'
|
||||
|
||||
describe Export::JsonEncoder do
|
||||
describe "exported data" do
|
||||
before do
|
||||
@streams = {}
|
||||
@encoder = Export::JsonEncoder.new(lambda{ |filename|
|
||||
@streams[File.basename(filename, ".*")] = StringIO.new
|
||||
})
|
||||
end
|
||||
|
||||
let :schema do
|
||||
JSON.parse(@streams['schema'].string)
|
||||
end
|
||||
|
||||
describe "write_schema_info" do
|
||||
it "should write a schema section when given valid arguments" do
|
||||
version = '20121216230719'
|
||||
@encoder.write_schema_info( source: 'discourse', version: version )
|
||||
@encoder.finish
|
||||
schema.should have_key('schema')
|
||||
schema['schema']['source'].should == 'discourse'
|
||||
schema['schema']['version'].should == version
|
||||
end
|
||||
|
||||
it "should raise an exception when its arguments are invalid" do
|
||||
expect {
|
||||
@encoder.write_schema_info({})
|
||||
}.to raise_error(Export::SchemaArgumentsError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "write_table" do
|
||||
let(:table_name) { Topic.table_name }
|
||||
let(:columns) { Topic.columns }
|
||||
|
||||
before do
|
||||
@encoder.write_schema_info( source: 'discourse', version: '111' )
|
||||
end
|
||||
|
||||
it "should yield a row count of 0 to the caller on the first iteration" do
|
||||
yield_count = 0
|
||||
@encoder.write_table(table_name, columns) do |row_count|
|
||||
row_count.should == 0
|
||||
yield_count += 1
|
||||
break
|
||||
end
|
||||
yield_count.should == 1
|
||||
end
|
||||
|
||||
it "should yield the number of rows I sent the first time on the second iteration" do
|
||||
yield_count = 0
|
||||
@encoder.write_table(table_name, columns) do |row_count|
|
||||
yield_count += 1
|
||||
if yield_count == 1
|
||||
[[1, 'Hello'], [2, 'Yeah'], [3, 'Great']]
|
||||
elsif yield_count == 2
|
||||
row_count.should == 3
|
||||
break
|
||||
end
|
||||
end
|
||||
yield_count.should == 2
|
||||
end
|
||||
|
||||
it "should stop yielding when it gets an empty array" do
|
||||
yield_count = 0
|
||||
@encoder.write_table(table_name, columns) do |row_count|
|
||||
yield_count += 1
|
||||
break if yield_count > 1
|
||||
[]
|
||||
end
|
||||
yield_count.should == 1
|
||||
end
|
||||
|
||||
it "should stop yielding when it gets nil" do
|
||||
yield_count = 0
|
||||
@encoder.write_table(table_name, columns) do |row_count|
|
||||
yield_count += 1
|
||||
break if yield_count > 1
|
||||
nil
|
||||
end
|
||||
yield_count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "exported data" do
|
||||
before do
|
||||
@encoder.write_schema_info( source: 'discourse', version: '20121216230719' )
|
||||
end
|
||||
|
||||
it "should have a table count of 0 when no tables were exported" do
|
||||
@encoder.finish
|
||||
schema['schema']['table_count'].should == 0
|
||||
end
|
||||
|
||||
it "should have a table count of 1 when one table was exported" do
|
||||
@encoder.write_table(Topic.table_name, Topic.columns) { |row_count| [] }
|
||||
@encoder.finish
|
||||
schema['schema']['table_count'].should == 1
|
||||
end
|
||||
|
||||
it "should have a table count of 3 when three tables were exported" do
|
||||
@encoder.write_table(Topic.table_name, Topic.columns) { |row_count| [] }
|
||||
@encoder.write_table(User.table_name, User.columns) { |row_count| [] }
|
||||
@encoder.write_table(Post.table_name, Post.columns) { |row_count| [] }
|
||||
@encoder.finish
|
||||
schema['schema']['table_count'].should == 3
|
||||
end
|
||||
|
||||
it "should have a row count of 0 when no rows were exported" do
|
||||
@encoder.write_table(Notification.table_name, Notification.columns) { |row_count| [] }
|
||||
@encoder.finish
|
||||
schema[Notification.table_name]['row_count'].should == 0
|
||||
end
|
||||
|
||||
it "should have a row count of 1 when one row was exported" do
|
||||
@encoder.write_table(Notification.table_name, Notification.columns) do |row_count|
|
||||
if row_count == 0
|
||||
[['1409', '5', '1227', '', 't', '2012-12-07 19:59:56.691592', '2012-12-07 19:59:56.691592', '303', '16', '420']]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
@encoder.finish
|
||||
schema[Notification.table_name]['row_count'].should == 1
|
||||
end
|
||||
|
||||
it "should have a row count of 2 when two rows were exported" do
|
||||
@encoder.write_table(Notification.table_name, Notification.columns) do |row_count|
|
||||
if row_count == 0
|
||||
[['1409', '5', '1227', '', 't', '2012-12-07 19:59:56.691592', '2012-12-07 19:59:56.691592', '303', '16', '420'],
|
||||
['1408', '4', '1188', '', 'f', '2012-12-07 18:40:30.460404', '2012-12-07 18:40:30.460404', '304', '1', '421']]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
@encoder.finish
|
||||
schema[Notification.table_name]['row_count'].should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,24 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'import/adapter/base'
|
||||
|
||||
describe Import::Adapter::Base do
|
||||
|
||||
describe 'the base implementation' do
|
||||
let(:adapter) { Import::Adapter::Base.new }
|
||||
|
||||
describe 'apply_to_column_names' do
|
||||
it 'should return the column names passed in' do
|
||||
cols = ['first', 'second']
|
||||
adapter.apply_to_column_names('table_name', cols).should == cols
|
||||
end
|
||||
end
|
||||
|
||||
describe 'apply_to_row' do
|
||||
it 'should return the row passed in' do
|
||||
row = [1,2,3,4]
|
||||
adapter.apply_to_row('table_name', row).should == row
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,66 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'import/import'
|
||||
|
||||
class AdapterX < Import::Adapter::Base; end
|
||||
|
||||
class Adapter1 < Import::Adapter::Base; end
|
||||
class Adapter2 < Import::Adapter::Base; end
|
||||
class Adapter3 < Import::Adapter::Base; end
|
||||
|
||||
describe Import do
|
||||
describe "is_import_running?" do
|
||||
it "should return true when an import is in progress" do
|
||||
$redis.stubs(:get).with(Import.import_running_key).returns('1')
|
||||
Import.is_import_running?.should be_true
|
||||
end
|
||||
|
||||
it "should return false when an import is not happening" do
|
||||
$redis.stubs(:get).with(Import.import_running_key).returns('0')
|
||||
Import.is_import_running?.should be_false
|
||||
end
|
||||
|
||||
it "should return false when an import has never been run" do
|
||||
$redis.stubs(:get).with(Import.import_running_key).returns(nil)
|
||||
Import.is_import_running?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'add_import_adapter' do
|
||||
it "should return true" do
|
||||
Import.clear_adapters
|
||||
Import.add_import_adapter(AdapterX, '20130110121212', ['users']).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adapters_for_version' do
|
||||
it "should return an empty Hash when there are no adapters" do
|
||||
Import.clear_adapters
|
||||
Import.adapters_for_version('1').should == {}
|
||||
end
|
||||
|
||||
context 'when there are some adapters' do
|
||||
before do
|
||||
Import.clear_adapters
|
||||
Import.add_import_adapter(Adapter1, '10', ['users'])
|
||||
Import.add_import_adapter(Adapter2, '20', ['users'])
|
||||
Import.add_import_adapter(Adapter3, '30', ['users'])
|
||||
end
|
||||
|
||||
it "should return no adapters when the version is newer than all adapters" do
|
||||
Import.adapters_for_version('31')['users'].should have(0).adapters
|
||||
end
|
||||
|
||||
it "should return adapters that are newer than the given version" do
|
||||
Import.adapters_for_version('12')['users'].should have(2).adapters
|
||||
Import.adapters_for_version('22')['users'].should have(1).adapters
|
||||
end
|
||||
|
||||
it "should return the adapters in order" do
|
||||
adapters = Import.adapters_for_version('1')['users']
|
||||
adapters[0].should be_a(Adapter1)
|
||||
adapters[1].should be_a(Adapter2)
|
||||
adapters[2].should be_a(Adapter3)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,76 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'import/json_decoder'
|
||||
|
||||
describe Import::JsonDecoder do
|
||||
|
||||
describe "start" do
|
||||
context "given valid arguments" do
|
||||
before do
|
||||
@version = '20121201205642'
|
||||
@schema = {
|
||||
"schema" => { 'source' => 'discourse', 'version' => @version},
|
||||
"categories" => {
|
||||
fields: Category.columns.map(&:name),
|
||||
row_count: 2
|
||||
},
|
||||
"notifications" => {
|
||||
fields: Notification.columns.map(&:name),
|
||||
row_count: 2
|
||||
}
|
||||
}
|
||||
|
||||
@categories = [
|
||||
["3", "entertainment", "AB9364", "155", nil, nil, nil, nil, "19", "2012-07-12 18:55:56.355932", "2012-07-12 18:55:56.355932", "1186", "17", "0", "0", "entertainment"],
|
||||
["4", "question", "AB9364", "164", nil, nil, nil, nil, "1", "2012-07-12 18:55:56.355932", "2012-07-12 18:55:56.355932", "1186", "1", "0", "0", "question"]
|
||||
]
|
||||
|
||||
@notifications = [
|
||||
["1416", "2", "1214", "{\"topic_title\":\"UI: Where did the 'Create a Topic' button go?\",\"display_username\":\"Lowell Heddings\"}", "t", "2012-12-09 18:05:09.862898", "2012-12-09 18:05:09.862898", "394", "2", nil],
|
||||
["1415", "2", "1187", "{\"topic_title\":\"Jenkins Config.xml\",\"display_username\":\"Sam\"}", "t", "2012-12-08 10:11:17.599724", "2012-12-08 10:11:17.599724", "392", "3", nil]
|
||||
]
|
||||
|
||||
@decoder = Import::JsonDecoder.new(['xyz/schema.json', 'xyz/categories.json', 'xyz/notifications.json'], lambda{|filename|
|
||||
case filename
|
||||
when 'xyz/schema.json'
|
||||
@schema
|
||||
when 'xyz/categories.json'
|
||||
@categories
|
||||
when 'xyz/notifications.json'
|
||||
@notifications
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
@valid_args = { callbacks: { schema_info: stub_everything, table_data: stub_everything } }
|
||||
end
|
||||
|
||||
it "should call the schema_info callback before sending table data" do
|
||||
callback_sequence = sequence('callbacks')
|
||||
@valid_args[:callbacks][:schema_info].expects(:call).in_sequence(callback_sequence)
|
||||
@valid_args[:callbacks][:table_data].expects(:call).in_sequence(callback_sequence).at_least_once
|
||||
@decoder.start( @valid_args )
|
||||
end
|
||||
|
||||
it "should call the schema_info callback with source and version parameters when export data is from discourse" do
|
||||
@valid_args[:callbacks][:schema_info].expects(:call).with do |arg|
|
||||
arg["source"].should == @schema["source"]
|
||||
arg["version"].should == @schema["version"]
|
||||
end
|
||||
@decoder.start( @valid_args )
|
||||
end
|
||||
|
||||
it "should call the table_data callback at least once for each table in the export file" do
|
||||
@valid_args[:callbacks][:table_data].expects(:call).with('categories',
|
||||
@schema['categories']['fields'],
|
||||
anything, anything
|
||||
).at_least_once
|
||||
|
||||
@valid_args[:callbacks][:table_data].expects(:call).with('notifications',
|
||||
@schema['notifications']['fields'], anything, anything).at_least_once
|
||||
@decoder.start( @valid_args )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user