Top Level Namespace

Defined Under Namespace

Modules: Spec, ValidationExpectations

Constant Summary

Constants included from ValidationExpectations

ValidationExpectations::BasicValidations, ValidationExpectations::InListValidations

Instance Method Summary collapse

Instance Method Details

#it_should_be_createable(*args) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/rspec_validation_expectations/validation_expectations.rb', line 39

def it_should_be_createable *args
  model_name = described_type
  attributes = args.last.is_a?(Hash) ? args.last[:with] : {}

  it "should be creatable" do
    lambda { model_name.create attributes }.should change(model_name, :count).by(1)
  end
end

#it_should_belong_to(*one_or_more_associations) ⇒ Object



1
2
3
4
5
6
7
8
# File 'lib/rspec_validation_expectations/association_expectations.rb', line 1

def it_should_belong_to *one_or_more_associations
  model_name = described_type
  one_or_more_associations.each do |association|
    it "should belong to #{association}" do
      model_name.should belong_to(association)
    end
  end
end

#it_should_have_and_belong_to_many(*one_or_more_associations) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rspec_validation_expectations/association_expectations.rb', line 19

def it_should_have_and_belong_to_many *one_or_more_associations
  model_name = described_type
  one_or_more_associations.each do |association|
    it "should have and belong to many #{association}" do
      model_name.should have_and_belong_to_many(association)
    end
  end
end

#it_should_have_many(*one_or_more_associations) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rspec_validation_expectations/association_expectations.rb', line 10

def it_should_have_many *one_or_more_associations
  model_name = described_type
  one_or_more_associations.each do |association|
    it "should have many #{association}" do
      model_name.should have_many(association)
    end
  end
end

#it_should_have_one(*one_or_more_associations) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/rspec_validation_expectations/association_expectations.rb', line 28

def it_should_have_one *one_or_more_associations
  model_name = described_type
  one_or_more_associations.each do |association|
    it "should have one #{association}" do
      model_name.should have_one(association)
    end
  end
end

#it_should_protect(*one_or_more_attrs) ⇒ Object



1
2
3
4
5
6
7
8
# File 'lib/rspec_validation_expectations/other_expectations.rb', line 1

def it_should_protect(*one_or_more_attrs)
  model_class = described_type
  one_or_more_attrs.each do |attr|
    it "should protect attribute #{attr}" do
      model_class.protected_attributes.should include(attr.to_s)
    end
  end
end