activator 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/activator.rb +10 -21
  3. data/lib/activator/version.rb +1 -1
  4. metadata +16 -94
  5. data/test/activator_test.rb +0 -50
  6. data/test/dummy/README.rdoc +0 -28
  7. data/test/dummy/Rakefile +0 -6
  8. data/test/dummy/app/assets/javascripts/application.js +0 -13
  9. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  10. data/test/dummy/app/controllers/application_controller.rb +0 -5
  11. data/test/dummy/app/helpers/application_helper.rb +0 -2
  12. data/test/dummy/app/models/project.rb +0 -3
  13. data/test/dummy/app/models/user.rb +0 -2
  14. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  15. data/test/dummy/bin/bundle +0 -3
  16. data/test/dummy/bin/rails +0 -4
  17. data/test/dummy/bin/rake +0 -4
  18. data/test/dummy/config.ru +0 -4
  19. data/test/dummy/config/application.rb +0 -23
  20. data/test/dummy/config/boot.rb +0 -5
  21. data/test/dummy/config/database.yml +0 -25
  22. data/test/dummy/config/environment.rb +0 -5
  23. data/test/dummy/config/environments/development.rb +0 -29
  24. data/test/dummy/config/environments/production.rb +0 -80
  25. data/test/dummy/config/environments/test.rb +0 -36
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  27. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  28. data/test/dummy/config/initializers/inflections.rb +0 -16
  29. data/test/dummy/config/initializers/mime_types.rb +0 -5
  30. data/test/dummy/config/initializers/secret_token.rb +0 -12
  31. data/test/dummy/config/initializers/session_store.rb +0 -3
  32. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  33. data/test/dummy/config/locales/en.yml +0 -23
  34. data/test/dummy/config/routes.rb +0 -56
  35. data/test/dummy/db/development.sqlite3 +0 -0
  36. data/test/dummy/db/migrate/20140424234705_create_projects.rb +0 -9
  37. data/test/dummy/db/migrate/20140425024510_create_users.rb +0 -8
  38. data/test/dummy/db/schema.rb +0 -27
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/dummy/log/development.log +0 -61
  41. data/test/dummy/log/test.log +0 -1954
  42. data/test/dummy/public/404.html +0 -58
  43. data/test/dummy/public/422.html +0 -58
  44. data/test/dummy/public/500.html +0 -57
  45. data/test/dummy/public/favicon.ico +0 -0
  46. data/test/dummy/test/fixtures/projects.yml +0 -7
  47. data/test/dummy/test/fixtures/users.yml +0 -11
  48. data/test/dummy/test/models/project_test.rb +0 -7
  49. data/test/dummy/test/models/user_test.rb +0 -7
  50. data/test/test_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0144188c149944e489bf8bf884a87076dee9f3d
4
- data.tar.gz: 30cb7237b762860a06654aa483d98f1805adeb7a
3
+ metadata.gz: ea33b8dd929767abff42ac3259cd5d670ce9ae51
4
+ data.tar.gz: f74ad1bb74d830af2649384dc0544894350d75f4
5
5
  SHA512:
6
- metadata.gz: 2d13af8c4792d556bd7b92fdc3b6e019eeaba771bf9e19b469ec0c6fe6100de810c304f199a6f79341c2adee37e61485ef38a53a2bc9e3fcf697db73258f73ca
7
- data.tar.gz: cb358f86dd945ef01d36cd9b1e35f8530ba4de27b15d31edf46587f2da07474439833108021a4e0a0c2ecb4effc1b6e927bfdabfc2586b40fd2ef939b13a7cae
6
+ metadata.gz: 301742a7670577c170fe9548356b0868eb5d6408ad56ca818105d5ed8d789586175e6a7493940876d8718c3b023e3a86aab0e7c1c364f151a4b391157489fd50
7
+ data.tar.gz: 7170ca096e87605b70bf33f708e4d18fb070c4abb4cbf2e37877a87d5f0f804b51afe691994591b2827a6ddc06a9485404978b1b8dfe93982a427fbb4f1d8a16
@@ -4,33 +4,22 @@ module Activator
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
+ after_save :deactivate_others
7
8
  end
8
9
 
9
10
  module ClassMethods
10
- def act_as_activator
11
- # If we don't activate a field, we don't need a class method to find the
12
- # active elements.
13
- self.extend(ActivationMethods)
14
- self.send(:include, InstanceMethods)
15
- self.send(:after_save, :deactivate_others)
16
- end
17
-
18
- module ActivationMethods
19
- def active
20
- find_by(active: true)
21
- end
11
+ def active
12
+ find_by(active: true)
22
13
  end
