vigetlabs / sprig-reap

Sprig-Reap is a gem that allows you to output your application's data state to seed files.
MIT License
18 stars 18 forks source link

CarrierWave uploader breaks data dump #5

Closed microspino closed 10 years ago

microspino commented 10 years ago

OS X 10.7 - Rails 4.0.3, ruby 2.1.1p76 using PostgreSQL. My Rails app. uses either ActsAsTaggableOn and Carrierwave. Every user has a Post and an Avatar uploaded via carrierwave on S3. Dumping all the user in a users.yml seed file works fine but the script explodes in my face with:

ArgumentError: undefined class/module Struct::AvatarUploader

The strange thing is that when i run for the first time

bundle exec rake db:seed:reap TARGET_ENV=development MODELS=User,Post IGNORED_ATTRS=created_at,updated_at

I don't get any error. I start receiving the error above from the second time i launch that command onward.

Here is a snatch of the users.yml file:

records:
- sprig_id: 2
  username: user2
  email: user2@.com
  encrypted_password: "$2a$10$GVFZPxh3tu2uO0mNs/D9SuihSzzsAOANZ.1J4MNGu73sUoGAYYQua"
  admin: false
  locked: false
  slug: user2
  reset_password_token: 
  reset_password_sent_at: 
  remember_created_at: 
  sign_in_count: 0
  current_sign_in_at: 
  last_sign_in_at: 
  current_sign_in_ip: 
  last_sign_in_ip: 
  confirmation_token: 
  confirmed_at: &1 2014-06-27 19:35:14.399730000 Z
  confirmation_sent_at: 
  unconfirmed_email: 
  avatar: &2 !ruby/object:AvatarUploader
    model: !ruby/object:User
      attributes:
        id: 2
        username: user2
        email: user2@aaa.com
        encrypted_password: "$2a$10$GVFZPxh3tu2uO0mNs/D9SuihSzzsAOANZ.1J4MNGu73sUoGAYYQua"
        admin: false
        locked: false
        slug: user2
        reset_password_token: 
        reset_password_sent_at: 
        remember_created_at: 
        sign_in_count: 0
        current_sign_in_at: 
        last_sign_in_at: 
        current_sign_in_ip: 
        last_sign_in_ip: 
        confirmation_token: 
        confirmed_at: *1
        confirmation_sent_at: 
        unconfirmed_email: 
        avatar: u2.jpg
        created_at: &3 2014-06-27 19:35:14.410751000 Z
        updated_at: &4 2014-06-27 19:35:14.410751000 Z
        on_private_message: '1'
        on_post_voted: '1'
        on_post_commented: '1'
        on_post_linked: '1'
        on_post_smart_filtered: '1'
        incomplete_reminder_timing: '1'
        digest_timing: '1'
        job_title: Corporate Metrics Manager
        summary: repurpose bleeding-edge channels
    mounted_as: :avatar
    storage: !ruby/object:CarrierWave::Storage::File
      uploader: *2
    file: !ruby/object:CarrierWave::SanitizedFile
      file: "...[edited].../public/uploads/user/avatar/2/u2.jpg"
      original_filename: 
      content_type: 
    versions:
      :thumb: &5 !ruby/object:AvatarUploader::Uploader70229152586100
        model: !ruby/object:User
          attributes:
            id: 2
            username: user2
            email: user2@aaa.com
            encrypted_password: "$2a$10$GVFZPxh3tu2uO0mNs/D9SuihSzzsAOANZ.1J4MNGu73sUoGAYYQua"
            admin: false
            locked: false
            slug: user2
            reset_password_token: 
            reset_password_sent_at: 
            remember_created_at: 
            sign_in_count: 0
            current_sign_in_at: 
            last_sign_in_at: 
            current_sign_in_ip: 
            last_sign_in_ip: 
            confirmation_token: 
            confirmed_at: *1
            confirmation_sent_at: 
            unconfirmed_email: 
            avatar: u2.jpg
            created_at: *3
            updated_at: *4
            on_private_message: '1'
            on_post_voted: '1'
            on_post_commented: '1'
            on_post_linked: '1'
            on_post_smart_filtered: '1'
            incomplete_reminder_timing: '1'
            digest_timing: '1'
            job_title: Corporate Metrics Manager
            summary: repurpose bleeding-edge channels
        mounted_as: :avatar
        storage: !ruby/object:CarrierWave::Storage::File
          uploader: *5
        file: !ruby/object:CarrierWave::SanitizedFile
          file: "...[edited].../public/uploads/user/avatar/2/thumb_u2.jpg"
          original_filename: 
          content_type: 
        versions: {}
  on_private_message: '1'
  on_post_voted: '1'
  on_post_commented: '1'
  on_post_linked: '1'
  on_post_smart_filtered: '1'
  incomplete_reminder_timing: '1'
  digest_timing: '1'
  job_title: Corporate Metrics Manager
  summary: repurpose bleeding-edge channels

Any clue, hint help is appreciated.

h0tl33t commented 10 years ago

Thanks for opening an issue on this and bringing it to our attention. This brought to light an issue with any database-backed field that's wrapped by some other kind of Ruby object. In your case, calling avatar returns an AvatarUploader when sprig-reap really only wants the underlying file location (the string stored in the database).

In order to handle these circumstances, I had to make some changes. I will be pushing a new version of sprig-reap (0.0.6) with a fix shortly.

h0tl33t commented 10 years ago

CarrierWave uploaders should be fixed as of version 0.0.6. Give it a shot!