draftsman 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +97 -0
  9. data/LICENSE +20 -0
  10. data/README.md +506 -0
  11. data/Rakefile +6 -0
  12. data/draftsman.gemspec +33 -0
  13. data/lib/draftsman/config.rb +13 -0
  14. data/lib/draftsman/draft.rb +289 -0
  15. data/lib/draftsman/frameworks/cucumber.rb +7 -0
  16. data/lib/draftsman/frameworks/rails.rb +58 -0
  17. data/lib/draftsman/frameworks/rspec.rb +16 -0
  18. data/lib/draftsman/frameworks/sinatra.rb +31 -0
  19. data/lib/draftsman/model.rb +428 -0
  20. data/lib/draftsman/serializers/json.rb +17 -0
  21. data/lib/draftsman/serializers/yaml.rb +17 -0
  22. data/lib/draftsman/version.rb +3 -0
  23. data/lib/draftsman.rb +101 -0
  24. data/lib/generators/draftsman/install_generator.rb +27 -0
  25. data/lib/generators/draftsman/templates/add_object_changes_column_to_drafts.rb +9 -0
  26. data/lib/generators/draftsman/templates/config/initializers/draftsman.rb +11 -0
  27. data/lib/generators/draftsman/templates/create_drafts.rb +22 -0
  28. data/spec/controllers/informants_controller_spec.rb +27 -0
  29. data/spec/controllers/users_controller_spec.rb +23 -0
  30. data/spec/controllers/whodunnits_controller_spec.rb +24 -0
  31. data/spec/draftsman_spec.rb +19 -0
  32. data/spec/dummy/Rakefile +7 -0
  33. data/spec/dummy/app/assets/images/rails.png +0 -0
  34. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +20 -0
  37. data/spec/dummy/app/controllers/informants_controller.rb +8 -0
  38. data/spec/dummy/app/controllers/users_controller.rb +8 -0
  39. data/spec/dummy/app/controllers/whodunnits_controller.rb +8 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/helpers/messages_helper.rb +2 -0
  42. data/spec/dummy/app/mailers/.gitkeep +0 -0
  43. data/spec/dummy/app/models/bastard.rb +3 -0
  44. data/spec/dummy/app/models/child.rb +4 -0
  45. data/spec/dummy/app/models/parent.rb +5 -0
  46. data/spec/dummy/app/models/trashable.rb +3 -0
  47. data/spec/dummy/app/models/vanilla.rb +3 -0
  48. data/spec/dummy/app/models/whitelister.rb +3 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  50. data/spec/dummy/config/application.rb +37 -0
  51. data/spec/dummy/config/boot.rb +6 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +32 -0
  55. data/spec/dummy/config/environments/production.rb +73 -0
  56. data/spec/dummy/config/environments/test.rb +39 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/inflections.rb +15 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  60. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  61. data/spec/dummy/config/initializers/session_store.rb +8 -0
  62. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/spec/dummy/config/locales/en.yml +5 -0
  64. data/spec/dummy/config/routes.rb +6 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/db/migrate/20110208155312_set_up_test_tables.rb +86 -0
  67. data/spec/dummy/db/schema.rb +106 -0
  68. data/spec/dummy/db/seeds.rb +7 -0
  69. data/spec/dummy/lib/assets/.gitkeep +0 -0
  70. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  71. data/spec/dummy/log/.gitkeep +0 -0
  72. data/spec/dummy/public/404.html +26 -0
  73. data/spec/dummy/public/422.html +26 -0
  74. data/spec/dummy/public/500.html +25 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/script/rails +6 -0
  77. data/spec/models/child_spec.rb +205 -0
  78. data/spec/models/draft_spec.rb +297 -0
  79. data/spec/models/parent_spec.rb +191 -0
  80. data/spec/models/trashable_spec.rb +164 -0
  81. data/spec/models/vanilla_spec.rb +201 -0
  82. data/spec/models/whitelister_spec.rb +262 -0
  83. data/spec/spec_helper.rb +52 -0
  84. metadata +304 -0
