Question

There are two issues here:

I have this code to publish on users' facebook walls:

def publish_on_facebook
    if user.last_published < 1.day.ago
        @graph = Koala::Facebook::API.new(user.service.token)
        begin
            @graph.put_wall_post("some post")
            user.last_published = Time.now
            user.save
        rescue
            user.last_published = 1.week.from_now
            user.save
        end
    end
end

It works perfectly:

if the user has authorized me, it publishes and updates the last_published (type datetime) field to now.

If the user has not authorized me to publish stuff in his wall, then it updates the last_published field to 1 week from now.

Now when I run in through my Cucumber, testing, it doesn't work:

When the user has authorized me, the last_published field updates to 1 minute from now, but 2 days ago

expected: > Sun, 03 Mar 2013 16:12:44 UTC +00:00
 got:   Fri, 01 Mar 2013 16:13:43 UTC +00:00

When the user hasn't authorized me, no change on the last_published field (i set the default value of the field to march 1st)

expected: > Sat, 09 Mar 2013 16:13:47 UTC +00:00
 got:   Fri, 01 Mar 2013 15:01:11 UTC +00:00

Any ideas?

Was it helpful?

Solution

When updating attributes, the variable @user must be reloaded:

@user.update_attributes(attribute: value)
@user = User.find(@user)

Cucumber was evaluating the values stored in @user, which were not up to date after the method ran.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top