counter_culture 1.8.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +65 -0
  3. data/.travis.yml +27 -9
  4. data/Appraisals +22 -0
  5. data/CHANGELOG.md +169 -0
  6. data/Gemfile +6 -41
  7. data/README.md +142 -21
  8. data/Rakefile +7 -34
  9. data/counter_culture.gemspec +39 -168
  10. data/gemfiles/rails_4.2.gemfile +10 -0
  11. data/gemfiles/rails_5.0.gemfile +10 -0
  12. data/gemfiles/rails_5.1.gemfile +10 -0
  13. data/gemfiles/rails_5.2.gemfile +10 -0
  14. data/gemfiles/rails_6.0.gemfile +10 -0
  15. data/lib/counter_culture.rb +1 -1
  16. data/lib/counter_culture/counter.rb +56 -38
  17. data/lib/counter_culture/extensions.rb +58 -48
  18. data/lib/counter_culture/reconciler.rb +83 -13
  19. data/lib/counter_culture/version.rb +3 -0
  20. data/lib/generators/counter_culture_generator.rb +7 -1
  21. data/lib/generators/templates/counter_culture_migration.rb.erb +6 -12
  22. data/run_tests_locally.sh +20 -0
  23. metadata +100 -131
  24. data/VERSION +0 -1
  25. data/spec/counter_culture_spec.rb +0 -1857
  26. data/spec/models/another_post.rb +0 -13
  27. data/spec/models/another_post_comment.rb +0 -4
  28. data/spec/models/candidate.rb +0 -3
  29. data/spec/models/candidate_profile.rb +0 -3
  30. data/spec/models/categ.rb +0 -13
  31. data/spec/models/category.rb +0 -3
  32. data/spec/models/company.rb +0 -11
  33. data/spec/models/conditional_dependent.rb +0 -7
  34. data/spec/models/conditional_main.rb +0 -3
  35. data/spec/models/conversation.rb +0 -4
  36. data/spec/models/has_string_id.rb +0 -4
  37. data/spec/models/industry.rb +0 -2
  38. data/spec/models/person.rb +0 -4
  39. data/spec/models/poly_employee.rb +0 -3
  40. data/spec/models/poly_image.rb +0 -15
  41. data/spec/models/poly_product.rb +0 -4
  42. data/spec/models/post.rb +0 -10
  43. data/spec/models/post_comment.rb +0 -6
  44. data/spec/models/product.rb +0 -7
  45. data/spec/models/review.rb +0 -33
  46. data/spec/models/simple_dependent.rb +0 -5
  47. data/spec/models/simple_main.rb +0 -3
  48. data/spec/models/simple_review.rb +0 -3
  49. data/spec/models/soft_delete.rb +0 -6
  50. data/spec/models/subcateg.rb +0 -14
  51. data/spec/models/transaction.rb +0 -15
  52. data/spec/models/twitter_review.rb +0 -6
  53. data/spec/models/user.rb +0 -40
  54. data/spec/rails_app/.gitignore +0 -15
  55. data/spec/rails_app/Gemfile +0 -41
  56. data/spec/rails_app/Gemfile.lock +0 -150
  57. data/spec/rails_app/README.rdoc +0 -261
  58. data/spec/rails_app/Rakefile +0 -7
  59. data/spec/rails_app/app/assets/images/rails.png +0 -0
  60. data/spec/rails_app/app/assets/javascripts/application.js +0 -15
  61. data/spec/rails_app/app/assets/stylesheets/application.css +0 -13
  62. data/spec/rails_app/app/controllers/application_controller.rb +0 -3
  63. data/spec/rails_app/app/helpers/application_helper.rb +0 -2
  64. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  65. data/spec/rails_app/app/models/.gitkeep +0 -0
  66. data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
  67. data/spec/rails_app/config.ru +0 -4
  68. data/spec/rails_app/config/application.rb +0 -58
  69. data/spec/rails_app/config/boot.rb +0 -6
  70. data/spec/rails_app/config/database.yml +0 -25
  71. data/spec/rails_app/config/environment.rb +0 -5
  72. data/spec/rails_app/config/environments/development.rb +0 -32
  73. data/spec/rails_app/config/environments/test.rb +0 -31
  74. data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  75. data/spec/rails_app/config/initializers/inflections.rb +0 -15
  76. data/spec/rails_app/config/initializers/mime_types.rb +0 -5
  77. data/spec/rails_app/config/initializers/paper_trail.rb +0 -1
  78. data/spec/rails_app/config/initializers/secret_token.rb +0 -7
  79. data/spec/rails_app/config/initializers/session_store.rb +0 -8
  80. data/spec/rails_app/config/initializers/wrap_parameters.rb +0 -14
  81. data/spec/rails_app/config/locales/en.yml +0 -5
  82. data/spec/rails_app/config/routes.rb +0 -58
  83. data/spec/rails_app/db/seeds.rb +0 -7
  84. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  85. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  86. data/spec/rails_app/log/.gitkeep +0 -0
  87. data/spec/rails_app/public/404.html +0 -26
  88. data/spec/rails_app/public/422.html +0 -26
  89. data/spec/rails_app/public/500.html +0 -25
  90. data/spec/rails_app/public/favicon.ico +0 -0
  91. data/spec/rails_app/public/index.html +0 -241
  92. data/spec/rails_app/public/robots.txt +0 -5
  93. data/spec/rails_app/script/rails +0 -6
  94. data/spec/rails_app/test/fixtures/.gitkeep +0 -0
  95. data/spec/rails_app/test/functional/.gitkeep +0 -0
  96. data/spec/rails_app/test/integration/.gitkeep +0 -0
  97. data/spec/rails_app/test/performance/browsing_test.rb +0 -12
  98. data/spec/rails_app/test/test_helper.rb +0 -13
  99. data/spec/rails_app/test/unit/.gitkeep +0 -0
  100. data/spec/rails_app/vendor/assets/javascripts/.gitkeep +0 -0
  101. data/spec/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
  102. data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
  103. data/spec/schema.rb +0 -227
  104. data/spec/spec_helper.rb +0 -32
  105. data/test_rails_versions.sh +0 -13
