Instantly share code, notes, and snippets.
Created
March 1, 2013 09:35
-
Save djforth/5063534 to your computer and use it in GitHub Desktop.
Shared Examples for models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared_examples_for 'manditory string' do |property| | |
it 'should respond' do | |
# pending | |
@record.respond_to?(property.to_sym).should be_true | |
end | |
it "is valid with valid attributes"do | |
@record.should be_valid | |
end | |
it "should reject a blank #{property}" do | |
# pending | |
@record.send(:"#{property}=",'') | |
@record.should_not be_valid | |
end | |
it "should reject a nil #{property}" do | |
# pending | |
@record.send(:"#{property}=",nil) | |
@record.should_not be_valid | |
end | |
end | |
shared_examples_for 'optional string' do |property| | |
it "should respond #{property}" do | |
# pending | |
@record.respond_to?(property.to_sym).should be_true | |
end | |
it "#{property} is valid with valid attributes"do | |
@record.should be_valid | |
end | |
end | |
shared_examples_for 'check position set' do |property| | |
it "should respond #{property}" do | |
# pending | |
@record.respond_to?(property.to_sym).should be_true | |
end | |
it "#{property} is valid with valid attributes"do | |
@record.should be_valid | |
end | |
it "Check position set" do | |
@record.save | |
@record.position.should == 1 | |
end | |
end | |
shared_examples_for 'optional boolean' do |property| | |
it "should respond #{property}" do | |
# pending | |
@record.respond_to?(property.to_sym).should be_true | |
end | |
it "#{property} is valid with valid attributes"do | |
@record.should be_valid | |
end | |
it "#{property} should be true"do | |
@record[property.to_sym].should eq(true) | |
end | |
end | |
shared_examples_for 'check association' do |association| | |
it "have many #{association}" do | |
@record.should respond_to(association) | |
end | |
end | |
shared_examples_for "check scope" do |no, property, title| | |
describe "Checks scope for #{title}" do | |
it "returns #{title} list" do | |
array.length.should == no | |
end | |
it "returns the #{title} right item" do | |
array.first[property.to_sym].should == result | |
end | |
end | |
end | |
shared_examples_for "check scope fails" do |title| | |
it "returns #{title} list" do | |
array.length.should == 0 | |
end | |
end | |
shared_examples_for "checks date scope" do |no, title| | |
describe "Checks scope for #{title}" do | |
it "returns #{title} list" do | |
array.length.should == no | |
end | |
it "returns the #{title} right item" do | |
array.first.should == result | |
end | |
end | |
end | |
shared_examples_for 'check position' do |pos_no| | |
it "set position" do | |
result.position = nil | |
result.run_callbacks(:save) | |
# raise displayed.inspect | |
result.position.should == pos_no | |
end | |
it "returns in correct order" do | |
# displayed = Company.ordered | |
pos = 0 | |
displayed.each do |comp| | |
comp.position.should > pos | |
pos = comp.position | |
end | |
end | |
end | |
shared_examples_for "visible" do |list| | |
it "returns all visible" do | |
displayed = list | |
displayed.each do |dis| | |
dis.displayit.should == true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment