0
@@ -13,56 +13,139 @@ module ContextSpecHelper
0
+
describe "Context validations" do
0
include ContextSpecHelper
0
- @context = Context.new
0
+ @context = Context.new
0
it "should be valid" do
0
- @context.name = "FooBar"
0
- @context.should be_valid
0
+ @context.attributes = valid_context_attributes
0
+ @context.should be_valid
0
+ Context.should have(4).records # 3 in fixtures 1 set up here
0
+ it "should have two errors with a missing name" do
0
+ @context.attributes = valid_context_attributes.except(:name)
0
+ @context.should_not be_valid
+ @context.should have(2).error_on(:name)
0
+ @context.errors.on(:name)[0].should eql("context must have a name")
0
+ @context.errors.on(:name)[1].should eql("context name must be less than 256 characters")
0
it "should have one error with a name of more than 255 characters" do
0
@context.name = "z" * 256
0
+ @context.should_not be_valid
0
@context.should have(1).error_on(:name)
0
+ @context.errors.on(:name).should eql("context name must be less than 256 characters")
0
it "should have one error with name containing comma" do
0
@context.name = "Foo,Bar"
0
+ @context.should_not be_valid
0
@context.should have(1).error_on(:name)
0
+ @context.errors.on(:name).should eql("cannot contain the comma (',') character")
0
+ it "should have one error if name already exists for user" do
0
+ @existing_context = Context.new
0
+ @existing_context.attributes = valid_context_attributes
0
+ @existing_context.save
0
+ @context.attributes = valid_context_attributes
0
+ @context.should_not be_valid
0
+ @context.should have(1).error_on(:name)
0
+ @context.errors.on(:name).should eql("already exists")
0
it "should have one record in Context model class" do
0
@context.name = "FooBar"
0
- Context.should have(
1).record0
+ Context.should have(
4).records # 3 in fixture, one set up here0
- it "should be hidden" do
0
- @context.attributes = valid_context_attributes
0
- @context.should be_hide # :hide should be true
0
+describe "Context model" do
0
+ fixtures :users, :todos, :contexts, :preferences
0
+ include ContextSpecHelper
0
+ it "should show hidden" do
0
+ contexts(:call).should be_hide # :hide should be true
0
+ it "should be produce correct .summary text for hidden context" do
0
+ contexts(:call).summary(1).should eql("<p>1. Context is Hidden.</p>")
0
+ it "should show not hidden" do
0
+ contexts(:call).hide = false
0
+ contexts(:call).should_not be_hide # :hide should be true
0
+ it "should produce correct .summary text for active context" do
0
+ contexts(:call).hide = false
0
+ contexts(:call).summary(1).should eql("<p>1. Context is Active.</p>")
0
+ it "should return .title which matches name" do
0
+ contexts(:agenda).title.should eql(contexts(:agenda).name)
0
- it "should be produce correct summary text for hidden context" do
0
- @context.attributes = valid_context_attributes
0
- @context.summary(1).should eql("<p>1. Context is Hidden.</p>")
0
+ it "should .find_by_namepart with exact match" do
0
+ @found = Context.find_by_namepart('agenda')
0
+ @found.should_not eql(nil)
0
+ @found.id.should eql(contexts(:agenda).id)
0
- it "should be active" do
0
- @context.attributes = valid_context_attributes
0
- @context.should_not be_hide # :hide should be true
0
+ it "should .find_by_namepart with partial match" do
0
+ @found = Context.find_by_namepart('ag')
0
+ @found.should_not eql(nil)
0
+ @found.id.should eql(contexts(:agenda).id)
0
- it "should produce correct summary text for active context" do
0
- @context.attributes = valid_context_attributes
0
- @context.summary(1).should eql("<p>1. Context is Active.</p>")
0
+ it "should return id with .to_param" do
0
+ Context.find(2).to_param.should eql("2")
0
+ it "should return feed options" do
0
+ opts = Context.feed_options(users(:admin_user))
0
+ opts[:title].should eql("Tracks Contexts")
0
+ opts[:description].should eql("Lists all the contexts for Admin Schmadmin")
0
+ it "should create null Context with .null_object" do
0
+ @empty = Context.null_object
0
+ @empty.should be_an_instance_of(NullContext)
0
+ @empty.id.should eql(nil)
0
+ @empty.name.should eql('')
0
+ it "should delete todos within context when context deleted" do
0
+ contexts(:agenda).todos.count.should eql(3)
0
+ agenda_todo_ids = contexts(:agenda).todos.collect{|t| t.id }
0
+ contexts(:agenda).destroy
0
+ agenda_todo_ids.each do |todo_id|
0
+ Todo.find(:all).should_not include(todo_id)
0
+ it "should return correct number of done todos" do
0
+ contexts(:agenda).done_todos.size.should eql(1)
0
+ t = contexts(:agenda).not_done_todos[0]
0
+ Context.find(contexts(:agenda)).done_todos.size.should eql(2)
0
+ it "should return correct number of not done todos" do
0
+ contexts(:agenda).not_done_todos.size.should eql(2)
0
+ t = contexts(:agenda).not_done_todos[0]
0
+ Context.find(contexts(:agenda)).not_done_todos.size.should eql(1)
Comments
I would definitely encourage making a clean break from fixtures as you start these specs.
This spec is failing for me. I only get 1 error, that a name is required.
Also, I wouldn’t use should be_valid in this spec. The should have(2).errors_on(:name) is more focused and is more expressive of what you’re getting at in this spec.
Thanks for the tips, Luke! I’m very new to rspec, so I’ve got a lot to learn. As I mentioned in the commit message, I’m aiming to move away from fixtures, but I need to learn more about mocks before I do that. Oddly, the example at L42 passes for me, so I’ll have to look into that.
I forgot to say: if you know of any good resources for learning about mocks in rspec, let me know.
I fixed the spec in my fork. See http://github.com/sr/tracks/commit/60b986a5b971f704a41f1c720a9471ea92040fc7
I’ll send you a pull request pretty sound with more specs.