amistad-actions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "amistad", ">= 0.7.5"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.3.0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ gem "activerecord"
16
+ gem "sqlite3"
17
+ end
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.1)
5
+ activesupport (= 3.1.1)
6
+ builder (~> 3.0.0)
7
+ i18n (~> 0.6)
8
+ activerecord (3.1.1)
9
+ activemodel (= 3.1.1)
10
+ activesupport (= 3.1.1)
11
+ arel (~> 2.2.1)
12
+ tzinfo (~> 0.3.29)
13
+ activesupport (3.1.1)
14
+ multi_json (~> 1.0)
15
+ amistad (0.7.5)
16
+ arel (2.2.1)
17
+ builder (3.0.0)
18
+ diff-lcs (1.1.3)
19
+ git (1.2.5)
20
+ i18n (0.6.0)
21
+ jeweler (1.6.4)
22
+ bundler (~> 1.0)
23
+ git (>= 1.2.5)
24
+ rake
25
+ multi_json (1.0.3)
26
+ rake (0.9.2)
27
+ rcov (0.9.11)
28
+ rspec (2.3.0)
29
+ rspec-core (~> 2.3.0)
30
+ rspec-expectations (~> 2.3.0)
31
+ rspec-mocks (~> 2.3.0)
32
+ rspec-core (2.3.1)
33
+ rspec-expectations (2.3.0)
34
+ diff-lcs (~> 1.1.2)
35
+ rspec-mocks (2.3.0)
36
+ sqlite3 (1.3.4)
37
+ tzinfo (0.3.30)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activerecord
44
+ amistad (>= 0.7.5)
45
+ bundler (~> 1.0.0)
46
+ jeweler (~> 1.6.4)
47
+ rcov
48
+ rspec (~> 2.3.0)
49
+ sqlite3
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jan Dupal
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = amistad-actions
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to amistad-actions
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Jan Dupal. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "amistad-actions"
18
+ gem.homepage = "http://github.com/JanDupal/amistad-actions"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Amistad Action logging}
21
+ gem.description = %Q{Action logging for Amistad friendship model}
22
+ gem.email = "dupal.j@gmail.com"
23
+ gem.authors = ["Jan Dupal"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "amistad-actions #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,9 @@
1
+ if defined?(ActiveRecord)
2
+ require 'amistad/active_record/action_model'
3
+ require 'amistad/active_record/has_actions'
4
+ require 'amistad/active_record/is_subject'
5
+ end
6
+
7
+ require 'amistad/action_model'
8
+ require 'amistad/has_actions'
9
+ require 'amistad/is_subject'
@@ -0,0 +1,13 @@
1
+ module Amistad
2
+ module ActionModel
3
+ def self.included(receiver)
4
+ if receiver.ancestors.map(&:to_s).include?("ActiveRecord::Base")
5
+ receiver.class_exec do
6
+ include Amistad::ActiveRecord::ActionModel
7
+ end
8
+ else
9
+ raise "Amistad-action only supports ActiveRecord"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ module Amistad
2
+ module ActiveRecord
3
+ module ActionModel
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ belongs_to :user
8
+ belongs_to :subject, :polymorphic => true
9
+
10
+ validates :user, :presence => true
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ end
16
+
17
+ module InstanceMethods
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ module Amistad
2
+ module ActiveRecord
3
+ module HasActions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :actions
8
+ end
9
+
10
+ module ClassMethods
11
+ def predefined_actions
12
+ @@predefined_actions ||= {}
13
+ end
14
+
15
+ def predefine_action(action, options = nil)
16
+ predefined_actions[action] = Action.new(options)
17
+ end
18
+
19
+ def has_predefined_action(action)
20
+ predefined_actions.has_key?(action)
21
+ end
22
+
23
+ def remove_all_predefined_actions
24
+ @@predefined_actions = {}
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ def did(what)
30
+ action = if what.is_a? Symbol
31
+ self.class.predefined_actions[what].dup
32
+ else
33
+ Action.new(:description => what)
34
+ end
35
+ actions << action
36
+ action
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ module Amistad
2
+ module ActiveRecord
3
+ module IsSubject
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :concerning_actions, :class_name => 'Action', :as => 'subject'
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ end
13
+
14
+ module InstanceMethods
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Amistad
2
+ module HasActions
3
+ def self.included(receiver)
4
+ if receiver.ancestors.map(&:to_s).include?("ActiveRecord::Base")
5
+ receiver.class_exec do
6
+ include Amistad::ActiveRecord::HasActions
7
+ end
8
+ else
9
+ raise "Amistad-action only supports ActiveRecord"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Amistad
2
+ module IsSubject
3
+ def self.included(receiver)
4
+ if receiver.ancestors.map(&:to_s).include?("ActiveRecord::Base")
5
+ receiver.class_exec do
6
+ include Amistad::ActiveRecord::IsSubject
7
+ end
8
+ else
9
+ raise "Amistad-action only supports ActiveRecord"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Amistad::ActiveRecord::ActionModel do
4
+ before(:all) do
5
+ %w(Jane David).each do |name|
6
+ instance_variable_set("@#{name.downcase}".to_sym, User.create(:name => name))
7
+ end
8
+ end
9
+
10
+ it "should validate presence of the user's id" do
11
+ action = Action.new
12
+ action.valid?.should be_false
13
+ action.errors.should include(:user)
14
+ action.errors.size.should == 1
15
+ end
16
+
17
+ it "should store subject" do
18
+ action = Action.create(:user => @jane,
19
+ :description => "#{@jane.name} sent message to #{@david.name}",
20
+ :subject => @david)
21
+ action.valid?.should be_true
22
+ end
23
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Amistad::ActiveRecord::HasActions do
4
+ before(:each) do
5
+ %w(Jane David).each do |name|
6
+ instance_variable_set("@#{name.downcase}".to_sym, User.create(:name => name))
7
+ end
8
+ end
9
+
10
+ context "when defining action for user" do
11
+ before(:each) do
12
+ User.remove_all_predefined_actions
13
+ User.predefined_actions.empty?.should be_true
14
+ end
15
+
16
+ it "should add action to predefined actions" do
17
+ User.has_predefined_action(:something).should be_false
18
+ User.predefine_action :something
19
+ User.has_predefined_action(:something).should be_true
20
+ end
21
+
22
+ it "should add action with description to available actions" do
23
+ User.has_predefined_action(:something).should be_false
24
+ User.predefine_action :something, { :description => 'Something' }
25
+ User.has_predefined_action(:something).should be_true
26
+ User.predefined_actions[:something].description.should == 'Something'
27
+ end
28
+ end
29
+
30
+ context "when creating action for user" do
31
+ before(:each) do
32
+ Action.delete_all
33
+ User.remove_all_predefined_actions
34
+
35
+ User.has_predefined_action(:anything).should be_false
36
+ User.predefine_action :anything, { :description => 'Anything'}
37
+ User.has_predefined_action(:anything).should be_true
38
+ end
39
+
40
+ it "should create action" do
41
+ @jane.did('nothing').should be_true
42
+ @jane.actions.size.should == 1
43
+ @jane.actions.first.description.should == 'nothing'
44
+ end
45
+
46
+ it "should use predefined action" do
47
+ @jane.did(:anything).should be_true
48
+ @jane.actions.size.should == 1
49
+ @jane.actions.first.description.should == 'Anything'
50
+ end
51
+
52
+ it "should leave predefined action untouched" do
53
+ @jane.did(:anything).should be_true
54
+
55
+ User.predefined_actions[:anything].user_id.should be_nil
56
+ end
57
+ end
58
+
59
+ context "when listing actions for user" do
60
+ before(:each) do
61
+ Action.delete_all
62
+
63
+ (@something = @jane.did('something')).should be_true
64
+ @something.description.should == 'something'
65
+
66
+ (@anything = @jane.did('anything')).should be_true
67
+ @anything.description.should == 'anything'
68
+ end
69
+
70
+ it "should list all actions" do
71
+ @jane.actions.should =~ [@something, @anything]
72
+ @david.actions.should =~ []
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Amistad::ActiveRecord::IsSubject do
4
+ before(:all) do
5
+ Action.delete_all
6
+ %w(Jane David).each do |name|
7
+ instance_variable_set("@#{name.downcase}".to_sym, User.create(:name => name))
8
+ end
9
+ end
10
+
11
+ it "should store concerning actions" do
12
+ action = Action.create(:user => @jane,
13
+ :description => "#{@jane.name} sent message to #{@david.name}",
14
+ :subject => @david)
15
+
16
+ @david.concerning_actions.size.should == 1
17
+ @david.concerning_actions.first.should == action
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'active_record'
5
+ require 'amistad-actions'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
@@ -0,0 +1,43 @@
1
+ require 'amistad'
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => "sqlite3",
5
+ :database => ":memory:"
6
+ )
7
+
8
+ ActiveRecord::Migration.verbose = false
9
+
10
+ ActiveRecord::Schema.define do
11
+ create_table :users, :force => true do |t|
12
+ t.string :name, :null => false
13
+ end
14
+
15
+ create_table :friendships, :force => true do |t|
16
+ t.integer :user_id
17
+ t.integer :friend_id
18
+ t.integer :blocker_id
19
+ t.boolean :pending, :default => true
20
+ end
21
+
22
+ add_index :friendships, [:user_id, :friend_id], :unique => true
23
+
24
+ create_table :actions, :force => true do |t|
25
+ t.integer :user_id
26
+ t.string :description
27
+ t.references :subject, :polymorphic => true
28
+ end
29
+ end
30
+
31
+ class User < ActiveRecord::Base
32
+ include Amistad::FriendModel
33
+ include Amistad::HasActions
34
+ include Amistad::IsSubject
35
+ end
36
+
37
+ class Friendship < ActiveRecord::Base
38
+ include Amistad::FriendshipModel
39
+ end
40
+
41
+ class Action < ActiveRecord::Base
42
+ include Amistad::ActionModel
43
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amistad-actions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Dupal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: amistad
16
+ requirement: &78671610 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *78671610
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &78671340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *78671340
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &78645780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *78645780
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &78645480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *78645480
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &78645180 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *78645180
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: &78644870 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *78644870
80
+ - !ruby/object:Gem::Dependency
81
+ name: sqlite3
82
+ requirement: &78644520 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *78644520
91
+ description: Action logging for Amistad friendship model
92
+ email: dupal.j@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ files:
99
+ - .document
100
+ - .rspec
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/amistad-actions.rb
108
+ - lib/amistad/action_model.rb
109
+ - lib/amistad/active_record/action_model.rb
110
+ - lib/amistad/active_record/has_actions.rb
111
+ - lib/amistad/active_record/is_subject.rb
112
+ - lib/amistad/has_actions.rb
113
+ - lib/amistad/is_subject.rb
114
+ - spec/activerecord/active_record_action_model_spec.rb
115
+ - spec/activerecord/active_record_has_actions_spec.rb
116
+ - spec/activerecord/active_record_is_subject_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/activerecord_spec_helper.rb
119
+ homepage: http://github.com/JanDupal/amistad-actions
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 501012815
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.6
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Amistad Action logging
147
+ test_files: []