@@ -0,0 +1,106 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20110208155312) do
15
+
16
+ create_table "bastards", force: true do |t|
17
+ t.string "name"
18
+ t.integer "parent_id"
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ create_table "change_hoarders", force: true do |t|
24
+ t.integer "draft_id"
25
+ end
26
+
27
+ create_table "children", force: true do |t|
28
+ t.string "name"
29
+ t.integer "parent_id"
30
+ t.integer "draft_id"
31
+ t.datetime "trashed_at"
32
+ t.datetime "published_at"
33
+ t.datetime "created_at"
34
+ t.datetime "updated_at"
35
+ end
36
+
37
+ create_table "draft_as_sketches", force: true do |t|
38
+ t.string "name"
39
+ t.integer "sketch_id"
40
+ t.datetime "published_at"
41
+ t.datetime "created_at"
42
+ t.datetime "updated_at"
43
+ end
44
+
45
+ create_table "draft_dependencies", force: true do |t|
46
+ t.integer "draft_id", null: false
47
+ t.integer "dependency_id", null: false
48
+ end
49
+
50
+ create_table "draft_dependents", force: true do |t|
51
+ t.integer "draft_id", null: false
52
+ t.integer "dependent_id", null: false
53
+ end
54
+
55
+ create_table "drafts", force: true do |t|
56
+ t.string "item_type"
57
+ t.integer "item_id"
58
+ t.string "event", null: false
59
+ t.string "whodunnit"
60
+ t.text "object"
61
+ t.text "object_changes"
62
+ t.text "previous_draft"
63
+ t.datetime "created_at"
64
+ t.datetime "updated_at"
65
+ t.integer "answer"
66
+ t.string "ip"
67
+ t.string "user_agent"
68
+ end
69
+
70
+ create_table "parents", force: true do |t|
71
+ t.string "name"
72
+ t.integer "draft_id"
73
+ t.datetime "trashed_at"
74
+ t.datetime "published_at"
75
+ t.datetime "created_at"
76
+ t.datetime "updated_at"
77
+ end
78
+
79
+ create_table "trashables", force: true do |t|
80
+ t.string "name"
81
+ t.string "title"
82
+ t.integer "draft_id"
83
+ t.datetime "published_at"
84
+ t.datetime "trashed_at"
85
+ t.datetime "created_at"
86
+ t.datetime "updated_at"
87
+ end
88
+
89
+ create_table "vanillas", force: true do |t|
90
+ t.string "name"
91
+ t.integer "draft_id"
92
+ t.datetime "published_at"
93
+ t.datetime "created_at"
94
+ t.datetime "updated_at"
95
+ end
96
+
97
+ create_table "whitelisters", force: true do |t|
98
+ t.string "name"
99
+ t.string "ignored"
100
+ t.integer "draft_id"
101
+ t.datetime "published_at"
102
+ t.datetime "created_at"
103
+ t.datetime "updated_at"
104
+ end
105
+
106
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
File without changes
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,205 @@
1
+ require 'spec_helper'
2
+
3
+ describe Child do
4
+ let(:parent) { Parent.new(:name => 'Marge') }
5
+ let(:child) { Child.new(:name => 'Lisa', :parent => parent) }
6
+
7
+ describe :publish! do
8
+ context 'parent `create` draft with child `create` draft' do
9
+ before do
10
+ parent.draft_creation
11
+ child.draft_creation
12
+ end
13
+
14
+ subject { child.draft.publish! }
15
+
16
+ its 'child should not be a draft' do
17
+ subject
18
+ child.reload.should_not be_draft
19
+ end
20
+
21
+ its 'child should be published' do
22
+ subject
23
+ child.reload.should be_published
24
+ end
25
+
26
+ its 'parent should be published' do
27
+ subject
28
+ parent.reload.should be_published
29
+ end
30
+
31
+ its 'parent should not be a draft' do
32
+ subject
33
+ parent.reload.should_not be_draft
34
+ end
35
+
36
+ it 'destroys both drafts' do
37
+ expect { subject }.to change(Draftsman::Draft, :count).by(-2)
38
+ end
39
+
40
+ it "destroys the child's draft" do
41
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
42
+ end
43
+
44
+ it "destroys the parent's draft" do
45
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Parent'), :count).by(-1)
46
+ end
47
+ end
48
+
49
+ context 'parent `destroy` draft with child `destroy` draft' do
50
+ before do
51
+ parent.save!
52
+ child.save!
53
+ child.draft_destroy
54
+ parent.draft_destroy
55
+ end
56
+
57
+ subject { child.draft.publish! }
58
+
59
+ it 'destroys the child' do
60
+ expect { subject }.to change(Child, :count).by(-1)
61
+ end
62
+
63
+ it 'keeps the parent' do
64
+ expect { subject }.to_not change(Parent, :count)
65
+ end
66
+
67
+ it 'destroys 1 draft' do
68
+ expect { subject }.to change(Draftsman::Draft, :count).by(-1)
69
+ end
70
+
71
+ it "destroys the child's draft" do
72
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe :revert! do
78
+ context 'parent `create` draft with child `create` draft' do
79
+ before do
80
+ parent.draft_creation
81
+ child.draft_creation
82
+ end
83
+
84
+ subject { child.draft.revert! }
85
+
86
+ it 'destroys the parent' do
87
+ expect { subject }.to_not change(Parent, :count).by(-1)
88
+ end
89
+
90
+ it 'destroys the child' do
91
+ expect { subject }.to change(Child, :count).by(-1)
92
+ end
93
+
94
+ it 'only destroys 1 draft overall' do
95
+ expect { subject }.to change(Draftsman::Draft, :count).by(-1)
96
+ end
97
+
98
+ it 'destroys the child draft' do
99
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
100
+ end
101
+ end
102
+
103
+ context 'parent `destroy` draft with child `destroy` draft' do
104
+ before do
105
+ parent.save!
106
+ child.save!
107
+ child.draft_destroy
108
+ parent.draft_destroy
109
+ end
110
+
111
+ subject do
112
+ child.draft.revert!
113
+ parent.reload
114
+ child.reload
115
+ end
116
+
117
+ it { should be_persisted }
118
+ it { should_not be_trashed }
119
+ it { should_not be_draft }
120
+
121
+ it 'deletes both drafts' do
122
+ expect { subject }.to change(Draftsman::Draft, :count).by(-2)
123
+ end
124
+
125
+ it "deletes the parent's draft" do
126
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Parent'), :count).by(-1)
127
+ end
128
+
129
+ it "deletes the child's draft" do
130
+ expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
131
+ end
132
+
133
+ its 'parent should not be trashed anymore' do
134
+ subject
135
+ parent.should_not be_trashed
136
+ end
137
+
138
+ its 'child should not be a draft anymore' do
139
+ subject
140
+ child.should_not be_draft
141
+ end
142
+ end
143
+ end
144
+
145
+ describe :draft_publication_dependencies do
146
+ context 'parent `create` draft with child `create` draft' do
147
+ before do
148
+ parent.draft_creation
149
+ child.draft_creation
150
+ end
151
+
152
+ subject { child.draft }
153
+ its(:draft_publication_dependencies) { should be_present }
154
+ its(:draft_publication_dependencies) { should include parent.draft }
155
+ end
156
+
157
+ context 'parent `create` draft with child `update` draft' do
158
+ before do
159
+ parent.draft_creation
160
+ child.save!
161
+ child.name = 'Heather'
162
+ child.draft_update
163
+ end
164
+
165
+ subject { child.draft }
166
+ its(:draft_publication_dependencies) { should be_present }
167
+ its(:draft_publication_dependencies) { should include parent.draft }
168
+ end
169
+
170
+ context 'parent `destroy` draft with child `destroy` draft' do
171
+ before do
172
+ child.save!
173
+ parent.draft_destroy
174
+ child.reload
175
+ end
176
+
177
+ subject { child.draft }
178
+ its(:draft_publication_dependencies) { should be_empty }
179
+ end
180
+ end
181
+
182
+ describe :draft_reversion_dependencies do
183
+ context 'parent `create` draft with child `create` draft' do
184
+ before do
185
+ parent.draft_creation
186
+ child.draft_creation
187
+ end
188
+
189
+ subject { child.draft }
190
+ its(:draft_reversion_dependencies) { should be_empty }
191
+ end
192
+
193
+ context 'parent `destroy` draft with child `destroy` draft' do
194
+ before do
195
+ child.save!
196
+ parent.draft_destroy
197
+ child.reload
198
+ end
199
+
200
+ subject { child.draft }
201
+ its(:draft_reversion_dependencies) { should be_present }
202
+ its(:draft_reversion_dependencies) { should include parent.draft }
203
+ end
204
+ end
205
+ end