require 'spec_helper' describe Flyboy::Ability do let(:ability){ Flyboy::Ability.new } describe Flyboy::Goal do it "can't close already closed goal" do goal = FactoryGirl.create(:flyboy_goal, status: "closed") expect(ability.can?(:close, goal)).to be false end it "can't open already open goal" do goal = FactoryGirl.create(:flyboy_goal, status: "open") expect(ability.can?(:open, goal)).to be false end it "can't close goals with undone tasks" do task = FactoryGirl.create(:flyboy_task, done: false) goal = task.goal expect(ability.can?(:close, goal)).to be false end end describe Flyboy::Task do it "can't create task in a closed goal" do goal = FactoryGirl.create(:flyboy_goal, status: "closed") task = goal.tasks.new expect(ability.can?(:create, task)).to be false end it "can't complete a done task" do task = FactoryGirl.create(:flyboy_task, done: true) expect(ability.can?(:complete, task)).to be false end it "can't snooze a done task" do task = FactoryGirl.create(:flyboy_task, done: true) expect(ability.can?(:snooze, task)).to be false end it "can't snooze if reminder >= today" do task = FactoryGirl.create(:flyboy_task, reminder: Date.today, term: Date.tomorrow) expect(ability.can?(:snooze, task)).to be false end end end