23
14
  end
24
15
 
25
- module InstanceMethods
26
- def deactivate
27
- self.update_attributes(active: false)
28
- end
16
+ def deactivate
17
+ self.update_attributes(active: false)
18
+ end
29
19
 
30
- def deactivate_others
31
- return unless self.active?
32
- self.class.where('id <> :id', id: self.id).where(active: true).
33
- map(&:deactivate)
34
- end
20
+ def deactivate_others
21
+ return unless self.try(:active?)
22
+ self.class.where('id <> :id', id: self.id).where(active: true).
23
+ map(&:deactivate)
35
24
  end
36
25
  end
@@ -1,3 +1,3 @@
1
1
  module Activator
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jelmer Snoeck
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Mark one model as active and automatically deactivate the others.
42
56
  email:
43
57
  - jelmer@siphoc.com
@@ -50,52 +64,6 @@ files:
50
64
  - lib/activator.rb
51
65
  - MIT-LICENSE
52
66
  - Rakefile
53
- - test/activator_test.rb
54
- - test/dummy/app/assets/javascripts/application.js
55
- - test/dummy/app/assets/stylesheets/application.css
56
- - test/dummy/app/controllers/application_controller.rb
57
- - test/dummy/app/helpers/application_helper.rb
58
- - test/dummy/app/models/project.rb
59
- - test/dummy/app/models/user.rb
60
- - test/dummy/app/views/layouts/application.html.erb
61
- - test/dummy/bin/bundle
62
- - test/dummy/bin/rails
63
- - test/dummy/bin/rake
64
- - test/dummy/config/application.rb
65
- - test/dummy/config/boot.rb
66
- - test/dummy/config/database.yml
67
- - test/dummy/config/environment.rb
68
- - test/dummy/config/environments/development.rb
69
- - test/dummy/config/environments/production.rb
70
- - test/dummy/config/environments/test.rb
71
- - test/dummy/config/initializers/backtrace_silencers.rb
72
- - test/dummy/config/initializers/filter_parameter_logging.rb
73
- - test/dummy/config/initializers/inflections.rb
74
- - test/dummy/config/initializers/mime_types.rb
75
- - test/dummy/config/initializers/secret_token.rb
76
- - test/dummy/config/initializers/session_store.rb
77
- - test/dummy/config/initializers/wrap_parameters.rb
78
- - test/dummy/config/locales/en.yml
79
- - test/dummy/config/routes.rb
80
- - test/dummy/config.ru
81
- - test/dummy/db/development.sqlite3
82
- - test/dummy/db/migrate/20140424234705_create_projects.rb
83
- - test/dummy/db/migrate/20140425024510_create_users.rb
84
- - test/dummy/db/schema.rb
85
- - test/dummy/db/test.sqlite3
86
- - test/dummy/log/development.log
87
- - test/dummy/log/test.log
88
- - test/dummy/public/404.html
89
- - test/dummy/public/422.html
90
- - test/dummy/public/500.html
91
- - test/dummy/public/favicon.ico
92
- - test/dummy/Rakefile
93
- - test/dummy/README.rdoc
94
- - test/dummy/test/fixtures/projects.yml
95
- - test/dummy/test/fixtures/users.yml
96
- - test/dummy/test/models/project_test.rb
97
- - test/dummy/test/models/user_test.rb
98
- - test/test_helper.rb
99
67
  homepage: https://github.com/jelmersnoeck/activator
100
68
  licenses: []
101
69
  metadata: {}
@@ -119,50 +87,4 @@ rubygems_version: 2.1.11
119
87
  signing_key:
120
88
  specification_version: 4
121
89
  summary: Mark one model as active
