<commit_before>require "spec_helper"
require "pp"

describe "Pomodori::Pomodoro" do
  let ( :test_config_path ) { File.expand_path( "../../dotpomodori", __FILE__ ) }

  # TODO: Convert to 'let' blocks
  before(:each) do
    @setup = Pomodori::Setup.new
    allow(@setup).to receive(:default_config_path).and_return( test_config_path )

    Pomodori::Database.any_instance.stub(:default_config_path).and_return( test_config_path )

    @setup.run
    @database = Pomodori::Database.new
    @database.connect

    @config = @database.config
  end

  after(:each) do
    FileUtils.rm_rf test_config_path
  end

  # TODO: Once the Pomodoro tests are written, abstract them to a shared
  # example group
  describe "saving" do
    it "saves a valid object" do
      pomodoro = build(:pomodoro, config: @config)

      expect(pomodoro.valid?).to be_true
      expect { pomodoro.save }.to_not raise_error
    end

    # Initial creation needs summary, duration, kind, state, created_at
    it "expects a summary" do
      pomodoro = build(:pomodoro, config: @config, summary: '')
      expect(pomodoro.valid?).to be_false

      pomodoro = build(:pomodoro, config: @config, summary: nil)
      expect(pomodoro.valid?).to be_false
    end

    it "expects a duration" do
      pomodoro = build(:pomodoro, config: @config, duration: '')
      expect(pomodoro.valid?).to be_false
    end

    it "expects a kind" do
      pomodoro = build(:pomodoro, config: @config)
      pomodoro.stub(:kind).and_return(nil)

      expect(pomodoro.valid?).to be_false
    end

    it "expects a state" do
      pomodoro = build(:pomodoro, config: @config, state: '')
      expect(pomodoro.valid?).to be_false
      
      pomodoro = build(:pomodoro, config: @config, state: nil)
      expect(pomodoro.valid?).to be_false
    end

    it "fills in a creation date and time" do
      pomodoro = build(:pomodoro, config:       @config,
                                  created_at:   nil,
                                  started_at:   nil,
                                  completed_at: nil
                                )

      expect(pomodoro.valid?).to be_true
      expect(pomodoro.created_at.nil?).to be_false
    end
  end

  describe "initialization" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )    
                    }

    it "sets a kind" do
      expect(pomodoro.kind).not_to be_nil
      expect(pomodoro.determine_kind).to eq('pomodoro')
      expect(pomodoro.kind).to eq('pomodoro')
    end

    it "sets a state" do
      expect(pomodoro.state).not_to be_nil
      expect(pomodoro.state).to eq('ready')
    end

    describe "duration" do 
      it "sets a default duration from config" do
        expect(pomodoro.duration).not_to be_nil
        expect(pomodoro.duration).to eq(25)
      end

      # TODO: CLI provided duration
    end

    describe "summary" do
      it "sets a default summary from config" do
        pp pomodoro

        expect(pomodoro.summary).not_to be_nil
        expect(pomodoro.summary).to include("Working on")
      end

      # TODO: CLI provided summary
    end
  end

  describe "starting a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )    
                    }

    it "changes state to 'in_progress'" do
      expect(pomodoro.state).to eq("ready")
      pomodoro.start
      expect(pomodoro.state).to eq("in_progress")
    end
    
    it "saves state to the database" do
      pending

      expect(pomodoro.state).to eq('in_progress')
    end

    it "sets started_at" do
      pomodoro.start
      expect(pomodoro.started_at).not_to be_nil
    end

    it "cannot be completed" do
      pending
    end

    it "cannot be cancelled" do
      pending
    end
  end

  describe "completing a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )    
                    }
    
    before(:each) do
      pomodoro.start
    end

    it "changes state to 'completed'" do
      expect(pomodoro.state).to eq("in_progress")
      pomodoro.complete
      expect(pomodoro.state).to eq("completed")
    end

    it "saves state to the database" do
      pending

      expect(pomodoro.state).to eq('completed')
    end

    it "sets completed_at" do
      pending
    end

    it "cannot be cancelled" do
      pending
    end

    it "cannot be started" do
      pending
    end
  end

  describe "cancelling a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config) }
    
    before(:each) do
      pomodoro.start
    end<commit_msg>Adding database test for started<commit_after>require "spec_helper"
require "pp"

