Skip to content

Commit

Permalink
Add shoulda matchers in Technology model
Browse files Browse the repository at this point in the history
  • Loading branch information
GittavanderPol committed Aug 17, 2024
1 parent 0cd8de6 commit 168f6e2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions spec/models/technology_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,21 @@

RSpec.describe(Technology, type: :model) do
require_factories
describe "attributes" do
it "accepts all valid attributes" do
technology = Technology.new(
name: "Ruby",
background_color: "#FF0000",
text_color: "#FFFFFF",
)
expect(technology).to(be_valid)
end
require_shoulda_matchers

it "throws an error if name is not present" do
technology = build(:technology, name: nil)
expect(technology).to_not(be_valid)
expect(technology.errors[:name]).to(be_present)
end
describe "validations" do
subject { build(:technology) }

it { is_expected.to(validate_presence_of(:name)) }
it { is_expected.to(validate_uniqueness_of(:name)) }

it "throws an error if background_color is not a valid hex color code" do
it "returns a validation error if background_color is not a valid hex color code" do
technology = build(:technology, background_color: "invalid")
expect(technology).to_not(be_valid)
expect(technology.errors[:background_color]).to(be_present)
end

it "throws an error if text_color is not a valid hex color code" do
it "returns a validation error if text_color is not a valid hex color code" do
technology = build(:technology, text_color: "invalid")
expect(technology).to_not(be_valid)
expect(technology.errors[:text_color]).to(be_present)
Expand Down

0 comments on commit 168f6e2

Please sign in to comment.