primer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. data/History.txt +17 -0
  2. data/README.rdoc +74 -35
  3. data/example/README.rdoc +33 -23
  4. data/example/application.rb +2 -2
  5. data/example/console.rb +133 -0
  6. data/example/db/blog.sqlite3 +0 -0
  7. data/example/{models → db}/connection.rb +0 -0
  8. data/example/environment.rb +17 -4
  9. data/example/models/comment.rb +5 -0
  10. data/example/models/post.rb +5 -0
  11. data/example/script/setup_database.rb +8 -2
  12. data/example/views/comments.erb +6 -0
  13. data/example/views/layout.erb +1 -1
  14. data/example/views/show.erb +5 -1
  15. data/lib/primer/bus/amqp.rb +7 -5
  16. data/lib/primer/bus/amqp.rbc +1045 -0
  17. data/lib/primer/bus/memory.rbc +344 -0
  18. data/lib/primer/bus.rb +3 -2
  19. data/lib/primer/bus.rbc +872 -0
  20. data/lib/primer/cache/memory.rbc +1443 -0
  21. data/lib/primer/cache/redis.rb +2 -2
  22. data/lib/primer/cache/redis.rbc +1643 -0
  23. data/lib/primer/cache.rb +2 -16
  24. data/lib/primer/cache.rbc +1502 -0
  25. data/lib/primer/enabler.rbc +414 -0
  26. data/lib/primer/helpers.rbc +1438 -0
  27. data/lib/primer/lazyness.rb +63 -0
  28. data/lib/primer/lazyness.rbc +1442 -0
  29. data/lib/primer/real_time.rbc +1999 -0
  30. data/lib/primer/route_set.rb +1 -0
  31. data/lib/primer/route_set.rbc +1475 -0
  32. data/lib/primer/watcher/active_record_macros.rb +13 -3
  33. data/lib/primer/watcher/active_record_macros.rbc +1796 -0
  34. data/lib/primer/watcher/macros.rb +11 -14
  35. data/lib/primer/watcher/macros.rbc +1628 -0
  36. data/lib/primer/watcher.rb +2 -7
  37. data/lib/primer/watcher.rbc +1416 -0
  38. data/lib/primer/worker/active_record_agent.rb +30 -33
  39. data/lib/primer/worker/active_record_agent.rbc +2840 -0
  40. data/lib/primer/worker/changes_agent.rb +20 -0
  41. data/lib/primer/worker/changes_agent.rbc +578 -0
  42. data/lib/primer/worker.rb +20 -3
  43. data/lib/primer/worker.rbc +1254 -0
  44. data/lib/primer.rb +10 -2
  45. data/lib/primer.rbc +944 -0
  46. data/spec/db/test.sqlite3 +0 -0
  47. data/spec/models/artist.rb +3 -2
  48. data/spec/models/artist.rbc +288 -0
  49. data/spec/models/blog_post.rb +3 -1
  50. data/spec/models/blog_post.rbc +181 -0
  51. data/spec/models/calendar.rbc +209 -0
  52. data/spec/models/concert.rbc +211 -0
  53. data/spec/models/performance.rbc +177 -0
  54. data/spec/models/person.rb +1 -0
  55. data/spec/models/person.rbc +306 -0
  56. data/spec/models/watchable.rbc +363 -0
  57. data/spec/primer/bus_spec.rbc +940 -0
  58. data/spec/primer/cache_spec.rb +3 -3
  59. data/spec/primer/cache_spec.rbc +8535 -0
  60. data/spec/primer/helpers/erb_spec.rb +14 -14
  61. data/spec/primer/helpers/erb_spec.rbc +2485 -0
  62. data/spec/primer/lazyness_spec.rb +61 -0
  63. data/spec/primer/lazyness_spec.rbc +1408 -0
  64. data/spec/primer/watcher/active_record_spec.rb +15 -15
  65. data/spec/primer/watcher/active_record_spec.rbc +5202 -0
  66. data/spec/primer/watcher_spec.rbc +2645 -0
  67. data/spec/schema.rbc +775 -0
  68. data/spec/spec_helper.rb +3 -0
  69. data/spec/spec_helper.rbc +1193 -0
  70. data/spec/templates/page.erb +0 -1
  71. metadata +77 -70
  72. data/example/models/blog_post.rb +0 -4
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Primer::Lazyness do
4
+ before do
5
+ @artist = Artist.create(:name => "Menomena")
6
+ @artist_id = @artist.id
7
+ end
8
+
9
+ it "does not call the database when finding a record" do
10
+ Artist.should_not_receive(:find_by_sql)
11
+ Artist.find(@artist_id)
12
+ end
13
+
14
+ it "does not call the database when getting the primary key" do
15
+ Artist.should_not_receive(:find_by_sql)
16
+ Artist.find_by_id(@artist_id).id.should == @artist_id
17
+ end
18
+
19
+ it "calls the database to get attributes" do
20
+ Artist.should_receive(:find_by_sql).and_return([@artist])
21
+ Artist.find(@artist_id).name.should == "Menomena"
22
+ end
23
+
24
+ it "does not call the database to get the attribute we searched on" do
25
+ Artist.should_not_receive(:find_by_sql)
26
+ Artist.find_by_name("Menomena").name.should == "Menomena"
27
+ end
28
+
29
+ it "calls the database to get the primary key if needed" do
30
+ Artist.should_receive(:find_by_sql).and_return([@artist])
31
+ Artist.find_by_name("Menomena").id.should == @artist_id
32
+ end
33
+
34
+ it "should be able to tell that an object doesn't really exist" do
35
+ Artist.find_by_name("The National").should == nil
36
+ Artist.find_by_name("The National").should be_nil
37
+ end
38
+
39
+ it "does not call the database to get all the records" do
40
+ Artist.should_not_receive(:find_by_sql)
41
+ Artist.find(:all)
42
+ Artist.all
43
+ end
44
+
45
+ it "calls the database when we enumerate all the records" do
46
+ Artist.should_receive(:find_by_sql).and_return([@artist])
47
+ Artist.all.should == [@artist]
48
+ end
49
+
50
+ it "does not call the database to get the first record" do
51
+ Artist.should_not_receive(:find_by_sql)
52
+ Artist.find(:first)
53
+ Artist.first
54
+ end
55
+
56
+ it "calls the database when we want an attribute from the first record" do
57
+ Artist.should_receive(:find_by_sql).and_return([@artist])
58
+ Artist.first.name.should == "Menomena"
59
+ end
60
+ end
61
+