122
- test_files:
123
- - test/activator_test.rb
124
- - test/dummy/app/assets/javascripts/application.js
125
- - test/dummy/app/assets/stylesheets/application.css
126
- - test/dummy/app/controllers/application_controller.rb
127
- - test/dummy/app/helpers/application_helper.rb
128
- - test/dummy/app/models/project.rb
129
- - test/dummy/app/models/user.rb
130
- - test/dummy/app/views/layouts/application.html.erb
131
- - test/dummy/bin/bundle
132
- - test/dummy/bin/rails
133
- - test/dummy/bin/rake
134
- - test/dummy/config/application.rb
135
- - test/dummy/config/boot.rb
136
- - test/dummy/config/database.yml
137
- - test/dummy/config/environment.rb
138
- - test/dummy/config/environments/development.rb
139
- - test/dummy/config/environments/production.rb
140
- - test/dummy/config/environments/test.rb
141
- - test/dummy/config/initializers/backtrace_silencers.rb
142
- - test/dummy/config/initializers/filter_parameter_logging.rb
143
- - test/dummy/config/initializers/inflections.rb
144
- - test/dummy/config/initializers/mime_types.rb
145
- - test/dummy/config/initializers/secret_token.rb
146
- - test/dummy/config/initializers/session_store.rb
147
- - test/dummy/config/initializers/wrap_parameters.rb
148
- - test/dummy/config/locales/en.yml
149
- - test/dummy/config/routes.rb
150
- - test/dummy/config.ru
151
- - test/dummy/db/development.sqlite3
152
- - test/dummy/db/migrate/20140424234705_create_projects.rb
153
- - test/dummy/db/migrate/20140425024510_create_users.rb
154
- - test/dummy/db/schema.rb
155
- - test/dummy/db/test.sqlite3
156
- - test/dummy/log/development.log
157
- - test/dummy/log/test.log
158
- - test/dummy/public/404.html
159
- - test/dummy/public/422.html
160
- - test/dummy/public/500.html
161
- - test/dummy/public/favicon.ico
162
- - test/dummy/Rakefile
163
- - test/dummy/README.rdoc
164
- - test/dummy/test/fixtures/projects.yml
165
- - test/dummy/test/fixtures/users.yml
166
- - test/dummy/test/models/project_test.rb
167
- - test/dummy/test/models/user_test.rb
168
- - test/test_helper.rb
90
+ test_files: []
@@ -1,50 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActivatorTest < ActiveSupport::TestCase
4
- test 'it can find the active items' do
5
- Project.create(active: false)
6
- project = Project.create(active: true)
7
-
8
- assert_equal project, Project.active
9
- end
10
-
11
- test 'it deactivates old items when creating new active ones' do
12
- project1 = Project.create(active: true)
13
- assert project1.active?
14
-
15
- project2 = Project.create(active: true)
16
- assert project2.active?
17
- refute project1.reload.active?
18
- end
19
-
20
- test 'it deactivates other items when setting another item to active' do
21
- project1 = Project.create(active: false)
22
- project2 = Project.create(active: true)
23
-
24
- refute project1.active?
25
- assert project2.active?
26
-
27
- project1.update_attributes(active: true)
28
-
29
- assert project1.reload.active?
30
- refute project2.reload.active?
31
- end
32
-
33
- test 'it shouldnt have an active class method if its not an activator' do
34
- assert_raise NoMethodError do
35
- User.active
36
- end
37
- end
38
-
39
- test 'it shouldnt have deactivation methods if not an activator' do
40
- user = User.create
41
-
42
- assert_raise NoMethodError do
43
- user.deactivate
44
- end
45
-
46
- assert_raise NoMethodError do
47
- user.deactivate_others
48
- end
49
- end
50
- end
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Dummy::Application.load_tasks
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,5 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,3 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- act_as_activator
3
- end
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
- <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
4
- Rake.application.run
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Rails.application
@@ -1,23 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- Bundler.require(*Rails.groups)
6
- require "activator"
7
-
8
- module Dummy
9
- class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
- # config.time_zone = 'Central Time (US & Canada)'
17
-
18
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
- # config.i18n.default_locale = :de
21
- end
22
- end
23
-
@@ -1,5 +0,0 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,25 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- development:
7
- adapter: sqlite3
8
- database: db/development.sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- # Warning: The database defined as "test" will be erased and
13
- # re-generated from your development database when you run "rake".
14
- # Do not set this db to the same as development or production.
15
- test:
16
- adapter: sqlite3
17
- database: db/test.sqlite3
18
- pool: 5
19
- timeout: 5000
20
-
21
- production:
22
- adapter: sqlite3
23
- database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Dummy::Application.initialize!
@@ -1,29 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Do not eager load code on boot.
10
- config.eager_load = false
11
-
12
- # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send.
17
- config.action_mailer.raise_delivery_errors = false
18
-
19
- # Print deprecation notices to the Rails logger.
20
- config.active_support.deprecation = :log
21
-
22
- # Raise an error on page load if there are pending migrations
23
- config.active_record.migration_error = :page_load
24
-
25
- # Debug mode disables concatenation and preprocessing of assets.
26
- # This option may cause significant delays in view rendering with a large
27
- # number of complex assets.
28
- config.assets.debug = true
29
- end