mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 01:08:50 +01:00
Context model specs completed. Using fixtures for some examples currently, but might convert to mocks in future. Specs now offer same coverage as Test::Unit tests for Context model.
This commit is contained in:
parent
1dc03195d0
commit
eb53865ff9
5 changed files with 250 additions and 34 deletions
|
|
@ -13,56 +13,139 @@ module ContextSpecHelper
|
|||
|
||||
end
|
||||
|
||||
describe Context do
|
||||
describe "Context validations" do
|
||||
include ContextSpecHelper
|
||||
|
||||
before(:each) do
|
||||
@context = Context.new
|
||||
end
|
||||
|
||||
it "should be valid" do
|
||||
@context.name = "FooBar"
|
||||
@context.should be_valid
|
||||
|
||||
before(:each) do
|
||||
@context = Context.new
|
||||
end
|
||||
|
||||
|
||||
it "should be valid" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.should be_valid
|
||||
@context.save
|
||||
Context.should have(4).records # 3 in fixtures 1 set up here
|
||||
end
|
||||
|
||||
it "should have two errors with a missing name" do
|
||||
@context.attributes = valid_context_attributes.except(:name)
|
||||
@context.should_not be_valid
|
||||
@context.should have(2).error_on(:name)
|
||||
@context.errors.on(:name)[0].should eql("context must have a name")
|
||||
@context.errors.on(:name)[1].should eql("context name must be less than 256 characters")
|
||||
end
|
||||
|
||||
it "should have one error with a name of more than 255 characters" do
|
||||
@context.name = "z" * 256
|
||||
@context.should_not be_valid
|
||||
@context.should have(1).error_on(:name)
|
||||
@context.errors.on(:name).should eql("context name must be less than 256 characters")
|
||||
end
|
||||
|
||||
|
||||
it "should have one error with name containing comma" do
|
||||
@context.name = "Foo,Bar"
|
||||
@context.should_not be_valid
|
||||
@context.should have(1).error_on(:name)
|
||||
@context.errors.on(:name).should eql("cannot contain the comma (',') character")
|
||||
end
|
||||
|
||||
it "should have one error if name already exists for user" do
|
||||
@existing_context = Context.new
|
||||
@existing_context.attributes = valid_context_attributes
|
||||
@existing_context.save
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.should_not be_valid
|
||||
@context.should have(1).error_on(:name)
|
||||
@context.errors.on(:name).should eql("already exists")
|
||||
end
|
||||
|
||||
it "should have one record in Context model class" do
|
||||
@context.name = "FooBar"
|
||||
@context.save
|
||||
Context.should have(1).record
|
||||
Context.should have(4).records # 3 in fixture, one set up here
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Context model" do
|
||||
fixtures :users, :todos, :contexts, :preferences
|
||||
|
||||
include ContextSpecHelper
|
||||
|
||||
it "should show hidden" do
|
||||
contexts(:call).should be_hide # :hide should be true
|
||||
end
|
||||
|
||||
it "should be hidden" do
|
||||
@context.attributes = valid_context_attributes
|
||||
@context.should be_hide # :hide should be true
|
||||
it "should be produce correct .summary text for hidden context" do
|
||||
contexts(:call).summary(1).should eql("<p>1. Context is Hidden.</p>")
|
||||
end
|
||||
|
||||
it "should show not hidden" do
|
||||
contexts(:call).hide = false
|
||||
contexts(:call).should_not be_hide # :hide should be true
|
||||
end
|
||||
|
||||
it "should produce correct .summary text for active context" do
|
||||
contexts(:call).hide = false
|
||||
contexts(:call).summary(1).should eql("<p>1. Context is Active.</p>")
|
||||
end
|
||||
|
||||
it "should return .title which matches name" do
|
||||
contexts(:agenda).title.should eql(contexts(:agenda).name)
|
||||
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>")
|
||||
it "should .find_by_namepart with exact match" do
|
||||
@found = Context.find_by_namepart('agenda')
|
||||
@found.should_not eql(nil)
|
||||
@found.id.should eql(contexts(:agenda).id)
|
||||
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
|
||||
it "should .find_by_namepart with partial match" do
|
||||
@found = Context.find_by_namepart('ag')
|
||||
@found.should_not eql(nil)
|
||||
@found.id.should eql(contexts(:agenda).id)
|
||||
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>")
|
||||
it "should return id with .to_param" do
|
||||
Context.find(2).to_param.should eql("2")
|
||||
end
|
||||
|
||||
end
|
||||
it "should return feed options" do
|
||||
opts = Context.feed_options(users(:admin_user))
|
||||
opts[:title].should eql("Tracks Contexts")
|
||||
opts[:description].should eql("Lists all the contexts for Admin Schmadmin")
|
||||
end
|
||||
|
||||
it "should create null Context with .null_object" do
|
||||
@empty = Context.null_object
|
||||
@empty.should be_an_instance_of(NullContext)
|
||||
@empty.id.should eql(nil)
|
||||
@empty.name.should eql('')
|
||||
end
|
||||
|
||||
it "should delete todos within context when context deleted" do
|
||||
contexts(:agenda).todos.count.should eql(3)
|
||||
agenda_todo_ids = contexts(:agenda).todos.collect{|t| t.id }
|
||||
contexts(:agenda).destroy
|
||||
agenda_todo_ids.each do |todo_id|
|
||||
Todo.find(:all).should_not include(todo_id)
|
||||
end
|
||||
end
|
||||
|
||||
it "should return correct number of done todos" do
|
||||
contexts(:agenda).done_todos.size.should eql(1)
|
||||
t = contexts(:agenda).not_done_todos[0]
|
||||
t.complete!
|
||||
t.save!
|
||||
Context.find(contexts(:agenda)).done_todos.size.should eql(2)
|
||||
end
|
||||
|
||||
it "should return correct number of not done todos" do
|
||||
contexts(:agenda).not_done_todos.size.should eql(2)
|
||||
t = contexts(:agenda).not_done_todos[0]
|
||||
t.complete!
|
||||
t.save!
|
||||
Context.find(contexts(:agenda)).not_done_todos.size.should eql(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue