spec/synchronization_spec.rb in active_git-0.0.7 vs spec/synchronization_spec.rb in active_git-0.0.8
- old
+ new
@@ -60,16 +60,61 @@
it 'Create' do
working_path = @file_helper.create_temp_folder
file_name = "#{working_path}/countries/1.json"
- @file_helper.write_file file_name, {id: 1, name: 'Argentina', created_at: '2012-04-20T11:24:11-03:00', updated_at: '2012-04-20T11:24:11-03:00'}.to_json
+ @file_helper.write_file file_name, {id: 1, name: 'Argentina', created_at: Time.now, updated_at: Time.now}.to_json
Country.count.should eq 0
ActiveGit::Synchronizer.synchronize ActiveGit::DbCreate.new(file_name, working_path)
Country.find(1).name.should eq 'Argentina'
+ end
+
+ it 'Create multiple models from a file with 3 nested levels' do
+ working_path = @file_helper.create_temp_folder
+
+ city1_json = {id: 1, name: "Buenos Aires", country_id: 1, created_at: Time.now, updated_at: Time.now}
+ city2_json = {id: 2, name: "Rosario", country_id: 1, created_at: Time.now, updated_at: Time.now}
+ country1_json = {id: 1, name: 'Argentina', language_id: 1, created_at: Time.now, updated_at: Time.now, cities:[city1_json,city2_json]}
+
+ city1_json = {id: 3, name: "Montevideo", country_id: 2, created_at: Time.now, updated_at: Time.now}
+ city2_json = {id: 4, name: "Colonia", country_id: 2, created_at: Time.now, updated_at: Time.now}
+ country2_json = {id: 2, name: 'Uruguay', language_id: 1, created_at: Time.now, updated_at: Time.now, cities:[city1_json,city2_json]}
+
+ file_name = "#{working_path}/languages/1.json"
+ @file_helper.write_file file_name, {id: 1, name: 'Spanish', created_at: Time.now, updated_at: Time.now, countries:[country1_json,country2_json] }.to_json
+
+ Language.count.should eq 0
+ Country.count.should eq 0
+ City.count.should eq 0
+
+ ActiveGit::Synchronizer.synchronize ActiveGit::DbCreate.new(file_name, working_path)
+
+ Language.count.should eq 1
+ Country.count.should eq 2
+ City.count.should eq 4
+
+ spanish = Language.find_by_name 'Spanish'
+
+ spanish.countries.count.should eq 2
+ spanish.countries.should include(Country.find_by_name 'Argentina')
+ spanish.countries.should include(Country.find_by_name 'Uruguay')
+
+ argentina = Country.find_by_name 'Argentina'
+
+ argentina.cities.count.should eq 2
+ argentina.cities.should include(City.find_by_name 'Buenos Aires')
+ argentina.cities.should include(City.find_by_name 'Rosario')
+ argentina.cities.should_not include(City.find_by_name 'Montevideo')
+
+ uruguay = Country.find_by_name 'Uruguay'
+
+ uruguay.cities.count.should eq 2
+ uruguay.cities.should include(City.find_by_name 'Montevideo')
+ uruguay.cities.should include(City.find_by_name 'Colonia')
+ uruguay.cities.should_not include(City.find_by_name 'Buenos Aires')
end
it 'Update' do
working_path = @file_helper.create_temp_folder
\ No newline at end of file