mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 11:58:33 +08:00
remove old import/export code
This commit is contained in:
@ -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