title: setting up objects for model testing with factory_girl
body: <p>I'd like to test the scopes below but don't know hot to setup test objects properly. I don't even know if I should create those in factory with some associations or using let/local vars.</p>
  
  <p>task.rb</p>
  
  <pre><code>belongs_to :assigner, class_name: "User"
  belongs_to :executor, class_name: "User"
  
  scope :completed, -&gt; { where.not(completed_at: nil) }
  scope :uncompleted, -&gt; { where(completed_at: nil) }
  scope :alltasks, -&gt; (u) { where('executor_id = ? OR assigner_id = ?', u.id, u.id) }
  scope :between, -&gt; (assigner_id, executor_id) do
    where("(tasks.assigner_id = ? AND tasks.executor_id = ?) OR (tasks.assigner_id = ? AND tasks.executor_id = ?)", assigner_id, executor_id, executor_id, assigner_id)
  end
  </code></pre>
  
  <p>factories</p>
  
  <pre><code>factory :task do
    content { Faker::Lorem.sentence }
    deadline { Faker::Time.between(DateTime.now + 2, DateTime.now + 3) }
    association :executor, factory: :user
    association :assigner, factory: :user #I guess this is not right
  end
  
  factory :user do
    sequence(:email) { |n| "example#{n}@gmail.com" }
    password 'example0000'
    password_confirmation 'example0000'
    new_chat_notification { Faker::Number.between(0, 10) }
    new_other_notification { Faker::Number.between(0, 10) } 
  end
  </code></pre>
  
  <p>task_spec.rb</p>
  
  <pre><code>describe Task do
  
    .....
  
    describe "scopes" do
  
      #I DON'T KNOW HOW TO SETUP THE TEST OBJECTS PROPERLY
      let(:uncompleted_task) { create(:task) }
      let(:completed_task) { create(:task, completed_at: DateTime.now - 2) }
      let(:user) { create(:user) 
  
      let(:task_1) { create(:task, executor_id: user.id, assigner_id: (user.id + 1)) }
      let(:task_2) { create(:task, assigner_id: user.id, executor_id: (user.id + 1) }
      let(:task_3) { create(:task, assigner_id: user.id, executor_id: (user.id + 2) }
  
      it "completed" do
        expect(completed_task).to eq(Task.completed.first)
      end
  
      it "uncompleted" do
        expect(uncompleted_task).to eq(Task.uncompleted.last)
      end
  
      it "alltasks" do
  
      end
  
      it "between" do
      end
    end
  end
  </code></pre>