espinita 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +60 -0
- data/Rakefile +31 -0
- data/app/models/espinita/audit.rb +41 -0
- data/config/database.yml +24 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20131029200927_create_auditable_audits.rb +15 -0
- data/lib/espinita.rb +16 -0
- data/lib/espinita/auditor.rb +18 -0
- data/lib/espinita/auditor_behavior.rb +83 -0
- data/lib/espinita/auditor_request.rb +13 -0
- data/lib/espinita/engine.rb +18 -0
- data/lib/espinita/version.rb +3 -0
- data/lib/tasks/espinita_tasks.rake +4 -0
- data/spec/controllers/audits_controller_spec.rb +47 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/general_controller.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/general_controller.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/general_controller_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/general_controller_helper.rb +2 -0
- data/spec/dummy/app/models/general_model.rb +4 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131029211126_create_general_models.rb +12 -0
- data/spec/dummy/db/migrate/20131030014901_create_users.rb +11 -0
- data/spec/dummy/db/schema.rb +52 -0
- data/spec/dummy/log/development.log +28 -0
- data/spec/dummy/log/test.log +17268 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/auditable_audits.rb +11 -0
- data/spec/factories/general_models.rb +10 -0
- data/spec/factories/users.rb +9 -0
- data/spec/integration/navigation_test.rb +10 -0
- data/spec/models/espinita/audit_spec.rb +8 -0
- data/spec/models/models/general_model_spec.rb +160 -0
- data/spec/models/models/user_spec.rb +5 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/models.rb +8 -0
- data/spec/support/schema.rb +34 -0
- metadata +291 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe GeneralModel do
|
5
|
+
it{should have_many :audits}
|
6
|
+
|
7
|
+
let(:current_user) do
|
8
|
+
FactoryGirl.create(:user)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "model" do
|
12
|
+
|
13
|
+
let(:general_model) do
|
14
|
+
GeneralModel
|
15
|
+
end
|
16
|
+
|
17
|
+
it "general model checks" do
|
18
|
+
expect(subject.audits).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it "general auditable only method" do
|
22
|
+
general_model.auditable only: [:name]
|
23
|
+
expect(general_model.permited_columns).to include("name")
|
24
|
+
expect(general_model.permited_columns.size).to eql 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "general auditable except method" do
|
28
|
+
general_model.auditable except: [:name]
|
29
|
+
expect(general_model.excluded_cols).to include("name")
|
30
|
+
expect(general_model.permited_columns).not_to include("name")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "update model with only name key" do
|
35
|
+
|
36
|
+
let(:general_model) do
|
37
|
+
FactoryGirl.create(:general_model)
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:updated_model) do
|
41
|
+
general_model.class.auditable only: [:name]
|
42
|
+
general_model.update_attribute(:name , "Foo" )
|
43
|
+
general_model
|
44
|
+
end
|
45
|
+
|
46
|
+
it "model should be associated" do
|
47
|
+
expect(updated_model.audits).to have(2).audits
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "update model with only name key" do
|
52
|
+
|
53
|
+
let(:general_model) do
|
54
|
+
FactoryGirl.create(:general_model)
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:updated_model) do
|
58
|
+
general_model.class.auditable except: [:name]
|
59
|
+
general_model.update_attribute(:name , "Foo" )
|
60
|
+
general_model
|
61
|
+
end
|
62
|
+
|
63
|
+
it "model should be associated" do
|
64
|
+
expect(updated_model.audits).to have(1).audits
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "update with audit comment" do
|
69
|
+
|
70
|
+
let(:general_model) do
|
71
|
+
FactoryGirl.create(:general_model)
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:updated_model) do
|
75
|
+
general_model.class.auditable
|
76
|
+
general_model.update_attributes(name: "Foo", audit_comment: "Some comment" )
|
77
|
+
general_model
|
78
|
+
end
|
79
|
+
|
80
|
+
it "auditable should be created with comment" do
|
81
|
+
expect(updated_model).to have(2).audits
|
82
|
+
expect(updated_model.audits.last.comment).to_not be_empty
|
83
|
+
expect(updated_model.audits.last.comment).to_not be "Some comment"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "auditable should be created with comment" do
|
87
|
+
expect(updated_model).to have(2).audits
|
88
|
+
expect(updated_model.audits.last.version).to_not be_blank
|
89
|
+
expect(updated_model.audits.last.version).to eql 2
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "save with current user" do
|
94
|
+
|
95
|
+
before :each do
|
96
|
+
RequestStore.store[:audited_user] = current_user
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:general_model) do
|
100
|
+
FactoryGirl.create(:general_model)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:updated_model) do
|
104
|
+
general_model.class.auditable
|
105
|
+
general_model.update_attributes(name: "Foo", audit_comment: "Some comment" )
|
106
|
+
general_model
|
107
|
+
end
|
108
|
+
|
109
|
+
it "auditable should set current user" do
|
110
|
+
expect(updated_model.audits.last.user).to_not be_blank
|
111
|
+
expect(updated_model.audits.last.user).to be_an_instance_of User
|
112
|
+
expect(updated_model.audits.last.user).to eql current_user
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "audit only on create" do
|
117
|
+
|
118
|
+
let(:general_model) do
|
119
|
+
[:create, :update, :destroy].each do |c|
|
120
|
+
GeneralModel.reset_callbacks(c)
|
121
|
+
end
|
122
|
+
GeneralModel.auditable on: [:create]
|
123
|
+
FactoryGirl.create(:general_model)
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:updated_model) do
|
127
|
+
general_model.update_attributes(name: "Foo", audit_comment: "Some comment" )
|
128
|
+
general_model
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should have 1 audit" do
|
132
|
+
expect(updated_model).to have(1).audits
|
133
|
+
expect(updated_model.audits.last.version).to_not be_blank
|
134
|
+
expect(updated_model.audits.last.version).to eql 1
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "audit only on update" do
|
139
|
+
|
140
|
+
let(:general_model) do
|
141
|
+
[:create, :update, :destroy].each do |c|
|
142
|
+
GeneralModel.reset_callbacks(c)
|
143
|
+
end
|
144
|
+
GeneralModel.auditable on: [:update]
|
145
|
+
FactoryGirl.create(:general_model)
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:updated_model) do
|
149
|
+
general_model.update_attributes(name: "Foo", audit_comment: "Some comment" )
|
150
|
+
general_model
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should have 1 audit" do
|
154
|
+
expect(updated_model).to have(1).audits
|
155
|
+
expect(updated_model.audits.last.version).to_not be_blank
|
156
|
+
expect(updated_model.audits.last.version).to eql 1
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
ENV["RAILS_ENV"] ||= 'test'
|
6
|
+
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'rspec/autorun'
|
9
|
+
|
10
|
+
require "factory_girl_rails"
|
11
|
+
require "database_cleaner"
|
12
|
+
require 'capybara'
|
13
|
+
require 'capybara/rspec'
|
14
|
+
require 'shoulda/matchers/integrations/rspec'
|
15
|
+
|
16
|
+
require "espinita"
|
17
|
+
|
18
|
+
|
19
|
+
require 'support/schema'
|
20
|
+
require 'support/models'
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.infer_base_class_for_anonymous_controllers = false
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
5
|
+
#ActiveRecord::Base.logger = Logger.new(SPEC_ROOT.join('debug.log'))
|
6
|
+
ActiveRecord::Migration.verbose = false
|
7
|
+
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
create_table :users do |t|
|
10
|
+
t.string :name
|
11
|
+
t.string :last_name
|
12
|
+
t.string :email
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
create_table :general_models do |t|
|
16
|
+
t.references :user, index: true
|
17
|
+
t.string :name
|
18
|
+
t.text :settings
|
19
|
+
t.integer :position
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table :espinita_audits do |t|
|
24
|
+
t.references :auditable, polymorphic: true, index: true
|
25
|
+
t.references :user, polymorphic: true, index: true
|
26
|
+
t.text :audited_changes
|
27
|
+
t.string :comment
|
28
|
+
t.integer :version
|
29
|
+
t.string :action
|
30
|
+
t.string :remote_address
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|