Skip to content

Instantly share code, notes, and snippets.

@jumpcheng
Forked from stujo/cohort_spec.rb
Last active August 29, 2015 14:21
Show Gist options
  • Save jumpcheng/8a80f03ae9b08e095597 to your computer and use it in GitHub Desktop.
Save jumpcheng/8a80f03ae9b08e095597 to your computer and use it in GitHub Desktop.

Revisions

  1. @stujo stujo created this gist May 12, 2015.
    38 changes: 38 additions & 0 deletions cohort_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    require_relative '../app'

    describe Cohort do
    before :each do
    Cohort.transaction
    end

    after :each do
    Cohort.rollback
    end

    describe "#initialize" do
    it "should take value from input attributes" do
    cohort = Cohort.new("name" => "FierySkippers!")
    expect(cohort[:name]).to eq "FierySkippers!"
    end

    it "should not take value from input attributes which not in the list" do
    expect{
    cohort = Cohort.new("made_up_attribute" => "Hello Mum!")
    }.to raise_error(Database::InvalidAttributeError)
    end
    end

    describe "::all" do

    it "should return an array of Cohort objects" do
    expect(Cohort.all[0]).to be_a Cohort
    end

    it "should return an array of count(*) length" do
    count = Database::Model.execute("SELECT count(*) AS CNT FROM cohorts")[0]['CNT']

    expect(Cohort.all.length).to eq count
    end

    end
    end