2013-02-06 03:16:51 +08:00
require 'spec_helper'
require 'import/json_decoder'
describe Import :: JsonDecoder do
describe " start " do
context " given valid arguments " do
before do
@version = '20121201205642'
2014-01-29 13:49:01 +08:00
@schema = {
" schema " = > { 'source' = > 'discourse' , 'version' = > @version } ,
" categories " = > {
2013-02-06 03:16:51 +08:00
fields : Category . columns . map ( & :name ) ,
2014-01-29 13:49:01 +08:00
row_count : 2
2013-02-06 03:16:51 +08:00
} ,
2014-01-29 13:49:01 +08:00
" notifications " = > {
2013-02-06 03:16:51 +08:00
fields : Notification . columns . map ( & :name ) ,
2014-01-29 13:49:01 +08:00
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 = [
2013-02-06 03:16:51 +08:00
[ " 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 ]
]
2014-01-29 13:49:01 +08:00
@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
} )
2013-02-06 03:16:51 +08:00
@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 |
2014-01-29 13:49:01 +08:00
arg [ " source " ] . should == @schema [ " source " ]
arg [ " version " ] . should == @schema [ " version " ]
2013-02-06 03:16:51 +08:00
end
@decoder . start ( @valid_args )
end
it " should call the table_data callback at least once for each table in the export file " do
2014-01-29 13:49:01 +08:00
@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
2013-02-06 03:16:51 +08:00
@decoder . start ( @valid_args )
end
end
end
2014-01-29 13:49:01 +08:00
end