secretary-rails 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +186 -0
- data/Rakefile +9 -0
- data/app/models/secretary/version.rb +93 -0
- data/lib/generators/secretary/install_generator.rb +23 -0
- data/lib/generators/secretary/templates/versions_migration.rb +18 -0
- data/lib/secretary/config.rb +19 -0
- data/lib/secretary/engine.rb +4 -0
- data/lib/secretary/errors.rb +10 -0
- data/lib/secretary/gem_version.rb +3 -0
- data/lib/secretary/has_secretary.rb +75 -0
- data/lib/secretary/tracks_association.rb +146 -0
- data/lib/secretary/versioned_attributes.rb +58 -0
- data/lib/secretary-rails.rb +3 -0
- data/lib/secretary.rb +40 -0
- data/lib/tasks/secretary_tasks.rake +6 -0
- data/spec/factories.rb +32 -0
- data/spec/internal/app/models/animal.rb +7 -0
- data/spec/internal/app/models/hobby.rb +3 -0
- data/spec/internal/app/models/location.rb +6 -0
- data/spec/internal/app/models/person.rb +14 -0
- data/spec/internal/app/models/story.rb +3 -0
- data/spec/internal/app/models/user.rb +3 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +2 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +50 -0
- data/spec/internal/log/test.log +23177 -0
- data/spec/lib/generators/secretary/install_generator_spec.rb +17 -0
- data/spec/lib/secretary/config_spec.rb +9 -0
- data/spec/lib/secretary/has_secretary_spec.rb +116 -0
- data/spec/lib/secretary/tracks_association_spec.rb +214 -0
- data/spec/lib/secretary/versioned_attributes_spec.rb +63 -0
- data/spec/lib/secretary_spec.rb +44 -0
- data/spec/models/secretary/version_spec.rb +68 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/tmp/db/migrate/20131105082639_create_versions.rb +18 -0
- metadata +181 -0
data/lib/secretary.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Secretary
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'secretary/engine'
|
5
|
+
require 'secretary/config'
|
6
|
+
require 'secretary/errors'
|
7
|
+
require 'diffy'
|
8
|
+
|
9
|
+
module Secretary
|
10
|
+
extend ActiveSupport::Autoload
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Pass a block to this method to define the configuration
|
14
|
+
# If no block is passed, config will be defaults
|
15
|
+
def configure
|
16
|
+
config = Config.new
|
17
|
+
yield config if block_given?
|
18
|
+
self.config = config
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_writer :config
|
22
|
+
def config
|
23
|
+
@config || configure
|
24
|
+
end
|
25
|
+
|
26
|
+
def versioned_models
|
27
|
+
@versioned_models ||= []
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
autoload :HasSecretary
|
32
|
+
autoload :VersionedAttributes
|
33
|
+
autoload :TracksAssociation
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveSupport.on_load(:active_record) do
|
37
|
+
include Secretary::HasSecretary
|
38
|
+
include Secretary::TracksAssociation
|
39
|
+
include Secretary::VersionedAttributes
|
40
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :animal do
|
3
|
+
name "Fred"
|
4
|
+
species "Elephant"
|
5
|
+
color "gray"
|
6
|
+
end
|
7
|
+
|
8
|
+
factory :location do
|
9
|
+
title "Crawford Family Forum"
|
10
|
+
address "474 S. Raymond, Pasadena"
|
11
|
+
end
|
12
|
+
|
13
|
+
factory :person do
|
14
|
+
name "Bryan"
|
15
|
+
ethnicity "none"
|
16
|
+
age 100
|
17
|
+
end
|
18
|
+
|
19
|
+
factory :story do
|
20
|
+
headline "Cool Headline"
|
21
|
+
body "Lorem, etc."
|
22
|
+
end
|
23
|
+
|
24
|
+
factory :user do
|
25
|
+
name "Bryan Ricker"
|
26
|
+
end
|
27
|
+
|
28
|
+
factory :version, class: "Secretary::Version" do
|
29
|
+
versioned { |v| v.association :story }
|
30
|
+
user
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Person < ActiveRecord::Base
|
2
|
+
has_secretary
|
3
|
+
|
4
|
+
belongs_to :location
|
5
|
+
|
6
|
+
has_many :animals
|
7
|
+
accepts_nested_attributes_for :animals, allow_destroy: true
|
8
|
+
|
9
|
+
has_many :hobbies
|
10
|
+
|
11
|
+
tracks_association :animals, :hobbies
|
12
|
+
|
13
|
+
self.unversioned_attributes = ["name", "ethnicity"]
|
14
|
+
end
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table "animals", force: true do |t|
|
3
|
+
t.string "name"
|
4
|
+
t.string "species"
|
5
|
+
t.string "color"
|
6
|
+
t.integer "person_id"
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table "hobbies", force: true do |t|
|
11
|
+
t.string "title"
|
12
|
+
t.integer "person_id"
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table "locations", force: true do |t|
|
17
|
+
t.string "title"
|
18
|
+
t.text "address"
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "people", force: true do |t|
|
23
|
+
t.string "name"
|
24
|
+
t.string "ethnicity"
|
25
|
+
t.integer "age"
|
26
|
+
t.integer "location_id"
|
27
|
+
t.timestamps
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "stories", force: true do |t|
|
31
|
+
t.string "headline"
|
32
|
+
t.text "body"
|
33
|
+
t.timestamps
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "users", force: true do |t|
|
37
|
+
t.string "name"
|
38
|
+
t.timestamps
|
39
|
+
end
|
40
|
+
|
41
|
+
create_table "versions", force: true do |t|
|
42
|
+
t.integer "version_number"
|
43
|
+
t.string "versioned_type"
|
44
|
+
t.integer "versioned_id"
|
45
|
+
t.integer "user_id"
|
46
|
+
t.text "description"
|
47
|
+
t.text "object_changes"
|
48
|
+
t.datetime "created_at"
|
49
|
+
end
|
50
|
+
end
|