← Back to Upcase

Is this factory right?


(Charlieanna) #1

I am getting an error when I run this spec with the whole project but not when I run it alone.

factory :daily_activity do
    sequence(:steps_covered,0) {|n| n*1000 }
    sequence(:start_time,0) { |n| Time.now + n.day}
  end

factory :user_activity do
    start_time  { (Time.now) }
    user
    challenge
    status "Participating"
    steps_covered "12000"
    factory :user_activity_with_daily_activity do

      after(:create) do |user_activity, evaluator|
        create_list(:daily_activity, user_activity.challenge.number_of_days,steps_covered:nil,user_activity: user_activity)
      end
    end

    factory :user_activity_with_daily_activity_with_steps do

      after(:create) do |user_activity, evaluator|
        create_list(:daily_activity, user_activity.challenge.number_of_days,user_activity: user_activity)
      end
    end
  end




require 'spec_helper'

feature "Daily Activity" do
  before do
    new_time = Time.local(2008, 9, 1, 12, 0, 0)
    Timecop.freeze(new_time)
  end
  scenario "User can feed in his daily activity" do
    Timecop.freeze(Time.now)
    user = create(:user)
    challenge = create(:challenge,number_of_steps:50000,number_of_days:7)
    user_activity = create(:user_activity_with_daily_activity,challenge: challenge, user: user, start_time: Time.now)
    Timecop.travel(Time.now + 1.day)
    visit root_path
    click_link "Login" 
    fill_in "Email",with: user.email
    fill_in "Password",with: user.password
    click_button "Sign in"
    click_link challenge.name

    expect(page).to have_content "Challenge started on #{ActiveSupport::Inflector.ordinalize((Time.now-1.day).to_date.strftime("%B %d, %Y"))}"
    fill_in (Time.now-1.day).strftime("%Y-%m-%d"),with: 100000

    click_button "add_steps_#{(Time.now-1.day).strftime("%Y-%m-%d")}"
    expect(page).to have_content "Congrats you just won another badge. MasterBlaster badge."
  end
end