@@ -1,13 +0,0 @@
1
- class AnotherPost < ActiveRecord::Base
2
- has_many :comments, class_name: 'AnotherPostComment', foreign_key: 'another_post_id', primary_key: 'another_id'
3
-
4
- before_save :assign_another_id, :if => :new_record?
5
-
6
- private
7
- def assign_another_id
8
- loop do
9
- self.another_id = Random.rand(65535)
10
- break unless self.class.where(another_id: another_id).exists?
11
- end
12
- end
13
- end
@@ -1,4 +0,0 @@
1
- class AnotherPostComment < ActiveRecord::Base
2
- belongs_to :post, class_name: 'AnotherPost', foreign_key: 'another_post_id', primary_key: 'another_id'
3
- counter_culture :post
4
- end
@@ -1,3 +0,0 @@
1
- class Candidate < ActiveRecord::Base
2
- has_one :candidate_profile, inverse_of: :candidate
3
- end
@@ -1,3 +0,0 @@
1
- class CandidateProfile < ActiveRecord::Base
2
- belongs_to :candidate
3
- end
@@ -1,13 +0,0 @@
1
- class Categ < ActiveRecord::Base
2
- CAT_1 = 0
3
- CAT_2 = 1
4
-
5
- self.primary_key = :cat_id
6
-
7
- has_many :subcategs, :foreign_key => :fk_subcat_id
8
-
9
- def cat_id
10
- # required for Rails 3.2 compatibility
11
- read_attribute(:cat_id)
12
- end
13
- end
@@ -1,3 +0,0 @@
1
- class Category < ActiveRecord::Base
2
- has_many :products
3
- end
@@ -1,11 +0,0 @@
1
- class Company < ActiveRecord::Base
2
- belongs_to :industry
3
- has_many :managers, :foreign_key => :manages_company_id
4
-
5
-
6
- belongs_to :parent, :class_name => 'Company', :foreign_key => 'parent_id'
7
- has_many :children, :class_name => 'Company', :foreign_key => 'parent_id'
8
-
9
- counter_culture :parent, :column_name => :children_count
10
-
11
- end
@@ -1,7 +0,0 @@
1
- class ConditionalDependent < ActiveRecord::Base
2
- belongs_to :conditional_main
3
-
4
- counter_culture :conditional_main,
5
- column_name: proc {|m| m.condition? ? 'conditional_dependents_count' : nil },
6
- column_names: { ['conditional_dependents.condition = ?', true] => 'conditional_dependents_count' }
7
- end
@@ -1,3 +0,0 @@
1
- class ConditionalMain < ActiveRecord::Base
2
- has_many :conditional_dependents
3
- end
@@ -1,4 +0,0 @@
1
- class Conversation < ActiveRecord::Base
2
- belongs_to :candidate
3
- counter_culture [:candidate, :candidate_profile]
4
- end
@@ -1,4 +0,0 @@
1
- class HasStringId < ActiveRecord::Base
2
- self.primary_key = :id
3
- has_many :users
4
- end
@@ -1,2 +0,0 @@
1
- class Industry < ActiveRecord::Base
2
- end
@@ -1,4 +0,0 @@
1
- class Person < ActiveRecord::Base
2
-
3
- has_many :transactions
4
- end
@@ -1,3 +0,0 @@
1
- class PolyEmployee < ActiveRecord::Base
2
- has_many :poly_images, as: :imageable
3
- end
@@ -1,15 +0,0 @@
1
- class PolyImage < ActiveRecord::Base
2
- belongs_to :imageable, polymorphic: true
3
- counter_culture :imageable
4
- counter_culture :imageable, column_name: 'poly_images_count_dup'
5
- counter_culture :imageable, column_name: ->(i){i.special? ? 'special_poly_images_count' : nil },
6
- column_names: {
7
- ["poly_images.url LIKE ?", '%special%'] => 'special_poly_images_count',
8
- }
9
-
10
-
11
- def special?
12
- url && url.include?('special')
13
- end
14
-
15
- end
@@ -1,4 +0,0 @@
1
- class PolyProduct < ActiveRecord::Base
2
- self.primary_key = :pp_pk_id
3
- has_many :poly_images, as: :imageable
4
- end
@@ -1,10 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- self.primary_key = :post_id
3
-
4
- belongs_to :subcateg, :foreign_key => :fk_subcat_id
5
-
6
- has_many :post_comments
7
- counter_culture :subcateg, :column_name => :posts_count
8
-
9
- counter_culture [:subcateg, :categ]
10
- end
@@ -1,6 +0,0 @@
1
- class PostComment < ActiveRecord::Base
2
- self.primary_key = :post_id
3
-
4
- belongs_to :post, :foreign_key => 'post_id'
5
- counter_culture :post, :column_name => :comments_count
6
- end
@@ -1,7 +0,0 @@
1
- class Product < ActiveRecord::Base
2
- belongs_to :category
3
-
4
- counter_culture :category, :foreign_key_values => proc {|foreign_key_value| Category.pluck(:id) }
5
-
6
- has_paper_trail
7
- end
@@ -1,33 +0,0 @@
1
- class Review < ActiveRecord::Base
2
- belongs_to :user
3
- belongs_to :product
4
-
5
- counter_culture :product, :touch => true, :with_papertrail => true
6
- counter_culture :product, :column_name => 'rexiews_count', touch: :rexiews_updated_at
7
- counter_culture :user
8
- counter_culture :user, :column_name => proc { |model| model.review_type && model.review_type != 'null' ? "#{model.review_type}_count" : nil }, :column_names => {"reviews.review_type = 'using'" => 'using_count', "reviews.review_type = 'tried'" => 'tried_count', "reviews.review_type = 'null'" => nil}
9
- counter_culture :user, :column_name => 'review_approvals_count', :delta_column => 'approvals'
10
- counter_culture :user, :column_name => 'review_value_sum', :delta_column => 'value'
11
- counter_culture :user, :column_name => 'dynamic_delta_count', delta_magnitude: proc {|model| model.weight }
12
- counter_culture :user, :column_name => 'custom_delta_count', delta_magnitude: 3
13
- counter_culture [:user, :manages_company]
14
- counter_culture [:user, :manages_company], :column_name => 'review_approvals_count', :delta_column => 'approvals'
15
- counter_culture [:user, :manages_company, :industry]
16
- counter_culture [:user, :manages_company, :industry], :column_name => 'rexiews_count'
17
- counter_culture [:user, :manages_company, :industry], :column_name => proc { |model| model.review_type ? "#{model.review_type}_count" : nil }
18
- counter_culture [:user, :manages_company, :industry], :column_name => 'review_approvals_count', :delta_column => 'approvals'
19
-
20
- after_create :update_some_text
21
-
22
- def update_some_text
23
- update_attribute(:some_text, rand(36**12).to_s(36))
24
- end
25
-
26
- def weight
27
- if heavy?
28
- 2
29
- else
30
- 1
31
- end
32
- end
33
- end
@@ -1,5 +0,0 @@
1
- class SimpleDependent < ActiveRecord::Base
2
- belongs_to :simple_main
3
-
4
- counter_culture :simple_main
5
- end
@@ -1,3 +0,0 @@
1
- class SimpleMain < ActiveRecord::Base
2
- has_many :simple_dependents
3
- end
@@ -1,3 +0,0 @@
1
- class SimpleReview < Review
2
- counter_culture :product
3
- end
@@ -1,6 +0,0 @@
1
- class SoftDelete < ActiveRecord::Base
2
- acts_as_paranoid
3
-
4
- belongs_to :company
5
- counter_culture :company
6
- end
@@ -1,14 +0,0 @@
1
- class Subcateg < ActiveRecord::Base
2
- SUBCAT_1 = 0
3
- SUBCAT_2 = 1
4
-
5
- self.primary_key = :subcat_id
6
-
7
- has_many :posts
8
- belongs_to :categ, :foreign_key => :fk_cat_id
9
-
10
- def subcat_id
11
- # required for Rails 3.2 compatibility
12
- read_attribute(:subcat_id)
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- class Transaction < ActiveRecord::Base
2
- belongs_to :person
3
-
4
- counter_culture [:person],
5
- :column_name => proc {|model| model.earns_money? ? 'money_earned_total' : 'money_spent_total' },
6
- :column_names => {
7
- ["transactions.monetary_value > 0"] => 'money_earned_total',
8
- ["transactions.monetary_value <= 0"] => 'money_spent_total'
9
- },
10
- :delta_column => 'monetary_value'
11
-
12
- def earns_money?
13
- monetary_value > 0
14
- end
15
- end
@@ -1,6 +0,0 @@
1
- class TwitterReview < Review
2
- counter_culture :product, column_name: 'twitter_reviews_count'
3
-
4
- counter_culture [:user, :manages_company]
5
-
6
- end
@@ -1,40 +0,0 @@
1
- class User < ActiveRecord::Base
2
- belongs_to :employer
3
-
4
- belongs_to :manages_company, :class_name => "Company"
5
- counter_culture :manages_company, :column_name => "managers_count"
6
- belongs_to :has_string_id
7
- counter_culture :has_string_id
8
-
9
- has_many :reviews
10
- accepts_nested_attributes_for :reviews, :allow_destroy => true
11
-
12
- has_paper_trail
13
-
14
- default_scope do
15
- if _default_scope_enabled
16
- query = joins("LEFT OUTER JOIN companies")
17
- if Rails.version < "5.0.0"
18
- query = query.uniq
19
- else
20
- query = query.distinct
21
- end
22
- else
23
- if Rails.version < "4.0.0"
24
- scoped
25
- else
26
- all
27
- end
28
- end
29
- end
30
-
31
- class << self
32
- attr_accessor :_default_scope_enabled
33
-
34
- def with_default_scope
35
- @_default_scope_enabled = true
36
- yield
37
- @_default_scope_enabled = false
38
- end
39
- end
40
- end
@@ -1,15 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
- # Ignore bundler config
8
- /.bundle
9
-
10
- # Ignore the default SQLite database.
11
- /db/*.sqlite3
12
-
13
- # Ignore all logfiles and tempfiles.
14
- /log/*.log
15
- /tmp
@@ -1,41 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rails', '~> 4.2.0'
4
-
5
- # Bundle edge Rails instead:
6
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
-
8
- gem 'sqlite3'
9
-
10
- # Gems used only for assets and not required
11
- # in production environments by default.
12
- group :assets do
13
- gem 'sass-rails'
14
- gem 'coffee-rails'
15
-
16
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
17
- # gem 'therubyracer', :platform => :ruby
18
-
19
- gem 'uglifier'
20
- end
21
-
22
- gem 'jquery-rails'
23
-
24
- gem 'counter_culture', path: '../..'
25
-
26
- gem 'paper_trail'
27
-
28
- # To use ActiveModel has_secure_password
29
- # gem 'bcrypt-ruby', '~> 3.0.0'
30
-
31
- # To use Jbuilder templates for JSON
32
- # gem 'jbuilder'
33
-
34
- # Use unicorn as the app server
35
- # gem 'unicorn'
36
-
37
- # Deploy with Capistrano
38
- # gem 'capistrano'
39
-
40
- # To use debugger
41
- # gem 'ruby-debug19', :require => 'ruby-debug'
@@ -1,150 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- counter_culture (1.6.2)
5
- activerecord (>= 3.0.0)
6
- activesupport (>= 3.0.0)
7
- after_commit_action (~> 1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionmailer (4.2.7.1)
13
- actionpack (= 4.2.7.1)
14
- actionview (= 4.2.7.1)
15
- activejob (= 4.2.7.1)
16
- mail (~> 2.5, >= 2.5.4)
17
- rails-dom-testing (~> 1.0, >= 1.0.5)
18
- actionpack (4.2.7.1)
19
- actionview (= 4.2.7.1)
20
- activesupport (= 4.2.7.1)
21
- rack (~> 1.6)
22
- rack-test (~> 0.6.2)
23
- rails-dom-testing (~> 1.0, >= 1.0.5)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
- actionview (4.2.7.1)
26
- activesupport (= 4.2.7.1)
27
- builder (~> 3.1)
28
- erubis (~> 2.7.0)
29
- rails-dom-testing (~> 1.0, >= 1.0.5)
30
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
- activejob (4.2.7.1)
32
- activesupport (= 4.2.7.1)
33
- globalid (>= 0.3.0)
34
- activemodel (4.2.7.1)
35
- activesupport (= 4.2.7.1)
36
- builder (~> 3.1)
37
- activerecord (4.2.7.1)
38
- activemodel (= 4.2.7.1)
39
- activesupport (= 4.2.7.1)
40
- arel (~> 6.0)
41
- activesupport (4.2.7.1)
42
- i18n (~> 0.7)
43
- json (~> 1.7, >= 1.7.7)
44
- minitest (~> 5.1)
45
- thread_safe (~> 0.3, >= 0.3.4)
46
- tzinfo (~> 1.1)
47
- after_commit_action (1.0.1)
48
- activerecord (>= 3.0.0)
49
- activesupport (>= 3.0.0)
50
- arel (6.0.3)
51
- builder (3.2.2)
52
- coffee-rails (4.2.1)
53
- coffee-script (>= 2.2.0)
54
- railties (>= 4.0.0, < 5.2.x)
55
- coffee-script (2.4.1)
56
- coffee-script-source
57
- execjs
58
- coffee-script-source (1.10.0)
59
- concurrent-ruby (1.0.2)
60
- erubis (2.7.0)
61
- execjs (2.7.0)
62
- globalid (0.3.7)
63
- activesupport (>= 4.1.0)
64
- i18n (0.7.0)
65
- jquery-rails (4.2.1)
66
- rails-dom-testing (>= 1, < 3)
67
- railties (>= 4.2.0)
68
- thor (>= 0.14, < 2.0)
69
- json (1.8.3)
70
- loofah (2.0.3)
71
- nokogiri (>= 1.5.9)
72
- mail (2.6.4)
73
- mime-types (>= 1.16, < 4)
74
- mime-types (3.1)
75
- mime-types-data (~> 3.2015)
76
- mime-types-data (3.2016.0521)
77
- mini_portile2 (2.1.0)
78
- minitest (5.9.1)
79
- nokogiri (1.6.8.1)
80
- mini_portile2 (~> 2.1.0)
81
- paper_trail (7.0.3)
82
- activerecord (>= 4.0, < 5.2)
83
- request_store (~> 1.1)
84
- rack (1.6.5)
85
- rack-test (0.6.3)
86
- rack (>= 1.0)
87
- rails (4.2.7.1)
88
- actionmailer (= 4.2.7.1)
89
- actionpack (= 4.2.7.1)
90
- actionview (= 4.2.7.1)
91
- activejob (= 4.2.7.1)
92
- activemodel (= 4.2.7.1)
93
- activerecord (= 4.2.7.1)
94
- activesupport (= 4.2.7.1)
95
- bundler (>= 1.3.0, < 2.0)
96
- railties (= 4.2.7.1)
97
- sprockets-rails
98
- rails-deprecated_sanitizer (1.0.3)
99
- activesupport (>= 4.2.0.alpha)
100
- rails-dom-testing (1.0.7)
101
- activesupport (>= 4.2.0.beta, < 5.0)
102
- nokogiri (~> 1.6.0)
103
- rails-deprecated_sanitizer (>= 1.0.1)
104
- rails-html-sanitizer (1.0.3)
105
- loofah (~> 2.0)
106
- railties (4.2.7.1)
107
- actionpack (= 4.2.7.1)
108
- activesupport (= 4.2.7.1)
109
- rake (>= 0.8.7)
110
- thor (>= 0.18.1, < 2.0)
111
- rake (11.3.0)
112
- request_store (1.3.2)
113
- sass (3.4.22)
114
- sass-rails (5.0.6)
115
- railties (>= 4.0.0, < 6)
116
- sass (~> 3.1)
117
- sprockets (>= 2.8, < 4.0)
118
- sprockets-rails (>= 2.0, < 4.0)
119
- tilt (>= 1.1, < 3)
120
- sprockets (3.7.0)
121
- concurrent-ruby (~> 1.0)
122
- rack (> 1, < 3)
123
- sprockets-rails (3.2.0)
124
- actionpack (>= 4.0)
125
- activesupport (>= 4.0)
126
- sprockets (>= 3.0.0)
127
- sqlite3 (1.3.12)
128
- thor (0.19.1)
129
- thread_safe (0.3.5)
130
- tilt (2.0.5)
131
- tzinfo (1.2.2)
132
- thread_safe (~> 0.1)
133
- uglifier (3.0.3)
134
- execjs (>= 0.3.0, < 3)
135
-
136
- PLATFORMS
137
- ruby
138
-
139
- DEPENDENCIES
140
- coffee-rails
141
- counter_culture!
142
- jquery-rails
143
- paper_trail
144
- rails (~> 4.2.0)
145
- sass-rails
146
- sqlite3
147
- uglifier
148
-
149
- BUNDLED WITH
150
- 1.14.6