require "spec_helper" describe Resource do it "should have a factory" do expect(FactoryGirl.build(:resource)).to be_valid end context "constants" do it "should create a range using the min and max" do expect(Resource::RANGE).to eq(Resource::MIN..Resource::MAX) end end context "validations" do it { is_expected.to validate_presence_of(:example_attribute) } it { is_expected.to ensure_inclusion_of(:another_example_attribute).in_array(Resource::ExampleValues.constant_values).allow_blank } end context "associations" do it { is_expected.to belong_to(:another_resource) } it { is_expected.to have_one(:single_resource) } it { is_expected.to have_many(:more_resources) } end context "scopes" do describe "#self.scoped" do let!(:not_scoped) { FactoryGirl.create(:resource) } let!(:scoped) { FactoryGirl.create(:resource, attribute_for_scope: true) } it "should include only scoped resources" do expect(Resource.scoped).to include(scoped) expect(Resource.scoped).to_not include(not_scoped) end end end end