best_boy 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ .rvmrc
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
@@ -0,0 +1,7 @@
1
+ ## 0.0.3
2
+
3
+ * added rspec tests
4
+
5
+ ## 0.0.2
6
+
7
+ * initial release
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
File without changes
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  best_boy
2
2
  ========
3
+ [![Build Status](https://secure.travis-ci.org/cseydel/best_boy.png?branch=master)](https://secure.travis-ci.org/cseydel/best_boy)
3
4
 
4
5
  A simple event driven logging for ActiveRecord models.
5
- This gem is not tested for now. I add testing asap.
6
- -----------------------------------------
6
+
7
7
 
8
8
  What does this gem do?
9
9
  ----------------------
10
10
 
11
- best_boy logs create and delete events in its first iteration. It uses an own polimorphic database table to log each event.
11
+ best_boy logs "create" and "delete" events as well as custom events triggered in controller actions. It uses an own polimorphic database table to log each event.
12
+ At the moment, best_boy only provides support for ActiveRecord models.
12
13
 
13
14
 
14
15
  Installation
@@ -24,12 +25,30 @@ Install it with Bundler
24
25
 
25
26
  Generate the BestBoyEvent table migration
26
27
 
27
- rails g best_boy:install
28
+ rails g best_boy
28
29
 
29
30
  Run the migration
30
31
 
31
32
  rake db:migrate
32
33
 
34
+
35
+ Usage
36
+ -----
37
+
38
+ In model context:
39
+
40
+ has_a_best_boy
41
+
42
+ This will log "create" and "delete" event for each instance.
43
+
44
+ In controller context:
45
+
46
+ best_boy_event object, event
47
+
48
+ This will log custom events for a object and a event phrase.
49
+ If no Object is given, it will raise an exception as well as if no event is provided.
50
+
51
+
33
52
  BestBoyEvent table
34
53
  ------------------
35
54
 
@@ -44,9 +63,15 @@ Getting BestBoyEvents
44
63
 
45
64
  The table is namespaced, so you can access for statistics maybe with BestBoy::BestBoyEvent.where...
46
65
 
66
+ Thanks
67
+ ------
68
+
69
+ Big thanks to each contributor on Impressionist. This gem helped me a long way to get here in modelling and creating a gem.
47
70
 
48
71
  Famous last words
49
72
  -----------------
50
73
  It's my first gem, be gentle ;)
51
74
 
75
+
76
+
52
77
  Copyright (c) 2012 Christoph Seydel. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,16 +1,11 @@
1
+ require 'rubygems'
1
2
  require 'bundler/setup'
3
+ require 'rake'
4
+ require 'rspec/core'
2
5
  require 'rspec/core/rake_task'
3
6
 
4
7
  Bundler::GemHelper.install_tasks
5
8
 
6
- RSpec::Core::RakeTask.new do |task|
7
- task.rspec_opts = "-I ./test_app/spec"
8
- task.pattern = "./test_app/spec/**/*_spec.rb"
9
- end
9
+ RSpec::Core::RakeTask.new(:spec)
10
10
 
11
- task :test => :spec
12
- task :default => :spec
13
-
14
- namespace :best_boy do
15
-
16
- end
11
+ task :default => :spec
File without changes
@@ -2,10 +2,6 @@ module BestBoy
2
2
  module Eventable
3
3
  extend ActiveSupport::Concern
4
4
 
5
- module ClassMethods
6
-
7
- end
8
-
9
5
  def eventable?
10
6
  true
11
7
  end
@@ -17,7 +17,11 @@ Gem::Specification.new do |s|
17
17
  s.required_rubygems_version = ">= 1.3.6"
18
18
 
19
19
  s.add_development_dependency("bundler", ">= 1.0.0")
20
- s.add_development_dependency("rspec", "~> 2.0.1")
20
+ s.add_development_dependency('activerecord', '>= 3.0.0')
21
+ s.add_development_dependency('activesupport', '>= 3.0.0')
22
+ s.add_development_dependency('sqlite3', '>= 1.3.4')
23
+ s.add_development_dependency("rake")
24
+ s.add_development_dependency("rspec")
21
25
 
22
26
  s.files = `git ls-files`.split("\n")
23
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Binary file
File without changes
File without changes
@@ -1,17 +1,17 @@
1
1
  class BestBoyEvent < ActiveRecord::Base
2
- # associations
3
- #
4
- #
5
- belongs_to :owner, :polymorphic => true
6
-
7
- # validations
8
- #
9
- #
10
- validates :event, :presence => true
11
-
12
- # attributes
13
- #
14
- #
15
- attr_accessible :owner_id, :owner_type, :event
2
+ # associations
3
+ #
4
+ #
5
+ belongs_to :owner, :polymorphic => true
6
+
7
+ # validations
8
+ #
9
+ #
10
+ validates :event, :presence => true
11
+
12
+ # attributes
13
+ #
14
+ #
15
+ attr_accessible :owner_id, :owner_type, :event
16
16
 
17
- end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module BestBoy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe BestBoyController do
4
+ before(:each) do
5
+ @user = User.create
6
+ end
7
+
8
+ it "should send valid custom event" do
9
+ best_boy_event @user, "testing"
10
+ BestBoyEvent.where(:owner_id => @user.id, :owner_type => @user.class.name.to_s, :event => "testing").first.should_not be_nil
11
+ end
12
+
13
+ it "should raise error on empty event_phrase" do
14
+ expect {best_boy_event(@user, "")}.should raise_error
15
+ end
16
+
17
+ it "should raise error on class not beeing a eventable" do
18
+ klass = Dummy.new
19
+ expect {best_boy_event(klass, "testing")}.should raise_error
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe BestBoyEvent do
4
+ it "should have valid model" do
5
+ user = User.create
6
+ BestBoyEvent.create(:owner_id => user.id, :owner_type => user.class.name.to_s, :event => "create").should be_valid
7
+ end
8
+
9
+ it "should require a event" do
10
+ BestBoyEvent.create(:event => "").should_not be_valid
11
+ end
12
+
13
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe BestBoy::Eventable do
4
+ before(:each) do
5
+ @user = User.create
6
+ end
7
+
8
+ it "should send valid create event" do
9
+ best_boy_event = @user.best_boy_events.first.should_not be_nil
10
+ end
11
+
12
+ it "should send valid destroy event" do
13
+ @user.destroy
14
+ BestBoyEvent.where(:owner_type => "User", :event => "destroy").should_not be_nil
15
+ end
16
+
17
+ it "should be an eventable" do
18
+ @user.respond_to?("eventable?").should eql(true)
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'active_record'
4
+ require 'active_support'
5
+ require "best_boy/models/active_record/best_boy_event.rb"
6
+ require "best_boy/models/active_record/best_boy/eventable.rb"
7
+ require "./app/models/best_boy/eventable.rb"
8
+ require "./app/controllers/best_boy_controller.rb"
9
+ require 'rspec'
10
+ require 'rspec/autorun'
11
+
12
+ root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
13
+ ActiveRecord::Base.establish_connection(
14
+ :adapter => "sqlite3",
15
+ :database => "#{root}/db/bestboy.db"
16
+ )
17
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'users'")
18
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'best_boy_events'")
19
+ ActiveRecord::Schema.define do
20
+ self.verbose = false
21
+
22
+ create_table :best_boy_events, :force => true do |t|
23
+ t.integer :owner_id
24
+ t.string :owner_type
25
+ t.string :event
26
+ t.timestamps
27
+ end
28
+ add_index :best_boy_events, :owner_id
29
+ add_index :best_boy_events, :owner_type
30
+ add_index :best_boy_events, [:owner_id, :owner_type]
31
+ add_index :best_boy_events, :event
32
+
33
+ create_table :users, :force => true do |t|
34
+ t.timestamps
35
+ end
36
+
37
+ end
38
+
39
+ ActiveRecord::Base.send(:include, BestBoy::Eventable)
40
+
41
+ RSpec.configure do |config|
42
+ config.include BestBoyController::InstanceMethods
43
+ end
44
+
45
+ class User < ActiveRecord::Base
46
+ has_a_best_boy
47
+ end
48
+
49
+ class Dummy
50
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_boy
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
4
+ prerelease:
5
+ version: 0.0.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - Christoph Seydel
@@ -14,37 +10,75 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2012-06-12 00:00:00 +02:00
13
+ date: 2012-06-13 00:00:00 +02:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: bundler
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
24
21
  requirements:
25
22
  - - ">="
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 0
30
- - 0
31
24
  version: 1.0.0
32
25
  type: :development
33
26
  version_requirements: *id001
34
27
  - !ruby/object:Gem::Dependency
35
- name: rspec
28
+ name: activerecord
36
29
  prerelease: false
37
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
38
32
  requirements:
39
- - - ~>
33
+ - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 0
44
- - 1
45
- version: 2.0.1
35
+ version: 3.0.0
46
36
  type: :development
47
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: activesupport
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: sqlite3
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.4
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rake
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
48
82
  description: Hybrid action logging, consisting of standard and custom logging.
49
83
  email:
50
84
  - christoph.seydel@me.com
@@ -56,6 +90,9 @@ extra_rdoc_files: []
56
90
 
57
91
  files:
58
92
  - .gitignore
93
+ - .rspec
94
+ - .travis.yml
95
+ - CHANGELOG.md
59
96
  - Gemfile
60
97
  - LICENSE.txt
61
98
  - README.md
@@ -63,6 +100,7 @@ files:
63
100
  - app/controllers/best_boy_controller.rb
64
101
  - app/models/best_boy/eventable.rb
65
102
  - best_boy.gemspec
103
+ - db/bestboy.db
66
104
  - lib/best_boy.rb
67
105
  - lib/best_boy/engine.rb
68
106
  - lib/best_boy/models/active_record/best_boy/eventable.rb
@@ -72,6 +110,10 @@ files:
72
110
  - lib/generators/active_record/templates/create_best_boy_events_table.rb
73
111
  - lib/generators/best_boy_generator.rb
74
112
  - lib/generators/templates/best_boy.rb
113
+ - spec/best_boy/best_boy_controller_spec.rb
114
+ - spec/best_boy/best_boy_event_spec.rb
115
+ - spec/best_boy/eventable_spec.rb
116
+ - spec/spec_helper.rb
75
117
  has_rdoc: true
76
118
  homepage: https://github.com/cseydel/best_boy
77
119
  licenses:
@@ -82,27 +124,26 @@ rdoc_options: []
82
124
  require_paths:
83
125
  - lib
84
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
85
128
  requirements:
86
129
  - - ">="
87
130
  - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
131
  version: "0"
91
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
92
134
  requirements:
93
135
  - - ">="
94
136
  - !ruby/object:Gem::Version
95
- segments:
96
- - 1
97
- - 3
98
- - 6
99
137
  version: 1.3.6
100
138
  requirements: []
101
139
 
102
140
  rubyforge_project: best_boy
103
- rubygems_version: 1.3.6
141
+ rubygems_version: 1.6.2
104
142
  signing_key:
105
143
  specification_version: 3
106
144
  summary: a simple event driven logging for models
107
- test_files: []
108
-
145
+ test_files:
146
+ - spec/best_boy/best_boy_controller_spec.rb
147
+ - spec/best_boy/best_boy_event_spec.rb
148
+ - spec/best_boy/eventable_spec.rb
149
+ - spec/spec_helper.rb