impressionist 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Rakefile +17 -4
- data/app/models/impressionist/impressionable.rb +2 -2
- data/impressionist.gemspec +4 -3
- data/lib/impressionist/engine.rb +8 -25
- data/lib/impressionist/load.rb +6 -4
- data/lib/impressionist/models/active_record/impression.rb +5 -2
- data/lib/impressionist/models/mongoid/impression.rb +8 -15
- data/lib/impressionist/models/mongoid/impressionist/impressionable.rb +13 -32
- data/lib/impressionist/rails_toggle.rb +22 -0
- data/lib/impressionist/setup_association.rb +48 -0
- data/lib/impressionist/version.rb +1 -1
- data/tests/README +1 -0
- data/tests/spec/minitest_helper.rb +4 -0
- data/tests/spec/rails_toggle_spec.rb +26 -0
- data/tests/spec/setup_association_spec.rb +55 -0
- data/{test_app → tests/test_app}/.gitignore +0 -0
- data/{test_app → tests/test_app}/.rspec +0 -0
- data/{test_app → tests/test_app}/Gemfile +4 -15
- data/{test_app → tests/test_app}/README +0 -0
- data/{test_app → tests/test_app}/README.rdoc +0 -0
- data/{test_app → tests/test_app}/Rakefile +0 -0
- data/{test_app → tests/test_app}/app/assets/images/rails.png +0 -0
- data/{test_app → tests/test_app}/app/assets/javascripts/application.js +0 -0
- data/{test_app → tests/test_app}/app/assets/stylesheets/application.css +0 -0
- data/{test_app → tests/test_app}/app/controllers/application_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/articles_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/dummy_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/posts_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/controllers/widgets_controller.rb +0 -0
- data/{test_app → tests/test_app}/app/helpers/application_helper.rb +0 -0
- data/{test_app → tests/test_app}/app/mailers/.gitkeep +0 -0
- data/{test_app → tests/test_app}/app/models/.gitkeep +0 -0
- data/{test_app → tests/test_app}/app/models/article.rb +0 -0
- data/{test_app → tests/test_app}/app/models/dummy.rb +0 -0
- data/{test_app → tests/test_app}/app/models/post.rb +0 -0
- data/{test_app → tests/test_app}/app/models/user.rb +0 -0
- data/{test_app → tests/test_app}/app/models/widget.rb +0 -0
- data/{test_app → tests/test_app}/app/views/articles/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/articles/show.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/dummy/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/layouts/application.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/edit.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/posts/show.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/index.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/new.html.erb +0 -0
- data/{test_app → tests/test_app}/app/views/widgets/show.html.erb +0 -0
- data/{test_app → tests/test_app}/config.ru +0 -0
- data/{test_app → tests/test_app}/config/application.rb +0 -0
- data/{test_app → tests/test_app}/config/boot.rb +0 -0
- data/{test_app → tests/test_app}/config/cucumber.yml +0 -0
- data/{test_app → tests/test_app}/config/database.yml +0 -0
- data/{test_app → tests/test_app}/config/environment.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/development.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/pg_test.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/production.rb +0 -0
- data/{test_app → tests/test_app}/config/environments/test.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/tests/test_app/config/initializers/impression.rb +2 -0
- data/{test_app → tests/test_app}/config/initializers/inflections.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/mime_types.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/secret_token.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/session_store.rb +0 -0
- data/{test_app → tests/test_app}/config/initializers/wrap_parameters.rb +0 -0
- data/{test_app → tests/test_app}/config/locales/en.yml +0 -0
- data/{test_app → tests/test_app}/config/routes.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20110201153144_create_articles.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20110210205028_create_posts.rb +0 -0
- data/{test_app → tests/test_app}/db/migrate/20111127184039_create_widgets.rb +0 -0
- data/tests/test_app/db/schema.rb +60 -0
- data/{test_app → tests/test_app}/db/seeds.rb +0 -0
- data/{test_app → tests/test_app}/lib/assets/.gitkeep +0 -0
- data/{test_app → tests/test_app}/lib/tasks/.gitkeep +0 -0
- data/{test_app → tests/test_app}/lib/tasks/cucumber.rake +0 -0
- data/{test_app → tests/test_app}/log/.gitkeep +0 -0
- data/{test_app → tests/test_app}/public/404.html +0 -0
- data/{test_app → tests/test_app}/public/422.html +0 -0
- data/{test_app → tests/test_app}/public/500.html +0 -0
- data/{test_app → tests/test_app}/public/favicon.ico +0 -0
- data/{test_app → tests/test_app}/public/images/rails.png +0 -0
- data/{test_app → tests/test_app}/public/index.html +0 -0
- data/{test_app → tests/test_app}/public/javascripts/application.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/controls.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/dragdrop.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/effects.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/prototype.js +0 -0
- data/{test_app → tests/test_app}/public/javascripts/rails.js +0 -0
- data/{test_app → tests/test_app}/public/robots.txt +0 -0
- data/{test_app → tests/test_app}/public/stylesheets/.gitkeep +0 -0
- data/{test_app → tests/test_app}/script/cucumber +0 -0
- data/{test_app → tests/test_app}/script/rails +0 -0
- data/{test_app → tests/test_app}/spec/controllers/articles_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/dummy_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/impressionist_uniqueness_spec.rb +45 -45
- data/{test_app → tests/test_app}/spec/controllers/posts_controller_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/controllers/widgets_controller_spec.rb +2 -2
- data/{test_app → tests/test_app}/spec/fixtures/articles.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/impressions.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/posts.yml +0 -0
- data/{test_app → tests/test_app}/spec/fixtures/widgets.yml +0 -0
- data/{test_app → tests/test_app}/spec/initializers/initializers_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/bots_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/counter_caching_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/models/model_spec.rb +0 -0
- data/{test_app → tests/test_app}/spec/rails_generators/rails_generators_spec.rb +0 -0
- data/tests/test_app/spec/spec_helper.rb +31 -0
- metadata +224 -99
- data/lib/impressionist/set_up_association.rb +0 -14
- data/spec/spec_helper.rb +0 -5
- data/test_app/config/initializers/impression.rb +0 -5
- data/test_app/spec/spec_helper.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac2802f1a96bf95bc358134f43a869aab3ba449
|
4
|
+
data.tar.gz: afab8713bbc4b91bcd84a57a3042cbfce578643e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f92d2ef3618bce991811cb438751bc6e76497bcae951a8a42b1050133ed492c19e77b290f69a141d91087c91a40d851716e834e70645119675b7f5cea41b7229
|
7
|
+
data.tar.gz: 8425229ed14a35088bb82ac68c3d4b5b910c694175ae03f4bdef963106745e06fb9e5597f6423e3b5233368670a086a80d46b1a62ba7bbb5737206b4d9ed0cff
|
data/.travis.yml
CHANGED
@@ -2,7 +2,8 @@ language: ruby
|
|
2
2
|
|
3
3
|
bundler_args: '--binstubs --without documentation'
|
4
4
|
before_install: gem install bundler
|
5
|
-
|
5
|
+
|
6
|
+
before_script: "cd tests/test_app && bundle install && ./script/rails generate impressionist -f && rake db:migrate && cd .."
|
6
7
|
|
7
8
|
rvm:
|
8
9
|
- rbx-18mode
|
data/Rakefile
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'rake/testtask'
|
3
4
|
|
4
5
|
Bundler::GemHelper.install_tasks
|
5
6
|
|
7
|
+
# Impressionist will use MiniTest instead of RSpec
|
6
8
|
RSpec::Core::RakeTask.new do |task|
|
7
|
-
task.rspec_opts = "-I ./test_app/spec"
|
8
|
-
task.pattern = "./test_app/spec/**/*_spec.rb"
|
9
|
+
task.rspec_opts = "-I ./tests/test_app/spec"
|
10
|
+
task.pattern = "./tests/test_app/spec/**/*_spec.rb"
|
9
11
|
end
|
10
12
|
|
11
|
-
task :
|
12
|
-
task :default => :
|
13
|
+
task :test_app => :spec
|
14
|
+
task :default => [:test, :test_app]
|
13
15
|
|
14
16
|
namespace :impressionist do
|
15
17
|
require File.dirname(__FILE__) + "/lib/impressionist/bots"
|
@@ -18,4 +20,15 @@ namespace :impressionist do
|
|
18
20
|
task :bots do
|
19
21
|
p Impressionist::Bots.consume
|
20
22
|
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# setup :test task to minitest
|
27
|
+
# Rake libs default is lib
|
28
|
+
# libs << path to load test_helper, etc..
|
29
|
+
Rake::TestTask.new do |t|
|
30
|
+
t.libs << "tests/spec"
|
31
|
+
t.pattern = "tests/spec/**/*_spec.rb"
|
32
|
+
t.test_files = FileList["tests/spec/**/*_spec.rb"]
|
33
|
+
t.verbose = true
|
21
34
|
end
|
@@ -32,10 +32,10 @@ module Impressionist
|
|
32
32
|
options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true)
|
33
33
|
end
|
34
34
|
|
35
|
-
def update_impressionist_counter_cache
|
35
|
+
def update_impressionist_counter_cache
|
36
36
|
slave = Impressionist::UpdateCounters.new(self)
|
37
37
|
slave.update
|
38
|
-
end
|
38
|
+
end
|
39
39
|
|
40
40
|
def impressionable?
|
41
41
|
true
|
data/impressionist.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.authors = ['johnmcaliley']
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files --
|
17
|
+
s.test_files = `git ls-files -- tests/**/*`.split("\n")
|
18
18
|
s.require_path = 'lib'
|
19
19
|
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
20
20
|
|
@@ -26,11 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
# Capybara has dropped support for Ruby 1.8.7 onwards version 2.0.3
|
27
27
|
s.add_development_dependency 'capybara', '>= 2.0.3'
|
28
28
|
s.add_development_dependency 'rake', '>= 0.9'
|
29
|
-
s.add_development_dependency 'rails', '
|
29
|
+
s.add_development_dependency 'rails', '3.2.12'
|
30
30
|
s.add_development_dependency 'rdoc', '>= 2.4.2'
|
31
31
|
s.add_development_dependency 'rspec-rails'
|
32
32
|
s.add_development_dependency 'simplecov'
|
33
33
|
s.add_development_dependency 'sqlite3'
|
34
34
|
s.add_development_dependency 'systemu'
|
35
|
-
|
35
|
+
s.add_development_dependency 'minitest'
|
36
|
+
s.add_development_dependency 'minitest-rails'
|
36
37
|
end
|
data/lib/impressionist/engine.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
require "impressionist"
|
2
|
-
require "rails"
|
3
|
-
|
4
1
|
module Impressionist
|
5
|
-
class Engine < Rails::Engine
|
2
|
+
class Engine < ::Rails::Engine
|
6
3
|
attr_accessor :orm
|
7
4
|
|
8
|
-
def initialize
|
9
|
-
define_orm_type(Impressionist.orm)
|
10
|
-
end
|
11
|
-
|
12
5
|
initializer 'impressionist.model' do |app|
|
13
|
-
|
14
|
-
|
6
|
+
@orm = Impressionist.orm
|
7
|
+
include_orm
|
15
8
|
end
|
16
9
|
|
17
10
|
|
@@ -26,22 +19,12 @@ module Impressionist
|
|
26
19
|
|
27
20
|
|
28
21
|
private
|
29
|
-
def require_and_include_orm
|
30
|
-
require "#{root}/app/models/impressionist/impressionable.rb"
|
31
|
-
require "impressionist/models/#{orm}/impression.rb"
|
32
|
-
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def define_orm_type(str)
|
37
|
-
@orm = matcher(str.to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
def matcher(str)
|
41
|
-
matched = str.match(/active_record|mongo_mapper|mongoid|/)
|
42
|
-
matched[0]
|
43
|
-
end
|
44
22
|
|
23
|
+
def include_orm
|
24
|
+
require "#{root}/app/models/impressionist/impressionable.rb"
|
25
|
+
require "impressionist/models/#{orm}/impression.rb"
|
26
|
+
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
|
27
|
+
end
|
45
28
|
|
46
29
|
end
|
47
30
|
end
|
data/lib/impressionist/load.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'impressionist/engine'
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'impressionist/setup_association'
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'impressionist/counter_cache'
|
6
6
|
|
7
|
-
require
|
7
|
+
require 'impressionist/update_counters'
|
8
|
+
|
9
|
+
require 'impressionist/rails_toggle'
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# Responsability
|
2
|
+
## See CounterCache TODO: extract it into a class
|
2
3
|
# * be able to update_counters
|
3
4
|
# * log an error if imps_id and imps_type can not be found
|
4
|
-
# asks updatable? whether it may or may not be updated
|
5
|
+
# * asks updatable? whether it may or may not be updated
|
5
6
|
# FIX exeception raising when no imps_id is found
|
6
7
|
|
7
8
|
class Impression < ActiveRecord::Base
|
9
|
+
|
8
10
|
include Impressionist::CounterCache
|
9
|
-
|
11
|
+
# sets belongs_to and attr_accessible
|
12
|
+
Impressionist::SetupAssociation.new(self).set
|
10
13
|
|
11
14
|
after_save :impressionable_counter_cache_updatable?
|
12
15
|
|
@@ -1,13 +1,15 @@
|
|
1
|
+
##
|
2
|
+
# see active_record/impression.rb
|
3
|
+
# same doc applies to here
|
1
4
|
class Impression
|
2
5
|
include Mongoid::Document
|
3
6
|
include Mongoid::Timestamps
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
:session_hash, :message, :referrer
|
8
|
-
|
9
|
-
belongs_to :impressionable, polymorphic: true
|
8
|
+
include Impressionist::CounterCache
|
9
|
+
Impressionist::SetupAssociation.new(self).set
|
10
10
|
|
11
|
+
field :impressionable_id
|
12
|
+
field :impressionable_type
|
11
13
|
field :user_id
|
12
14
|
field :controller_name
|
13
15
|
field :action_name
|
@@ -18,15 +20,6 @@ class Impression
|
|
18
20
|
field :message
|
19
21
|
field :referrer
|
20
22
|
|
21
|
-
|
22
|
-
unless impressionable_id.nil?
|
23
|
-
impressionable_class = doc.impressionable_type.constantize
|
23
|
+
after_save :impressionable_counter_cache_updatable?
|
24
24
|
|
25
|
-
if impressionable_class.impressionist_counter_cache_options
|
26
|
-
resource = impressionable_class.find(doc.impressionable_id)
|
27
|
-
resource.try(:update_impressionist_counter_cache)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
25
|
end
|
@@ -7,37 +7,25 @@ module Impressionist
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
+
|
10
11
|
def is_impressionable(options={})
|
11
|
-
|
12
|
-
|
13
|
-
if !@impressionist_cache_options.nil?
|
14
|
-
opts = impressionist_counter_cache_options
|
15
|
-
field opts[:column_name], type: Integer
|
16
|
-
end
|
17
|
-
end
|
12
|
+
define_association
|
13
|
+
@impressionist_cache_options = options
|
18
14
|
|
19
|
-
|
20
|
-
if @impressionist_cache_options
|
21
|
-
options = { :column_name => :impressions_count, :unique => false }
|
22
|
-
options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash)
|
23
|
-
options
|
24
|
-
end
|
15
|
+
true
|
25
16
|
end
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
private
|
19
|
+
def define_association
|
20
|
+
has_many(:impressions,
|
21
|
+
:as => :impressionable,
|
22
|
+
:dependent => :destroy)
|
23
|
+
end
|
30
24
|
|
31
|
-
def counter_caching?
|
32
|
-
::ActiveSupport::Deprecation.warn("#counter_caching? is deprecated; please use #impressionist_counter_caching? instead")
|
33
|
-
impressionist_counter_caching?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def impressionable?
|
38
|
-
true
|
39
25
|
end
|
40
26
|
|
27
|
+
##
|
28
|
+
# Overides active_record impressionist_count
|
41
29
|
def impressionist_count(options={})
|
42
30
|
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
|
43
31
|
imps = options[:start_date].blank? ? impressions : impressions.between(created_at: options[:start_date]..options[:end_date])
|
@@ -45,13 +33,6 @@ module Impressionist
|
|
45
33
|
filter == :all ? imps.count : imps.where(filter.ne => nil).distinct(filter).count
|
46
34
|
end
|
47
35
|
|
48
|
-
def update_impressionist_counter_cache
|
49
|
-
cache_options = self.class.impressionist_counter_cache_options
|
50
|
-
column_name = cache_options[:column_name].to_sym
|
51
|
-
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
|
52
|
-
old_count = send(column_name) || 0
|
53
|
-
self.inc(column_name, (count - old_count))
|
54
|
-
end
|
55
|
-
|
56
36
|
end
|
37
|
+
|
57
38
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Impressionist
|
2
|
+
# Responsability
|
3
|
+
# Toggles between rails > 3.1 < 4
|
4
|
+
# In order to make attr_accessible available in a rails app < 4
|
5
|
+
|
6
|
+
class RailsToggle
|
7
|
+
# decides where or not to include attr_accessible
|
8
|
+
def should_include?
|
9
|
+
ask_rails || false
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# returns false if rails >= 4
|
15
|
+
# true if rails < 4
|
16
|
+
def ask_rails
|
17
|
+
::Rails::VERSION::MAJOR.to_i >= 4 ? false : true
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Impressionist
|
2
|
+
# Impressionist::SetupAssociation.new(entity).set
|
3
|
+
class SetupAssociation
|
4
|
+
def initialize(receiver)
|
5
|
+
@receiver = receiver
|
6
|
+
end
|
7
|
+
|
8
|
+
# True or False
|
9
|
+
# Note toggle returns false if rails >= 4
|
10
|
+
def include_attr_acc?
|
11
|
+
toggle && make_accessible
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_belongs_to
|
15
|
+
receiver.belongs_to(:impressionable, :polymorphic => true)
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns done if thruthy
|
19
|
+
def set
|
20
|
+
:done if (include_attr_acc? && define_belongs_to)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
attr_reader :receiver, :toggle
|
25
|
+
|
26
|
+
def make_accessible
|
27
|
+
receiver.
|
28
|
+
attr_accessible(:impressionable_type,
|
29
|
+
:impressionable_id,
|
30
|
+
:controller_name,
|
31
|
+
:request_hash,
|
32
|
+
:session_hash,
|
33
|
+
:action_name,
|
34
|
+
:ip_address,
|
35
|
+
:view_name,
|
36
|
+
:referrer,
|
37
|
+
:message,
|
38
|
+
:user_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def toggle
|
42
|
+
t = RailsToggle.new
|
43
|
+
t.should_include?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
data/tests/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Impressionist uses MiniTest
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Responsability
|
2
|
+
# Test whether rails version > 4
|
3
|
+
# includes attr_accessible if < 4
|
4
|
+
require 'minitest_helper'
|
5
|
+
require 'impressionist/rails_toggle'
|
6
|
+
|
7
|
+
module Impressionist
|
8
|
+
describe RailsToggle do
|
9
|
+
|
10
|
+
before {
|
11
|
+
@toggle = RailsToggle.new
|
12
|
+
}
|
13
|
+
|
14
|
+
describe "Rails 4" do
|
15
|
+
|
16
|
+
# see your_minitest_path/lib/minitest/mock.rb
|
17
|
+
it "must not include attr_accessible" do
|
18
|
+
@toggle.stub :ask_rails, false do
|
19
|
+
refute @toggle.should_include?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
require 'impressionist/setup_association'
|
3
|
+
|
4
|
+
module Impressionist
|
5
|
+
describe SetupAssociation do
|
6
|
+
|
7
|
+
let(:mock) { Minitest::Mock.new }
|
8
|
+
let(:set_up) { SetupAssociation.new(mock) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
# expects attr_accessible to return true
|
12
|
+
# and pass 11 arguments
|
13
|
+
mock.
|
14
|
+
expect(:attr_accessible, true) do |args|
|
15
|
+
args.size == 11
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "attr_accessible" do
|
21
|
+
|
22
|
+
it "includes" do
|
23
|
+
set_up.stub :toggle, true do
|
24
|
+
set_up.include_attr_acc?.must_equal true
|
25
|
+
|
26
|
+
mock.verify
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "belongs_to" do
|
33
|
+
|
34
|
+
it "active_record" do
|
35
|
+
mock.expect(:belongs_to, true, [Symbol, Hash])
|
36
|
+
set_up.define_belongs_to.must_equal true
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#set" do
|
42
|
+
|
43
|
+
it "sets an association" do
|
44
|
+
def set_up.include_attr_acc?; true; end
|
45
|
+
|
46
|
+
set_up.stub(:define_belongs_to, true) {
|
47
|
+
set_up.set.must_equal :done
|
48
|
+
}
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|