paper_trail_manager 0.1.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 (89) hide show
  1. data/Gemfile +17 -0
  2. data/Gemfile.lock +147 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +32 -0
  5. data/Rakefile +52 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/paper_trail_manager/changes_controller.rb +109 -0
  8. data/app/helpers/paper_trail_manager/changes_helper.rb +99 -0
  9. data/app/views/paper_trail_manager/changes/_version.html.haml +32 -0
  10. data/app/views/paper_trail_manager/changes/index.atom.builder +44 -0
  11. data/app/views/paper_trail_manager/changes/index.html.haml +26 -0
  12. data/app/views/paper_trail_manager/changes/show.html.haml +8 -0
  13. data/lib/paper_trail_manager.rb +70 -0
  14. data/paper_trail_manager.gemspec +209 -0
  15. data/spec/controllers/paper_trail_manager/changes_controller_spec.rb +8 -0
  16. data/spec/dummy/Rakefile +7 -0
  17. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  18. data/spec/dummy/app/controllers/entities_controller.rb +83 -0
  19. data/spec/dummy/app/controllers/platforms_controller.rb +83 -0
  20. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  21. data/spec/dummy/app/helpers/entities_helper.rb +2 -0
  22. data/spec/dummy/app/helpers/platforms_helper.rb +2 -0
  23. data/spec/dummy/app/models/entity.rb +6 -0
  24. data/spec/dummy/app/models/platform.rb +6 -0
  25. data/spec/dummy/app/views/entities/_form.html.erb +17 -0
  26. data/spec/dummy/app/views/entities/edit.html.erb +6 -0
  27. data/spec/dummy/app/views/entities/index.html.erb +21 -0
  28. data/spec/dummy/app/views/entities/new.html.erb +5 -0
  29. data/spec/dummy/app/views/entities/show.html.erb +5 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/app/views/platforms/_form.html.erb +17 -0
  32. data/spec/dummy/app/views/platforms/edit.html.erb +6 -0
  33. data/spec/dummy/app/views/platforms/index.html.erb +21 -0
  34. data/spec/dummy/app/views/platforms/new.html.erb +5 -0
  35. data/spec/dummy/app/views/platforms/show.html.erb +5 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/config/application.rb +45 -0
  38. data/spec/dummy/config/boot.rb +10 -0
  39. data/spec/dummy/config/database.yml +22 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +26 -0
  42. data/spec/dummy/config/environments/production.rb +49 -0
  43. data/spec/dummy/config/environments/test.rb +35 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  45. data/spec/dummy/config/initializers/inflections.rb +10 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  48. data/spec/dummy/config/initializers/session_store.rb +8 -0
  49. data/spec/dummy/config/locales/en.yml +5 -0
  50. data/spec/dummy/config/routes.rb +64 -0
  51. data/spec/dummy/db/migrate/20110228091428_create_entities.rb +14 -0
  52. data/spec/dummy/db/migrate/20110228093241_create_platforms.rb +14 -0
  53. data/spec/dummy/db/migrate/20110228094444_create_versions.rb +18 -0
  54. data/spec/dummy/db/schema.rb +40 -0
  55. data/spec/dummy/public/404.html +26 -0
  56. data/spec/dummy/public/422.html +26 -0
  57. data/spec/dummy/public/500.html +26 -0
  58. data/spec/dummy/public/favicon.ico +0 -0
  59. data/spec/dummy/public/javascripts/application.js +2 -0
  60. data/spec/dummy/public/javascripts/controls.js +965 -0
  61. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  62. data/spec/dummy/public/javascripts/effects.js +1123 -0
  63. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  64. data/spec/dummy/public/javascripts/rails.js +175 -0
  65. data/spec/dummy/script/rails +6 -0
  66. data/spec/dummy/spec/controllers/entities_controller_spec.rb +125 -0
  67. data/spec/dummy/spec/controllers/platforms_controller_spec.rb +125 -0
  68. data/spec/dummy/spec/helpers/entities_helper_spec.rb +15 -0
  69. data/spec/dummy/spec/helpers/platforms_helper_spec.rb +15 -0
  70. data/spec/dummy/spec/integration/navigation_spec.rb +9 -0
  71. data/spec/dummy/spec/integration/paper_trail_manager_spec.rb +194 -0
  72. data/spec/dummy/spec/models/entity_spec.rb +14 -0
  73. data/spec/dummy/spec/models/platform_spec.rb +14 -0
  74. data/spec/dummy/spec/requests/entities_spec.rb +11 -0
  75. data/spec/dummy/spec/requests/platforms_spec.rb +11 -0
  76. data/spec/dummy/spec/routing/entities_routing_spec.rb +35 -0
  77. data/spec/dummy/spec/routing/platforms_routing_spec.rb +35 -0
  78. data/spec/dummy/spec/views/entities/edit.html.erb_spec.rb +15 -0
  79. data/spec/dummy/spec/views/entities/index.html.erb_spec.rb +14 -0
  80. data/spec/dummy/spec/views/entities/new.html.erb_spec.rb +15 -0
  81. data/spec/dummy/spec/views/entities/show.html.erb_spec.rb +11 -0
  82. data/spec/dummy/spec/views/platforms/edit.html.erb_spec.rb +15 -0
  83. data/spec/dummy/spec/views/platforms/index.html.erb_spec.rb +14 -0
  84. data/spec/dummy/spec/views/platforms/new.html.erb_spec.rb +15 -0
  85. data/spec/dummy/spec/views/platforms/show.html.erb_spec.rb +11 -0
  86. data/spec/paper_trail_manager_spec.rb +7 -0
  87. data/spec/spec_helper.rb +82 -0
  88. data/spec/support/factories.rb +12 -0
  89. metadata +387 -0
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the PlatformsHelper. For example:
5
+ #
6
+ # describe PlatformsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe PlatformsHelper do
14
+ #IK# pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Navigation" do
4
+ include Capybara
5
+
6
+ it "should be a valid app" do
7
+ ::Rails.application.should be_a(Dummy::Application)
8
+ end
9
+ end
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+
3
+ describe PaperTrailManager do
4
+ include Capybara
5
+
6
+ def version
7
+ return assigns[:version]
8
+ end
9
+
10
+ def versions
11
+ return assigns[:versions]
12
+ end
13
+
14
+ def item_types
15
+ return versions.map(&:item_type).uniq.sort
16
+ end
17
+
18
+ def populate
19
+ @reimu = FactoryGirl.create(:entity, :name => "Miko Hakurei Reimu", :status => "Highly Responsive to Prayers")
20
+ @reimu.update_attributes(:name => "Hakurei Reimu", :status => "Phantasmagoria of Dimensional Dream")
21
+ @reimu.update_attributes(:status => "Perfect Cherry Blossom")
22
+
23
+ @sakuya = FactoryGirl.create(:entity, :name => "Sakuya Izayoi", :status => "Flowering Night")
24
+
25
+ @flanchan = FactoryGirl.create(:entity, :name => "Flandre Scarlet", :status => "The Embodiment of Scarlet Devil")
26
+ @flanchan.destroy
27
+
28
+ @kyuu_hachi = FactoryGirl.create(:platform, :name => "PC-9801", :status => "SUGOI!!1!")
29
+ @kyuu_hachi.update_attributes(:status => "Kimochi warui.")
30
+ @kyuu_hachi.destroy
31
+
32
+ @uinodouzu = FactoryGirl.create(:platform, :name => "Mikorusofto Uinodouzu", :status => 'o-O')
33
+ end
34
+
35
+ context "without changes" do
36
+ context "index" do
37
+ it "should have no changes by default" do
38
+ get "/changes"
39
+
40
+ assigns[:versions].should be_empty
41
+ end
42
+ end
43
+ end
44
+
45
+ context "with changes" do
46
+ before(:all) do
47
+ populate
48
+ end
49
+
50
+ after(:all) do
51
+ Entity.destroy_all
52
+ Platform.destroy_all
53
+ Version.destroy_all
54
+ end
55
+
56
+ context "index" do
57
+ context "when getting all changes" do
58
+ context "and authorized" do
59
+ before(:all) { get changes_path }
60
+
61
+ it "should have all changes" do
62
+ versions.size.should == 10
63
+ end
64
+
65
+ it "should have changes for all changed item types" do
66
+ item_types.should == ["Entity", "Platform"]
67
+ end
68
+
69
+ it "should order changes with newest and highest id at the top" do
70
+ versions.map(&:id).should == versions.sort_by { |o| [o.created_at, o.id] }.reverse.map(&:id)
71
+ end
72
+ end
73
+
74
+ context "when not authorized" do
75
+ it "should display an error if user is not allowed to list changes"
76
+ end
77
+ end
78
+
79
+ context "when getting changes for a specific type" do
80
+ context "that exists" do
81
+ before(:all) { get changes_path(:type => "Entity") }
82
+
83
+ it "should show a subset of the changes" do
84
+ versions.size.should == 6
85
+ end
86
+
87
+ it "should have changes only for that type" do
88
+ item_types.should == ["Entity"]
89
+ end
90
+ end
91
+
92
+ context "that doesn't exist" do
93
+ it "should display ana error that the type doesn't exist"
94
+ end
95
+ end
96
+
97
+ context "when getting changes for a specific record" do
98
+ context "that exists" do
99
+ before(:all) { get changes_path(:type => "Entity", :id => @reimu.id) }
100
+
101
+ it "should show a subset of the changes" do
102
+ versions.size.should == 3
103
+ end
104
+
105
+ it "should have changes only for that type" do
106
+ item_types.should == ["Entity"]
107
+ end
108
+
109
+ it "should have changes only for that record" do
110
+ versions.map(&:item_id).uniq.should == [@reimu.id]
111
+ end
112
+ end
113
+
114
+ context "that doesn't exist" do
115
+ it "should display an error that the record doesn't exist"
116
+ end
117
+ end
118
+ end
119
+
120
+ context "show a change" do
121
+ context "that exists" do
122
+ context "when authorized" do
123
+ before(:all) do
124
+ @version = @reimu.versions.last
125
+ get change_path(@version)
126
+ end
127
+
128
+ it "should show the requested change" do
129
+ version.should == @version
130
+ end
131
+
132
+ it "should show a change with the right event" do
133
+ version.event.should == "update"
134
+ end
135
+
136
+ it "should be associated with the expected record" do
137
+ version.item.should == @reimu
138
+ end
139
+ end
140
+
141
+ context "when not authorized" do
142
+ it "should display an error if user is not allowed to show the change"
143
+ end
144
+ end
145
+
146
+ context "that doesn't exist" do
147
+ it "should display an error that the change doesn't exist"
148
+ end
149
+ end
150
+ end
151
+
152
+ context "when rolling back changes" do
153
+ context "that that exist" do
154
+ before(:each) { populate }
155
+
156
+ context "when authorized" do
157
+ it "should rollback a newly-created record by deleting it" do
158
+ Entity.exists?(@reimu.id).should be_true
159
+
160
+ put change_path(@reimu.versions.first)
161
+
162
+ Entity.exists?(@reimu.id).should be_false
163
+ end
164
+
165
+ it "should rollback an edit by reverting to the previous state" do
166
+ @reimu.reload
167
+ @reimu.status.should == "Perfect Cherry Blossom"
168
+
169
+ put change_path(@reimu.versions.last)
170
+
171
+ @reimu.reload
172
+ @reimu.status.should == "Phantasmagoria of Dimensional Dream"
173
+ end
174
+
175
+ it "should rollback a delete by restoring the record" do
176
+ Entity.exists?(@flanchan.id).should be_false
177
+
178
+ put change_path(Version.where(:item_id => @flanchan.id, :item_type => "Entity").last)
179
+
180
+ flanchan = Entity.find(@flanchan.id)
181
+ flanchan.status.should == "The Embodiment of Scarlet Devil"
182
+ end
183
+ end
184
+
185
+ context "when not authorized" do
186
+ it "should display an error if user is not allowed to revert that change"
187
+ end
188
+ end
189
+
190
+ context "that don't exist" do
191
+ it "should display an error that the change doesn't exist"
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Entity do
4
+ context "when creating a sample record" do
5
+ subject { FactoryGirl.create(:entity) }
6
+
7
+ its(:id) { should be_present }
8
+ its(:name) { should be_present }
9
+ its(:status) { should be_present }
10
+
11
+ it { should be_valid }
12
+ it { should_not be_a_new_record }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Platform do
4
+ context "when creating a sample record" do
5
+ subject { FactoryGirl.create(:platform) }
6
+
7
+ its(:id) { should be_present }
8
+ its(:name) { should be_present }
9
+ its(:status) { should be_present }
10
+
11
+ it { should be_valid }
12
+ it { should_not be_a_new_record }
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Entities" do
4
+ describe "GET /entities" do
5
+ it "works! (now write some real specs)" do
6
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
7
+ get entities_path
8
+ response.status.should be(200)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Platforms" do
4
+ describe "GET /platforms" do
5
+ it "works! (now write some real specs)" do
6
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
7
+ get platforms_path
8
+ response.status.should be(200)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe EntitiesController do
4
+ describe "routing" do
5
+
6
+ it "recognizes and generates #index" do
7
+ { :get => "/entities" }.should route_to(:controller => "entities", :action => "index")
8
+ end
9
+
10
+ it "recognizes and generates #new" do
11
+ { :get => "/entities/new" }.should route_to(:controller => "entities", :action => "new")
12
+ end
13
+
14
+ it "recognizes and generates #show" do
15
+ { :get => "/entities/1" }.should route_to(:controller => "entities", :action => "show", :id => "1")
16
+ end
17
+
18
+ it "recognizes and generates #edit" do
19
+ { :get => "/entities/1/edit" }.should route_to(:controller => "entities", :action => "edit", :id => "1")
20
+ end
21
+
22
+ it "recognizes and generates #create" do
23
+ { :post => "/entities" }.should route_to(:controller => "entities", :action => "create")
24
+ end
25
+
26
+ it "recognizes and generates #update" do
27
+ { :put => "/entities/1" }.should route_to(:controller => "entities", :action => "update", :id => "1")
28
+ end
29
+
30
+ it "recognizes and generates #destroy" do
31
+ { :delete => "/entities/1" }.should route_to(:controller => "entities", :action => "destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe PlatformsController do
4
+ describe "routing" do
5
+
6
+ it "recognizes and generates #index" do
7
+ { :get => "/platforms" }.should route_to(:controller => "platforms", :action => "index")
8
+ end
9
+
10
+ it "recognizes and generates #new" do
11
+ { :get => "/platforms/new" }.should route_to(:controller => "platforms", :action => "new")
12
+ end
13
+
14
+ it "recognizes and generates #show" do
15
+ { :get => "/platforms/1" }.should route_to(:controller => "platforms", :action => "show", :id => "1")
16
+ end
17
+
18
+ it "recognizes and generates #edit" do
19
+ { :get => "/platforms/1/edit" }.should route_to(:controller => "platforms", :action => "edit", :id => "1")
20
+ end
21
+
22
+ it "recognizes and generates #create" do
23
+ { :post => "/platforms" }.should route_to(:controller => "platforms", :action => "create")
24
+ end
25
+
26
+ it "recognizes and generates #update" do
27
+ { :put => "/platforms/1" }.should route_to(:controller => "platforms", :action => "update", :id => "1")
28
+ end
29
+
30
+ it "recognizes and generates #destroy" do
31
+ { :delete => "/platforms/1" }.should route_to(:controller => "platforms", :action => "destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "entities/edit.html.erb" do
4
+ before(:each) do
5
+ @entity = assign(:entity, stub_model(Entity))
6
+ end
7
+
8
+ it "renders the edit entity form" do
9
+ render
10
+
11
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
12
+ assert_select "form", :action => entities_path(@entity), :method => "post" do
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "entities/index.html.erb" do
4
+ before(:each) do
5
+ assign(:entities, [
6
+ stub_model(Entity),
7
+ stub_model(Entity)
8
+ ])
9
+ end
10
+
11
+ it "renders a list of entities" do
12
+ render
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "entities/new.html.erb" do
4
+ before(:each) do
5
+ assign(:entity, stub_model(Entity).as_new_record)
6
+ end
7
+
8
+ it "renders new entity form" do
9
+ render
10
+
11
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
12
+ assert_select "form", :action => entities_path, :method => "post" do
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "entities/show.html.erb" do
4
+ before(:each) do
5
+ @entity = assign(:entity, stub_model(Entity))
6
+ end
7
+
8
+ it "renders attributes in <p>" do
9
+ render
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "platforms/edit.html.erb" do
4
+ before(:each) do
5
+ @platform = assign(:platform, stub_model(Platform))
6
+ end
7
+
8
+ it "renders the edit platform form" do
9
+ render
10
+
11
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
12
+ assert_select "form", :action => platforms_path(@platform), :method => "post" do
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "platforms/index.html.erb" do
4
+ before(:each) do
5
+ assign(:platforms, [
6
+ stub_model(Platform),
7
+ stub_model(Platform)
8
+ ])
9
+ end
10
+
11
+ it "renders a list of platforms" do
12
+ render
13
+ end
14
+ end