public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Search Repo:
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
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.
bsag (author)
Sun Jun 22 07:30:38 -0700 2008
commit  6f760c768e800714926e284dd955e2990bb60267
tree    061fb3d499748c4d3f1731f652658a97104ea0e1
parent  6e0999bd062c7e74a5a2594a4c06cb0ae176c112
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -1,7 +1,22 @@
1
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
0
 
0
-# one:
0
-# column: value
0
-#
0
-# two:
0
-# column: value
0
+agenda:
0
+ id: 2
0
+ name: agenda
0
+ position: 2
0
+ hide: false
0
+ user: admin_user
0
+
0
+call:
0
+ id: 3
0
+ name: call
0
+ position: 3
0
+ hide: true
0
+ user: admin_user
0
+
0
+email:
0
+ id: 4
0
+ name: email
0
+ position: 4
0
+ hide: false
0
+ user: admin_user
...
13
14
15
16
 
17
18
19
20
21
22
 
 
 
 
 
23
24
25
 
 
 
 
26
27
 
 
 
 
 
 
 
 
 
28
29
 
30
 
31
32
 
33
34
 
35
 
36
37
 
 
 
 
 
 
 
 
 
 
38
39
40
41
 
42
 
 
43
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
50
51
 
 
 
 
52
53
54
55
56
57
58
 
 
 
 
59
60
61
62
63
64
65
 
 
66
67
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
13
14
15
 
16
17
 
 
 
 
 
18
19
20
21
22
23
 
 
24
25
26
27
28
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
65
66
67
68
69
 
 
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
 
 
97
98
99
100
101
102
 
 
 
 
 
103
104
105
106
107
108
 
 
 
 
 
109
110
111
112
 
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
0
@@ -13,56 +13,139 @@ module ContextSpecHelper
0
    
0
 end
0
  
0
- describe Context do
0
+describe "Context validations" do
0
   include ContextSpecHelper
0
-
0
- before(:each) do
0
- @context = Context.new
0
- end
0
-
0
+
0
+ before(:each) do
0
+ @context = Context.new
0
+ end
0
+
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.save
0
+ Context.should have(4).records # 3 in fixtures 1 set up here
0
   end
0
-
0
+
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
1
+ @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
+ end
0
+
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
   end
0
-
0
+
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
   end
0
   
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
+ end
0
+
0
   it "should have one record in Context model class" do
0
     @context.name = "FooBar"
0
     @context.save
0
- Context.should have(1).record
0
+ Context.should have(4).records # 3 in fixture, one set up here
0
   end
0
+
0
+end
0
 
0
- 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
+
0
+ include ContextSpecHelper
0
+
0
+ it "should show hidden" do
0
+ contexts(:call).should be_hide # :hide should be true
0
+ end
0
+
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
+ end
0
+
0
+ it "should show not hidden" do
0
+ contexts(:call).hide = false
0
+ contexts(:call).should_not be_hide # :hide should be true
0
+ end
0
+
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
+ end
0
+
0
+ it "should return .title which matches name" do
0
+ contexts(:agenda).title.should eql(contexts(:agenda).name)
0
   end
0
   
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
   end
0
   
0
- it "should be active" do
0
- @context.attributes = valid_context_attributes
0
- @context.hide = false
0
- @context.save
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
   end
0
   
0
- it "should produce correct summary text for active context" do
0
- @context.attributes = valid_context_attributes
0
- @context.hide = false
0
- @context.save
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
   end
0
   
0
- end
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
+ end
0
+
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
+ end
0
+
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
+ end
0
+ end
0
+
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
+ t.complete!
0
+ t.save!
0
+ Context.find(contexts(:agenda)).done_todos.size.should eql(2)
0
+ end
0
+
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
+ t.complete!
0
+ t.save!
0
+ Context.find(contexts(:agenda)).not_done_todos.size.should eql(1)
0
+ end
0
+
0
+end

Comments

  • lukemelia Sun Jun 22 21:40:24 -0700 2008 at spec/fixtures/contexts.yml L1

    I would definitely encourage making a clean break from fixtures as you start these specs.

  • lukemelia Sun Jun 22 21:43:04 -0700 2008 at spec/models/context_spec.rb L42

    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.

  • bsag Mon Jun 23 00:33:36 -0700 2008

    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.

  • bsag Mon Jun 23 00:34:43 -0700 2008

    I forgot to say: if you know of any good resources for learning about mocks in rspec, let me know.

  • sr Mon Jun 23 03:10:22 -0700 2008

    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.

  • sr Mon Jun 23 03:11:34 -0700 2008


    I forgot to say: if you know of any good resources for learning about mocks
    > in rspec, let me know.

    I’ll make you a compilation of resources that helped me.