Files
grecia/spec/models/widget/card_spec.rb
Javi Martín d410fcbc0e Split scope tests
In the scenario where we want to test scopes and use `match_array`, we
usually declare variables we never use, which raises a warning in the
Ruby interpreter (since the main cause for an unused variable is a
typo).

So I've decided to just split the tests into cases where every record is
returned and cases were no records are returned, just like we do in
other places.

There are several other options we've considered:

1. Don't declare unused variables, but declare the ones we use
2. Prefix unused variables with un underscore
3. Declare just one variable being an array containing all elements, and
access the elements using Array#[]
4. Don't declare any variables, and compare results against attributes
such as titles

None of these options was met with enthusiasm.
2019-09-30 15:46:58 +02:00

44 lines
1.0 KiB
Ruby

require "rails_helper"
describe Widget::Card do
let(:card) { build(:widget_card) }
it_behaves_like "globalizable", :widget_card
context "validations" do
it "is valid" do
expect(card).to be_valid
end
end
describe "#header" do
it "returns header cards" do
header = create(:widget_card, header: true)
expect(Widget::Card.header).to eq([header])
end
it "does not return regular cards" do
create(:widget_card, header: false)
expect(Widget::Card.header).to be_empty
end
end
describe "#body" do
it "returns cards for the homepage body" do
header = create(:widget_card, header: true)
card1 = create(:widget_card, header: false)
card2 = create(:widget_card, header: false)
page_card = create(:widget_card, header: false, page: create(:site_customization_page))
expect(Widget::Card.body).to match_array [card1, card2]
expect(Widget::Card.body).not_to include(header)
expect(Widget::Card.body).not_to include(page_card)
end
end
end