Updated

spec/models / tag_spec.rb

D
57 lines of codes
0 methods
N/A complexity/method
2 churn
176.88 complexity
81 duplications
require 'rails_helper' RSpec.describe Tag, type: :model do subject { FactoryBot.build(:tag) } describe "schema" do
  1. describe#schema has a flog score of 44
it { is_expected.to have_db_column(:name).of_type(:string).with_options(limit: 50, null: false) } it { is_expected.to have_db_column(:description).of_type(:string).with_options(limit: 200, null: true) } it { is_expected.to have_db_column(:created_at).of_type(:datetime).with_options(null: false) } it { is_expected.to have_db_column(:updated_at).of_type(:datetime).with_options(null: false) } end describe "indexes" do it { is_expected.to have_db_index([:name]).unique } end describe "validations" do
  1. describe#validations has a flog score of 32
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_uniqueness_of(:name) } it { is_expected.to validate_length_of(:name).is_at_most(50) } it { is_expected.to validate_length_of(:description).is_at_most(200) } end describe "callbacks" do context "when a tag is destroyed" do let!(:tag) { FactoryBot.create(:tag) } let!(:petition) { FactoryBot.create(:petition, tags: [tag.id]) } let!(:archived_petition) { FactoryBot.create(:archived_petition, tags: [tag.id]) } it "removes tags from petitions" do
  1. Similar code found in 2 nodes Locations: 0 1
  2. describe(callbacks)::context(when a tag is destroyed)::it#removes tags from petitions has a flog score of 25
expect { tag.destroy }.to change { petition.reload.tags }.from([tag.id]).to([]) end it "removes tags from archived petitions" do
  1. Similar code found in 2 nodes Locations: 0 1
  2. describe(callbacks)::context(when a tag is destroyed)::it#removes tags from archived petitions has a flog score of 25
expect { tag.destroy }.to change { archived_petition.reload.tags }.from([tag.id]).to([]) end end end describe ".by_name" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:tag_1) { FactoryBot.create(:tag, name: "baz") } let!(:tag_2) { FactoryBot.create(:tag, name: "foo") } let!(:tag_3) { FactoryBot.create(:tag, name: "bar") } it "returns tags in alphabetical order" do expect(described_class.by_name).to match_array([tag_3, tag_1, tag_2]) end end end