describe "Pomodori::Pomodoro" do
  let ( :test_config_path ) { File.expand_path( "../../dotpomodori", __FILE__ ) }

  # TODO: Convert to 'let' blocks
  before(:each) do
    @setup = Pomodori::Setup.new
    allow(@setup).to receive(:default_config_path).and_return( test_config_path )

    Pomodori::Database.any_instance.stub(:default_config_path).and_return( test_config_path )

    @setup.run
    @database = Pomodori::Database.new
    @database.connect

    @config = @database.config
  end

  after(:each) do
    FileUtils.rm_rf test_config_path
  end

  # TODO: Once the Pomodoro tests are written, abstract them to a shared
  # example group
  describe "saving" do
    it "saves a valid object" do
      pomodoro = build(:pomodoro, config: @config)

      expect(pomodoro.valid?).to be_true
      expect { pomodoro.save }.to_not raise_error
    end

    # Initial creation needs summary, duration, kind, state, created_at
    it "expects a summary" do
      pomodoro = build(:pomodoro, config: @config, summary: '')
      expect(pomodoro.valid?).to be_false

      pomodoro = build(:pomodoro, config: @config, summary: nil)
      expect(pomodoro.valid?).to be_false
    end

    it "expects a duration" do
      pomodoro = build(:pomodoro, config: @config, duration: '')
      expect(pomodoro.valid?).to be_false
    end

    it "expects a kind" do
      pomodoro = build(:pomodoro, config: @config)
      pomodoro.stub(:kind).and_return(nil)

      expect(pomodoro.valid?).to be_false
    end

    it "expects a state" do
      pomodoro = build(:pomodoro, config: @config, state: '')
      expect(pomodoro.valid?).to be_false

      pomodoro = build(:pomodoro, config: @config, state: nil)
      expect(pomodoro.valid?).to be_false
    end

    it "fills in a creation date and time" do
      pomodoro = build(:pomodoro, config:       @config,
                                  created_at:   nil,
                                  started_at:   nil,
                                  completed_at: nil
                                )

      expect(pomodoro.valid?).to be_true
      expect(pomodoro.created_at.nil?).to be_false
    end
  end

  describe "initialization" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )
                    }

    it "sets a kind" do
      expect(pomodoro.kind).not_to be_nil
      expect(pomodoro.determine_kind).to eq('pomodoro')
      expect(pomodoro.kind).to eq('pomodoro')
    end

    it "sets a state" do
      expect(pomodoro.state).not_to be_nil
      expect(pomodoro.state).to eq('ready')
    end

    describe "duration" do
      it "sets a default duration from config" do
        expect(pomodoro.duration).not_to be_nil
        expect(pomodoro.duration).to eq(25)
      end

      # TODO: CLI provided duration
    end

    describe "summary" do
      it "sets a default summary from config" do
        pp pomodoro

        expect(pomodoro.summary).not_to be_nil
        expect(pomodoro.summary).to include("Working on")
      end

      # TODO: CLI provided summary
    end
  end

  describe "starting a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )
                    }

    it "changes state to 'in_progress'" do
      expect(pomodoro.state).to eq("ready")
      pomodoro.start
      expect(pomodoro.state).to eq("in_progress")
    end

    it "saves state to the database" do
      pomodoro.start
      pomodoro.save

      db_pomodoro = Pomodori::Pomodoro.find(id: pomodoro.id)

      expect(db_pomodoro.state).to eq('in_progress')
      expect(db_pomodoro.object_id).not_to eq(pomodoro.object_id)
    end

    it "sets started_at" do
      pomodoro.start
      expect(pomodoro.started_at).not_to be_nil
    end

    it "cannot be completed" do
      pending
    end

    it "cannot be cancelled" do
      pending
    end
  end

  describe "completing a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config,
                                      created_at:   nil,
                                      started_at:   nil,
                                      completed_at: nil
                                )
                    }

    before(:each) do
      pomodoro.start
    end

    it "changes state to 'completed'" do
      expect(pomodoro.state).to eq("in_progress")
      pomodoro.complete
      expect(pomodoro.state).to eq("completed")
    end

    it "saves state to the database" do
      pending

      expect(pomodoro.state).to eq('completed')
    end

    it "sets completed_at" do
      pending
    end

    it "cannot be cancelled" do
      pending
    end

    it "cannot be started" do
      pending
    end
  end

  describe "cancelling a pomodoro" do
    let(:pomodoro) { build(:pomodoro, config: @config) }

    before(:each) do
      pomodoro.start
    end
{'fraction_non_alphanumeric': 0.09041122213681783, 'fraction_numerical': 0.0003843197540353574, 'mean_word_length': 1.837012810029981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3363617', 'n_tokens_mistral': 3335, 'n_tokens_neox': 3073, 'n_words': 799}