rails-observers 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,18 +0,0 @@
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
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- before_install: gem install bundler
5
- script: bundle exec rake test
6
- notifications:
7
- email: false
8
- irc:
9
- on_success: change
10
- on_failure: always
11
- channels:
12
- - "irc.freenode.org#rails-contrib"
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in active_record-observers.gemspec
4
- gemspec
5
-
6
- gem 'activerecord-deprecated_finders'
7
-
8
- gem 'mocha', require: false
data/Rakefile DELETED
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
-
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new("test:regular") do |t|
7
- t.libs = ["test"]
8
- t.pattern = "test/*_test.rb"
9
- t.ruby_opts = ['-w']
10
- end
11
-
12
- Rake::TestTask.new("test:generators") do |t|
13
- t.libs = ["test"]
14
- t.pattern = "test/generators/*_test.rb"
15
- t.ruby_opts = ['-w']
16
- end
17
-
18
- task :default => :test
19
- task :test => ['test:regular', 'test:generators']
20
-
21
- specname = "rails-observers.gemspec"
22
- deps = `git ls-files`.split("\n") - [specname]
23
-
24
- file specname => deps do
25
- files = `git ls-files`.split("\n")
26
- test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
- executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
-
29
- require 'erb'
30
-
31
- File.open specname, 'w:utf-8' do |f|
32
- f.write ERB.new(File.read("#{specname}.erb")).result(binding)
33
- end
34
- end
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/rails/observers/version', __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "rails-observers"
6
- s.authors = ["Rafael Mendonça França", "Steve Klabnik"]
7
- s.email = ["rafaelmfranca@gmail.com", "steve@steveklabnik.com"]
8
- s.description = %q{Rails observer (removed from core in Rails 4.0)}
9
- s.summary = %q{ActiveModel::Observer, ActiveRecord::Observer and ActionController::Caching::Sweeper extracted from Rails.}
10
- s.homepage = "https://github.com/rails/rails-observers"
11
- s.version = Rails::Observers::VERSION
12
-
13
- s.files = [".gitignore",".travis.yml","Gemfile","LICENSE","README.md","Rakefile","lib/generators/active_record/observer/observer_generator.rb","lib/generators/active_record/observer/templates/observer.rb","lib/generators/rails/observer/USAGE","lib/generators/rails/observer/observer_generator.rb","lib/generators/test_unit/observer/observer_generator.rb","lib/generators/test_unit/observer/templates/unit_test.rb","lib/rails-observers.rb","lib/rails/observers/action_controller/caching.rb","lib/rails/observers/action_controller/caching/sweeping.rb","lib/rails/observers/active_model.rb","lib/rails/observers/active_model/active_model.rb","lib/rails/observers/active_model/observer_array.rb","lib/rails/observers/active_model/observing.rb","lib/rails/observers/activerecord/active_record.rb","lib/rails/observers/activerecord/base.rb","lib/rails/observers/activerecord/observer.rb","lib/rails/observers/railtie.rb","lib/rails/observers/version.rb","rails-observers.gemspec","rails-observers.gemspec.erb","test/configuration_test.rb","test/console_test.rb","test/fixtures/developers.yml","test/fixtures/minimalistics.yml","test/fixtures/topics.yml","test/generators/generators_test_helper.rb","test/generators/namespaced_generators_test.rb","test/generators/observer_generator_test.rb","test/helper.rb","test/isolation/abstract_unit.rb","test/lifecycle_test.rb","test/models/observers.rb","test/observer_array_test.rb","test/observing_test.rb","test/rake_test.rb","test/sweeper_test.rb","test/transaction_callbacks_test.rb"]
14
- s.test_files = ["test/configuration_test.rb","test/console_test.rb","test/fixtures/developers.yml","test/fixtures/minimalistics.yml","test/fixtures/topics.yml","test/generators/generators_test_helper.rb","test/generators/namespaced_generators_test.rb","test/generators/observer_generator_test.rb","test/helper.rb","test/isolation/abstract_unit.rb","test/lifecycle_test.rb","test/models/observers.rb","test/observer_array_test.rb","test/observing_test.rb","test/rake_test.rb","test/sweeper_test.rb","test/transaction_callbacks_test.rb"]
15
- s.executables = []
16
- s.require_paths = ["lib"]
17
-
18
- s.add_dependency 'activemodel', '~> 4.0'
19
-
20
- s.add_development_dependency 'minitest', '>= 3'
21
- s.add_development_dependency 'railties', '~> 4.0'
22
- s.add_development_dependency 'activerecord', '~> 4.0'
23
- s.add_development_dependency 'actionmailer', '~> 4.0'
24
- s.add_development_dependency 'actionpack', '~> 4.0'
25
- s.add_development_dependency 'sqlite3', '~> 1.3'
26
- end
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/rails/observers/version', __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "rails-observers"
6
- s.authors = ["Rafael Mendonça França", "Steve Klabnik"]
7
- s.email = ["rafaelmfranca@gmail.com", "steve@steveklabnik.com"]
8
- s.description = %q{Rails observer (removed from core in Rails 4.0)}
9
- s.summary = %q{ActiveModel::Observer, ActiveRecord::Observer and ActionController::Caching::Sweeper extracted from Rails.}
10
- s.homepage = "https://github.com/rails/rails-observers"
11
- s.version = Rails::Observers::VERSION
12
-
13
- s.files = [<%= files.map(&:inspect).join ',' %>]
14
- s.test_files = [<%= test_files.map(&:inspect).join ',' %>]
15
- s.executables = [<%= executables.map(&:inspect).join ',' %>]
16
- s.require_paths = ["lib"]
17
-
18
- s.add_dependency 'activemodel', '~> 4.0'
19
-
20
- s.add_development_dependency 'minitest', '>= 3'
21
- s.add_development_dependency 'railties', '~> 4.0'
22
- s.add_development_dependency 'activerecord', '~> 4.0'
23
- s.add_development_dependency 'actionmailer', '~> 4.0'
24
- s.add_development_dependency 'actionpack', '~> 4.0'
25
- s.add_development_dependency 'sqlite3', '~> 1.3'
26
- end
@@ -1,37 +0,0 @@
1
- require 'isolation/abstract_unit'
2
- require 'rails-observers'
3
-
4
- class ConfigurationTest < ActiveSupport::TestCase
5
- include ActiveSupport::Testing::Isolation
6
-
7
- def setup
8
- build_app
9
- boot_rails
10
- FileUtils.rm_rf("#{app_path}/config/environments")
11
- end
12
-
13
- def teardown
14
- teardown_app
15
- end
16
-
17
- test "config.active_record.observers" do
18
- add_to_config <<-RUBY
19
- config.active_record.observers = :foo_observer
20
- RUBY
21
-
22
- app_file 'app/models/foo.rb', <<-RUBY
23
- class Foo < ActiveRecord::Base
24
- end
25
- RUBY
26
-
27
- app_file 'app/models/foo_observer.rb', <<-RUBY
28
- class FooObserver < ActiveRecord::Observer
29
- end
30
- RUBY
31
-
32
- require "#{app_path}/config/environment"
33
-
34
- _ = ActiveRecord::Base
35
- assert defined?(FooObserver)
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- require 'isolation/abstract_unit'
2
- require 'rails-observers'
3
-
4
- class ConsoleTest < ActiveSupport::TestCase
5
- include ActiveSupport::Testing::Isolation
6
-
7
- def setup
8
- build_app
9
- boot_rails
10
- end
11
-
12
- def teardown
13
- teardown_app
14
- end
15
-
16
- def load_environment
17
- require "#{rails_root}/config/environment"
18
- Rails.application.sandbox = false
19
- Rails.application.load_console
20
- end
21
-
22
- def test_active_record_does_not_panic_when_referencing_an_observed_constant
23
- add_to_config "config.active_record.observers = :user_observer"
24
-
25
- app_file "app/models/user.rb", <<-MODEL
26
- class User < ActiveRecord::Base
27
- end
28
- MODEL
29
-
30
- app_file "app/models/user_observer.rb", <<-MODEL
31
- class UserObserver < ActiveRecord::Observer
32
- end
33
- MODEL
34
-
35
- load_environment
36
- assert_nothing_raised { User }
37
- end
38
- end
@@ -1,4 +0,0 @@
1
- david:
2
- id: 1
3
- name: David
4
- salary: 80000
@@ -1,2 +0,0 @@
1
- first:
2
- id: 1
@@ -1,41 +0,0 @@
1
- first:
2
- id: 1
3
- title: The First Topic
4
- author_name: David
5
- author_email_address: david@loudthinking.com
6
- written_on: 2003-07-16t15:28:11.2233+01:00
7
- last_read: 2004-04-15
8
- bonus_time: 2005-01-30t15:28:00.00+01:00
9
- content: Have a nice day
10
- approved: false
11
- replies_count: 1
12
-
13
- second:
14
- id: 2
15
- title: The Second Topic of the day
16
- author_name: Mary
17
- written_on: 2004-07-15t15:28:00.0099+01:00
18
- content: Have a nice day
19
- approved: true
20
- replies_count: 0
21
- parent_id: 1
22
- type: Reply
23
-
24
- third:
25
- id: 3
26
- title: The Third Topic of the day
27
- author_name: Carl
28
- written_on: 2012-08-12t20:24:22.129346+00:00
29
- content: I'm a troll
30
- approved: true
31
- replies_count: 1
32
-
33
- fourth:
34
- id: 4
35
- title: The Fourth Topic of the day
36
- author_name: Carl
37
- written_on: 2006-07-15t15:28:00.0099+01:00
38
- content: Why not?
39
- approved: true
40
- type: Reply
41
- parent_id: 3
@@ -1,16 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require 'fileutils'
4
-
5
- require 'rails/all'
6
- require 'rails/generators'
7
- require 'rails/generators/test_case'
8
-
9
- module TestApp
10
- class Application < Rails::Application
11
- end
12
- end
13
-
14
- # Call configure to load the settings from
15
- # Rails.application.config.generators to Rails::Generators
16
- Rails.application.load_generators
@@ -1,34 +0,0 @@
1
- require 'generators/generators_test_helper'
2
- require 'generators/rails/observer/observer_generator'
3
-
4
- class NamespacedObserverGeneratorTest < Rails::Generators::TestCase
5
- tests Rails::Generators::ObserverGenerator
6
- arguments %w(account)
7
- destination File.expand_path("../../tmp", __FILE__)
8
-
9
- def setup
10
- super
11
- prepare_destination
12
- Rails::Generators.namespace = TestApp
13
- end
14
-
15
- def teardown
16
- super
17
- Rails::Generators.namespace = nil
18
- end
19
-
20
- def test_invokes_default_orm
21
- run_generator
22
- assert_file "app/models/test_app/account_observer.rb", /module TestApp/, / class AccountObserver < ActiveRecord::Observer/
23
- end
24
-
25
- def test_invokes_default_orm_with_class_path
26
- run_generator ["admin/account"]
27
- assert_file "app/models/test_app/admin/account_observer.rb", /module TestApp/, / class Admin::AccountObserver < ActiveRecord::Observer/
28
- end
29
-
30
- def test_invokes_default_test_framework
31
- run_generator
32
- assert_file "test/unit/test_app/account_observer_test.rb", /module TestApp/, / class AccountObserverTest < ActiveSupport::TestCase/
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- require 'generators/generators_test_helper'
2
- require 'generators/rails/observer/observer_generator'
3
-
4
- class ObserverGeneratorTest < Rails::Generators::TestCase
5
- tests Rails::Generators::ObserverGenerator
6
- destination File.expand_path("../../tmp", __FILE__)
7
- arguments %w(account)
8
-
9
- def setup
10
- super
11
- prepare_destination
12
- end
13
-
14
- def test_invokes_default_orm
15
- run_generator
16
- assert_file "app/models/account_observer.rb", /class AccountObserver < ActiveRecord::Observer/
17
- end
18
-
19
- def test_invokes_default_orm_with_class_path
20
- run_generator ["admin/account"]
21
- assert_file "app/models/admin/account_observer.rb", /class Admin::AccountObserver < ActiveRecord::Observer/
22
- end
23
-
24
- def test_invokes_default_test_framework
25
- run_generator
26
- assert_file "test/unit/account_observer_test.rb", /class AccountObserverTest < ActiveSupport::TestCase/
27
- end
28
-
29
- def test_logs_if_the_test_framework_cannot_be_found
30
- content = run_generator ["account", "--test-framework=rspec"]
31
- assert_match(/rspec \[not found\]/, content)
32
- end
33
- end
@@ -1,74 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'active_record'
3
-
4
- require 'rails/observers/activerecord/active_record'
5
-
6
- FIXTURES_ROOT = File.expand_path(File.dirname(__FILE__)) + "/fixtures"
7
-
8
- class ActiveSupport::TestCase
9
- include ActiveRecord::TestFixtures
10
-
11
- self.fixture_path = FIXTURES_ROOT
12
- self.use_instantiated_fixtures = false
13
- self.use_transactional_fixtures = true
14
- end
15
-
16
- ActiveRecord::Base.configurations = { "test" => { adapter: 'sqlite3', database: ':memory:' } }
17
- ActiveRecord::Base.establish_connection(:test)
18
-
19
- ActiveRecord::Schema.verbose = false
20
- ActiveRecord::Schema.define do
21
- create_table :topics do |t|
22
- t.string :title
23
- t.string :author_name
24
- t.string :author_email_address
25
- t.datetime :written_on
26
- t.time :bonus_time
27
- t.date :last_read
28
- t.text :content
29
- t.text :important
30
- t.boolean :approved, :default => true
31
- t.integer :replies_count, :default => 0
32
- t.integer :parent_id
33
- t.string :parent_title
34
- t.string :type
35
- t.string :group
36
- t.timestamps
37
- end
38
-
39
- create_table :comments do |t|
40
- t.string :title
41
- end
42
-
43
- create_table :minimalistics do |t|
44
- end
45
-
46
- create_table :developers do |t|
47
- t.string :name
48
- t.integer :salary
49
- end
50
- end
51
-
52
- class Topic < ActiveRecord::Base
53
- has_many :replies, dependent: :destroy, foreign_key: "parent_id"
54
- end
55
-
56
- class Reply < Topic
57
- belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
58
- end
59
-
60
- class Comment < ActiveRecord::Base
61
- def self.lol
62
- "lol"
63
- end
64
- end
65
-
66
- class Developer < ActiveRecord::Base
67
- end
68
-
69
- class Minimalistic < ActiveRecord::Base
70
- end
71
-
72
- ActiveSupport::Deprecation.silence do
73
- require 'active_record/test_case'
74
- end
@@ -1,119 +0,0 @@
1
- # Note:
2
- # It is important to keep this file as light as possible
3
- # the goal for tests that require this is to test booting up
4
- # rails from an empty state, so anything added here could
5
- # hide potential failures
6
- #
7
- # It is also good to know what is the bare minimum to get
8
- # Rails booted up.
9
- require 'fileutils'
10
-
11
- require 'bundler/setup'
12
- require 'minitest/autorun'
13
- require 'active_support/test_case'
14
-
15
- # These files do not require any others and are needed
16
- # to run the tests
17
- require "active_support/testing/isolation"
18
- require "active_support/core_ext/kernel/reporting"
19
- require 'tmpdir'
20
-
21
- module TestHelpers
22
- module Paths
23
- def app_template_path
24
- File.join Dir.tmpdir, 'app_template'
25
- end
26
-
27
- def tmp_path(*args)
28
- @tmp_path ||= File.realpath(Dir.mktmpdir)
29
- File.join(@tmp_path, *args)
30
- end
31
-
32
- def app_path(*args)
33
- tmp_path(*%w[app] + args)
34
- end
35
-
36
- def rails_root
37
- app_path
38
- end
39
- end
40
-
41
- module Generation
42
- # Build an application by invoking the generator and going through the whole stack.
43
- def build_app(options = {})
44
- @prev_rails_env = ENV['RAILS_ENV']
45
- ENV['RAILS_ENV'] = 'development'
46
-
47
- FileUtils.rm_rf(app_path)
48
- FileUtils.cp_r(app_template_path, app_path)
49
-
50
- # Delete the initializers unless requested
51
- unless options[:initializers]
52
- Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
53
- File.delete(initializer)
54
- end
55
- end
56
-
57
- gemfile_path = "#{app_path}/Gemfile"
58
- if options[:gemfile].blank? && File.exist?(gemfile_path)
59
- File.delete gemfile_path
60
- end
61
-
62
- routes = File.read("#{app_path}/config/routes.rb")
63
- if routes =~ /(\n\s*end\s*)\Z/
64
- File.open("#{app_path}/config/routes.rb", 'w') do |f|
65
- f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', :via => :all\n" + $1
66
- end
67
- end
68
-
69
- add_to_config <<-RUBY
70
- config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
71
- config.session_store :cookie_store, :key => "_myapp_session"
72
- config.active_support.deprecation = :log
73
- config.action_controller.allow_forgery_protection = false
74
- config.eager_load = false
75
- RUBY
76
- end
77
-
78
- def teardown_app
79
- ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
80
- end
81
-
82
- def add_to_config(str)
83
- environment = File.read("#{app_path}/config/application.rb")
84
- if environment =~ /(\n\s*end\s*end\s*)\Z/
85
- File.open("#{app_path}/config/application.rb", 'w') do |f|
86
- f.puts $` + "\n#{str}\n" + $1
87
- end
88
- end
89
- end
90
-
91
- def app_file(path, contents)
92
- FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
93
- File.open("#{app_path}/#{path}", 'w') do |f|
94
- f.puts contents
95
- end
96
- end
97
-
98
- def boot_rails
99
- require 'rubygems' unless defined? Gem
100
- require 'bundler'
101
- Bundler.setup
102
- end
103
- end
104
- end
105
-
106
- class ActiveSupport::TestCase
107
- include TestHelpers::Paths
108
- include TestHelpers::Generation
109
- end
110
-
111
- Module.new do
112
- extend TestHelpers::Paths
113
-
114
- # Build a rails app
115
- FileUtils.rm_rf(app_template_path)
116
- FileUtils.mkdir(app_template_path)
117
-
118
- `rails new #{app_template_path} --skip-gemfile`
119
- end