Sha256: 7852384684e204e42b09c0d90302f432fac0c7f71aaf8f1da6d42dd6ba3cc577

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe ResquePerformLater do
  let(:user) { User.create }

  context "args to resque" do
    it "should convert the AR object to the proper string" do
      user_id = user.id

      ResquePerformLater.args_to_resque(user).length.should == 1
      ResquePerformLater.args_to_resque(user)[0].should == "AR:User:#{user_id}"
    end

    it "should convert a hash into YAML string so that Resque will be able to JSON convert it" do
      hash = {name: "something", other: "something else"}
      ResquePerformLater.args_to_resque(hash)[0].class.name.should == "String"
    end

    it "should be able to load a yaml from the string and translate it into the same hash again" do
      hash = {name: "something", other: "something else"}
      yaml = ResquePerformLater.args_to_resque(hash)[0]

      loaded_yaml = YAML.load(yaml)
      
      loaded_yaml[:name].should == "something"
      loaded_yaml[:other].should == "something else"
    end

    it "should convert a class to the proper string representation" do
      klass = User
      ResquePerformLater.args_to_resque(klass)[0].should == "CLASS:User"
    end
  end

  context "args from resque" do
    it "should give me a hash back when I pass a yaml representation of it" do
      hash = {name: "something", other: "something else"}   
      yaml = hash.to_yaml

      args = ResquePerformLater.args_from_resque(yaml)
      args[0].class.name.should == "Hash"
      args[0][:name].should == "something"
      args[0][:other].should == "something else"
    end

    it "Should give me a user model back when I pass the proper string" do
      args = ResquePerformLater.args_from_resque("AR:User:#{user.id}")
      args[0].should == user
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
perform_later-0.0.4 spec/lib/resque_perform_later_spec.rb
perform_later-0.0.3 spec/lib/resque_perform_later_spec.rb
perform_later-0.0.2 spec/lib/resque_perform_later_spec.rb