ruby-on-railsrubytwitterfabrication-gem

Unable to fabricate Twitter::Tweet from twitter gem using Fabrication gem


I'm trying to fabricate Twitter::Tweet class from Twitter gem. And I got this error

undefined method `id' for #<Fabrication::Schematic::Runner:0x00000102da7c28>

Here's my Fabricator.

Fabricator(:twitter_tweet, from: 'Twitter::Tweet', class_name: 'Twitter::Tweet') do
    id "1"
    text "tweet"
    created_at Time.now
    user {
        id "created_by_social_id"
        name "name"
        location "location"
    }
    entites {
        user_mentions nil
    }
end

But I could create it manually like this.

tweet = Twitter::Tweet.new(:id => "1", 
      :created_at => Time.now.to_s,
      :text => "text",
      :user => {
        :id => "created_by_social_id",
        :name => "name",
        :location => "location"
      }, 
      :entities => {:user_mentions => user_mentions})

Did I miss anything obvious?


Solution

  • Twitter

    I think you're getting confused of how to use the Twitter gem to create Tweets:

    client.update("I'm tweeting with @gem!")
    

    This is how you can create a new tweet. This is based on the idea you've already initialized an object & associated with the variable client:

    #config/initializers/twitter.rb
    client = Twitter::REST::Client.new do |config|
      config.consumer_key    = "YOUR_CONSUMER_KEY"
      config.consumer_secret = "YOUR_CONSUMER_SECRET"
    end
    

    Code

    Although not a direct answer to using fabrication, I would suggest you have to adapt your syntax to accommodate the loading of this gem (connecting to the Twitter API), and then use fabrication to sort it out