Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Populating Database #17

Closed
muZZkat opened this issue Nov 18, 2014 · 10 comments
Closed

Populating Database #17

muZZkat opened this issue Nov 18, 2014 · 10 comments

Comments

@muZZkat
Copy link

muZZkat commented Nov 18, 2014

Hi,

In your demo you use the example of populating the database, if you did run a script to pollute the database then I guess you would need to know the path of the .app?

I am trying to work out how I can preload a workout database onto the simulator app so I have some data for the screenshots.

Thanks

setup_for_language_change do |lang, device|
puts "Running #{lang} on #{device}"
system("./popuplateDatabase.sh")
end

@KrauseFx
Copy link
Collaborator

That's a good question. You could help me with this:

Put something inside the /tmp/snapshot/build/[AppName].app by right clicking there and click on Show package content.
You'd have to do this after building is finished and the tests are already running.

@KrauseFx KrauseFx self-assigned this Nov 18, 2014
@muZZkat
Copy link
Author

muZZkat commented Nov 19, 2014

For now, I added a empty Documents.zip file to the project target and wrote a script that uses curl to download different Document.zip files from the web and replaces the empty Documents.zip file in the project just before it starts the build. (I didn't want my 35MB sample database to be in my git repo)

I'm interested in testing out injecting it into the .app after build as this will allow me to use localised workout data for different regions (eg. a Run in Japan or a Bike in London.

Thanks for the great tool!

@KrauseFx
Copy link
Collaborator

You can still download localised data from your app, since you can easily detect the locale while running the app.

@KrauseFx
Copy link
Collaborator

I just successfully integrated it - in your Snapfile do the following:

folder_name = "ExampleDocuments"

setup_for_language_change do |lang, device|
  puts "Copying example files to .app"

  app_path = "/tmp/snapshot/build/app_name.app/"

  FileUtils.mkdir_p(File.join(app_path, folder_name))

  Dir.glob(File.join(example_files, '*')).each do |example_path|
    FileUtils.cp_r(example_path, File.join(app_path, folder_name)) rescue nil # in case the file already exists
  end
end

@hanneskaeufler
Copy link
Contributor

Did any of you guys manage to replace an empty .sqlite with a prefilled one for a CoreData backed app?

@buscarini
Copy link

I think the documentation is quite lacking in this regard. It took me a long time to get this working. The current example could use some data from the Documents folder, and use this hook to populate it for screenshots.

Anyway, in case someone needs help: I used the script in the previous comment, putting it into "test_data", and then I did this in my app delegate did finish launching:

#ifdef SNAPSHOT
    [[SDStatusBarManager sharedInstance] enableOverrides];

    NSError *error = nil;
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test_data" withExtension:nil];
    NSArray *fileUrls = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:0 error:nil];
NSString *docsPath = [BMFUtils applicationDocumentsDirectory];
for (NSURL *fileUrl in fileUrls) {
    NSURL *finalUrl = [NSURL fileURLWithPath:[docsPath stringByAppendingPathComponent:fileUrl.lastPathComponent]];
    if (![[NSFileManager defaultManager] copyItemAtURL:fileUrl toURL:finalUrl error:&error]) {
        DDLogError(@"Error copying test data: %@",error);
    }
}
#endif

I think this should work for Core Data databases too.

@hanneskaeufler
Copy link
Contributor

Interesting, I was messing with xcappdata packages lately (I use a seperate Scheme for snapshot), which is a dead end because xcappdata loading is currently broken in XCode 6.3 http://stackoverflow.com/questions/29717611/xcode-is-not-loading-the-xcappdata-into-the-app

@KrauseFx
Copy link
Collaborator

@buscarini @hanneskaeufler

Take a look at how MindNode implements the Snapfile.

How could I improve the documentation? With more sample code and how it works?

@hanneskaeufler
Copy link
Contributor

I want to avoid having any CoreData importing code in the app, as I really don´t need it otherwise. xcappdata would be perfect for the snapshot Scheme imho.

Sure, maybe linking to the mind node example here could help. https://github.com/KrauseFx/snapshot#custom-callbacks-to-prepare-your-app

I was a little disappointed to see ./prepareDatabase.sh and then not find any documentation about actually preparing a (sqlite/coredata) database to be honest.

@fastlanebot
Copy link

This issue was migrated to fastlane/fastlane#2733. Please post all further comments there.

fastlane is now a mono repo, you can read more about the change in our blog post. All tools are now available in the fastlane main repo 🚀

@fastlane-old fastlane-old locked and limited conversation to collaborators Mar 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants