mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Initial work on specs for models - Context model spec started.
This commit is contained in:
parent
5f3cdf5ce8
commit
1dc03195d0
2 changed files with 75 additions and 0 deletions
7
spec/fixtures/contexts.yml
vendored
Normal file
7
spec/fixtures/contexts.yml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# one:
|
||||
# column: value
|
||||
#
|
||||
# two:
|
||||
# column: value
|
||||
68
spec/models/context_spec.rb
Normal file
68
spec/models/context_spec.rb
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
module ContextSpecHelper
|
||||
|
||||
def valid_context_attributes
|
||||
{
|
||||
:name => "FooBar",
|
||||
:position => 1,
|
||||
:hide => true,
|
||||
:user_id => 1
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe Context do
|
||||
include ContextSpecHelper
|
||||
|
||||
before(:each) do
|
||||
@context = Context.new
|
||||
end
|
||||
|
||||
it "should be valid" do
|
||||
@context.name = "FooBar"
|
||||
@context.should be_valid
|
||||
end
|
||||
|
||||
it "should have one error with a name of more than 255 characters" do
|
||||
@context.name = "z" * 256
|
||||
@context.should have(1).error_on(:name)
|
||||
end
|
||||
|
||||
it "should have one error with name containing comma" do
|
||||
@context.name = "Foo,Bar"
|
||||
@context.should have(1).error_on(:name)
|
||||
end
|
||||
|
||||
it "should have one record in Context model class" do
|
||||
@context.name = "FooBar"
|
||||
@context.save
|
||||
Context.should have(1).record
|
||||
end
|
||||
|
||||
it "should be hidden" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.should be_hide # :hide should be true
|
||||
end
|
||||
|
||||
it "should be produce correct summary text for hidden context" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.summary(1).should eql("<p>1. Context is Hidden.</p>")
|
||||
end
|
||||
|
||||
it "should be active" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.hide = false
|
||||
@context.save
|
||||
@context.should_not be_hide # :hide should be true
|
||||
end
|
||||
|
||||
it "should produce correct summary text for active context" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.hide = false
|
||||
@context.save
|
||||
@context.summary(1).should eql("<p>1. Context is Active.</p>")
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue