summaryrefslogtreecommitdiff
path: root/spec/models/tool_spec.rb
blob: db08b512cd6427ce05d59ae00ad27ea27b97f5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "rails_helper"


describe Tool do 
  
  it "has a name" do 
    tool = Tool.new 
    tool.name = "wilton pan"
    expect(tool.name).to eql("wilton pan")
  end

  it "has a description" do
    tool = Tool.new
    tool.description = "This pan can be used to make round cakes"
    expect(tool.description).to eql("This pan can be used to make round cakes")
  end

  it "has an ASIN" do
    tool = Tool.new
    tool.asin = "223455"
    expect(tool.asin).to eql("223455")
  end

  it "saves to the database" do
    tool = Tool.new
    tool.asin = "223455"
    tool.description = "This pan can be used to make round cakes"
    tool.name = "wilton pan"
    tool.save
    tool.reload
    expect(tool.name).to eql("wilton pan")
    expect(tool.description).to eql("This pan can be used to make round cakes")
    expect(tool.asin).to eql("223455")
  end

  context "#validation" do
    let(:tool) { build(:tool) }

    it "has to have a name" do
      tool.name = nil
      expect(tool).to_not be_valid
      expect(tool.errors[:name]).to_not be_empty
    end

    it "name has to be unique" do 
      create(:tool, name: 'blah')
      tool.name = 'blah'
      
      expect(tool).to_not be_valid
      expect(tool.errors[:name]).to_not be_empty
    end

    it "has a ASIN number" do
      tool.asin = nil
      expect(tool).to_not be_valid
      expect(tool.errors[:asin]).to_not be_empty
    end

    it "validates" do
      expect(tool).to be_valid
    end
  end
end