shoulda-matchers-callbacks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f7084ec432a7f3ccb95af1e8b2b492061db3428
4
+ data.tar.gz: 7be71f80e211d74315d85bfd6fbf4afa27632955
5
+ SHA512:
6
+ metadata.gz: 1405f4219f87da94ffd99b322ddfa960e10cb1ff82dca9297df86af6318164acf3331baecd72439a1abd392fadfe85079922e10619811bfdd79f5a5036d35c2c
7
+ data.tar.gz: 5a3e33ddadafc7e1b48ff2852d3417549992274368f402aaf2d11e2cdbeae46500a2a46235bdfe8066ac4d93943b607759219cdacd7e31e265778c6dec179052
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-version
19
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shoulda-matchers-callbacks.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomas Valent
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # Shoulda::Matchers::Callbacks
2
+
3
+ Gem created from my refused :broken_hearth:
4
+ [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) pull request
5
+ https://github.com/thoughtbot/shoulda-matchers/pull/353 :smile:
6
+
7
+
8
+ ## ActiveModel Matchers
9
+
10
+ Matchers to test callbacks:
11
+
12
+ ```ruby
13
+ describe Event do
14
+ it { should have_after_create_callback_on(:send_invitation_emails) }
15
+ it { should have_before_destroy_callback_on(:delete_calendar_entries)
16
+ }
17
+ it { should have_around_update_callback_on(:sign_other_events) }
18
+ it { should have_after_validation_callback_on(:mark_event_upcomming) }
19
+ # ... you can use any of possible ActiveRecord::Base::CALLBACKS
20
+ end
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'shoulda-matchers-callbacks'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install shoulda-matchers-callbacks
36
+
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,61 @@
1
+ module Shoulda # :nodoc:
2
+ module Matchers
3
+ module ActiveModel # :nodoc:
4
+
5
+ def self.possible_callback_pairs
6
+ ::ActiveRecord::Base::CALLBACKS.collect{|symbol| symbol.to_s.split('_')}
7
+ end
8
+
9
+ possible_callback_pairs.each do |pair|
10
+ when_occures = pair[0]
11
+ action = pair[1]
12
+
13
+ define_method "have_#{when_occures}_#{action}_callback_on" do |method_name|
14
+ Callbacks.new(when_occures, action, method_name)
15
+ end
16
+ end
17
+
18
+ class Callbacks
19
+ attr_reader :failure_message_for_should, :failure_message_for_should_not
20
+
21
+ def initialize(occures, action, method_name)
22
+ @occures = occures.to_sym
23
+ @action = action.to_sym
24
+ @method_name = method_name.to_sym
25
+ end
26
+
27
+ def matches?(subject)
28
+ @subject = subject
29
+ if callbacks.include?(@method_name)
30
+ @failure_message_for_should_not = "Didn't expect #{@subject.model_name} model to have #{callback_name} callback on method :#{@method_name}"
31
+ else
32
+ @failure_message_for_should = "Expected #{@subject.model_name} model to have #{callback_name} callback on method :#{@method_name}"
33
+ return false
34
+ end
35
+ true
36
+ end
37
+
38
+ def description
39
+ "have #{@occures.to_s} #{@action.to_s} callback"
40
+ end
41
+
42
+ def callbacks
43
+ action_callbacks.select{|cb| cb.kind.eql?(@occures) }.collect(&:filter)
44
+ end
45
+
46
+ def action_callbacks
47
+ begin
48
+ @subject.send("_#{@action}_callbacks")
49
+ rescue NoMethodError
50
+ raise "Subject must be Rails model class"
51
+ end
52
+ end
53
+
54
+ def callback_name
55
+ "#{@occures}_#{@action}"
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ require "shoulda/matchers/callbacks/version"
2
+ require "shoulda/matchers/active_model/callbacks"
3
+
4
+ module Shoulda
5
+ module Matchers
6
+ module Callbacks
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Callbacks
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shoulda/matchers/callbacks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shoulda-matchers-callbacks"
8
+ spec.version = Shoulda::Matchers::Callbacks::VERSION
9
+ spec.authors = ["Equivalent"]
10
+ spec.email = ["equivalent@eq8.eu"]
11
+ spec.description = %q{Shoulda Matchers gem extension for Active Model (Rails) callbacks
12
+ (after_create, before_create, after_update, before_update...) }
13
+ spec.summary = %q{Shoulda Matchers for Active Model (Rails) callbacks}
14
+ spec.homepage = "https://github.com/equivalent/shoulda-matchers-callbacks"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "shoulda-matchers", "~> 1.3"
24
+ spec.add_development_dependency('rspec-rails', '>= 2.13.1', '< 3')
25
+ spec.add_development_dependency('rails', '~> 3.0')
26
+ spec.add_development_dependency "sqlite3"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoulda::Matchers::ActiveModel::Callbacks do
4
+
5
+ ActiveRecord::Base::CALLBACKS.each do |callback_name|
6
+ context 'class with callbacks' do
7
+ subject{ ClassWithCallbacks }
8
+ it{ should send("have_#{callback_name}_callback_on", :method_to_call) }
9
+ end
10
+
11
+ context 'class with callbacks' do
12
+ subject{ ClassWithoutCallbacks }
13
+ it{ should_not send("have_#{callback_name}_callback_on", :method_to_call) }
14
+ end
15
+ end
16
+
17
+ context 'class with after create callback' do
18
+ subject{ ClassWithoutAfterCreateCalbacks }
19
+ it{ should_not have_before_create_callback_on :foo_bar }
20
+ it{ should have_after_create_callback_on :foo_bar }
21
+ it{ should_not have_after_update_callback_on :foo_bar }
22
+ end
23
+
24
+ end
@@ -0,0 +1,29 @@
1
+ # Required by shoulda
2
+ #
3
+ # * Create Rails environment based on the version given from Appraisal
4
+ TESTAPP_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp', 'aruba', 'testapp')
5
+ FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
6
+ `rails new #{TESTAPP_ROOT}`
7
+ ENV['RAILS_ENV'] = 'test'
8
+ ENV['BUNDLE_GEMFILE'] ||= TESTAPP_ROOT + '/Gemfile'
9
+ require "#{TESTAPP_ROOT}/config/environment"
10
+
11
+ # Main requirements
12
+ require 'shoulda-matchers'
13
+ require 'rspec/rails'
14
+
15
+ # Models to test
16
+ class ClassWithCallbacks < ActiveRecord::Base
17
+ ActiveRecord::Base::CALLBACKS.each do |callback_name|
18
+ send callback_name, :method_to_call
19
+ end
20
+ end
21
+
22
+ class ClassWithoutCallbacks < ActiveRecord::Base
23
+ end
24
+
25
+ class ClassWithoutAfterCreateCalbacks < ActiveRecord::Base
26
+ after_create :foo_bar
27
+ after_update :somethig_else
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoulda-matchers-callbacks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Equivalent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda-matchers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.13.1
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: '3'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 2.13.1
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: "Shoulda Matchers gem extension for Active Model (Rails) callbacks\n
104
+ \ (after_create, before_create, after_update, before_update...) "
105
+ email:
106
+ - equivalent@eq8.eu
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - .gitignore
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - lib/shoulda/matchers/active_model/callbacks.rb
117
+ - lib/shoulda/matchers/callbacks.rb
118
+ - lib/shoulda/matchers/callbacks/version.rb
119
+ - shoulda-matchers-callbacks.gemspec
120
+ - spec/shoulda/matchers/active_model/callbacks_matchers_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: https://github.com/equivalent/shoulda-matchers-callbacks
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.0.5
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Shoulda Matchers for Active Model (Rails) callbacks
146
+ test_files:
147
+ - spec/shoulda/matchers/active_model/callbacks_matchers_spec.rb
148
+ - spec/spec_helper.rb