unread 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b54928f534685b22218df3b892e9be469dda4a22
4
- data.tar.gz: 847e2b242a01ac7489bf0f59f0fa88be9e2ee67b
3
+ metadata.gz: 05f0404c7e8d4778e3c417c8ea555ea8281770ec
4
+ data.tar.gz: d528c0105fe90d6e8e354a6828e6edf0fb5d0349
5
5
  SHA512:
6
- metadata.gz: 87aa05f39bb03471ae1eec26b7e51deae00529b93a6bedb99b00f63a13b6a6df7266b717286c728ae9fe7e87ad42dfef0e57f040390ad768bb10eb9a67eb2db0
7
- data.tar.gz: b9a815db5ea3ae66df1c7e60737a74f103b5cbe2e8364ea1abe0a7a1fb8f3b6daa1d6ef5811d0364ae58db78e1b3f8884e5c4e7c40d177d8a0ca43c5cd9174f3
6
+ metadata.gz: d378c5dec0dde8062d584f012b50552af831d6aac3917e7e9df201a1806b0012a35fd878279ae4bfdbe83ee45b2bda760d2eaa56b798ba061f7b380e3c4aed3a
7
+ data.tar.gz: 8f3b85a26665a94e989351320c9ae6ba9b724e035170d6007333e06ae722515417e5685f9ceab0e0718f8c441fb902771ac745f72f404059a9ed0e3d07509cc9
data/.travis.yml CHANGED
@@ -13,3 +13,8 @@ gemfile:
13
13
  - ci/Gemfile-rails-4-2
14
14
  before_install: gem update bundler
15
15
  sudo: false
16
+ env:
17
+ - DB=sqlite
18
+ - DB=mysql
19
+ before_script:
20
+ - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS unread_test;'; fi"
data/ci/Gemfile-rails-3-0 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.0.20'
4
4
  gem 'sqlite3'
5
+ gem 'activerecord-mysql2-adapter'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/ci/Gemfile-rails-3-1 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.1.12'
4
4
  gem 'sqlite3'
5
+ gem 'mysql2'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/ci/Gemfile-rails-3-2 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.2.17'
4
4
  gem 'sqlite3'
5
+ gem 'mysql2'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/ci/Gemfile-rails-4-0 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 4.0.4'
4
4
  gem 'sqlite3'
5
+ gem 'mysql2'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/ci/Gemfile-rails-4-1 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 4.1.0'
4
4
  gem 'sqlite3'
5
+ gem 'mysql2'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/ci/Gemfile-rails-4-2 CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 4.2.0'
4
4
  gem 'sqlite3'
5
+ gem 'mysql2'
5
6
  gem 'timecop'
6
7
  gem 'rake'
7
8
  gem 'rspec'
data/lib/unread/base.rb CHANGED
@@ -5,7 +5,7 @@ module Unread
5
5
 
6
6
  module Base
7
7
  def acts_as_reader(options={})
8
- ReadMark.belongs_to :user, :class_name => self.to_s
8
+ ReadMark.belongs_to :user, :class_name => self.to_s, inverse_of: :read_marks
9
9
 
10
10
  has_many :read_marks, :dependent => :delete_all, :foreign_key => 'user_id', :inverse_of => :user
11
11
 
@@ -32,7 +32,7 @@ module Unread
32
32
  options.reverse_merge!(:on => :updated_at)
33
33
  self.readable_options = options
34
34
 
35
- has_many :read_marks, :as => :readable, :dependent => :delete_all
35
+ has_many :read_marks, :as => :readable, :dependent => :delete_all, inverse_of: :readable
36
36
 
37
37
  ReadMark.readable_classes ||= []
38
38
  ReadMark.readable_classes << self unless ReadMark.readable_classes.include?(self)
@@ -7,7 +7,7 @@ module Unread
7
7
  joins "LEFT JOIN read_marks
8
8
  ON read_marks.readable_type = '#{base_class.name}'
9
9
  AND read_marks.readable_id = #{quoted_table_name}.#{quoted_primary_key}
10
- AND read_marks.user_id = #{user.id}
10
+ AND read_marks.user_id = #{quote_bound_value(user.id)}
11
11
  AND read_marks.timestamp >= #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])}"
12
12
  end
13
13
 
@@ -15,32 +15,28 @@ module Unread
15
15
  result = join_read_marks(user)
16
16
 
17
17
  if global_time_stamp = user.read_mark_global(self).try(:timestamp)
18
- result = result.where("read_marks.id IS NULL
19
- AND #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} > ?", global_time_stamp)
18
+ result.where("read_marks.id IS NULL
19
+ AND #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} > ?", global_time_stamp)
20
20
  else
21
- result = result.where('read_marks.id IS NULL')
21
+ result.where('read_marks.id IS NULL')
22
22
  end
23
-
24
- result
25
23
  end
26
24
 
27
25
  def read_by(user)
28
26
  result = join_read_marks(user)
29
27
 
30
28
  if global_time_stamp = user.read_mark_global(self).try(:timestamp)
31
- result = result.where("read_marks.id IS NOT NULL
32
- OR #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} <= ?", global_time_stamp)
29
+ result.where("read_marks.id IS NOT NULL
30
+ OR #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])} <= ?", global_time_stamp)
33
31
  else
34
- result = result.where('read_marks.id IS NOT NULL')
32
+ result.where('read_marks.id IS NOT NULL')
35
33
  end
36
-
37
- result
38
34
  end
39
35
 
40
36
  def with_read_marks_for(user)
41
37
  join_read_marks(user).select("#{quoted_table_name}.*,
42
38
  read_marks.id AS read_mark_id,
43
- #{user.id} AS read_mark_user_id")
39
+ #{quote_bound_value(user.id)} AS read_mark_user_id")
44
40
  end
45
41
  end
46
42
  end
@@ -12,7 +12,7 @@ module Unread
12
12
  end
13
13
 
14
14
  def have_not_read(readable)
15
- join_read_marks(readable).where("read_marks.id IS NULL")
15
+ join_read_marks(readable).where('read_marks.id IS NULL')
16
16
  end
17
17
 
18
18
  def have_read(readable)
@@ -1,3 +1,3 @@
1
1
  module Unread
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
  end
data/spec/database.yml ADDED
@@ -0,0 +1,8 @@
1
+ sqlite:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ mysql:
5
+ adapter: mysql2
6
+ database: unread_test
7
+ username: root
8
+ encoding: utf8
@@ -25,6 +25,11 @@ describe Unread::Readable do
25
25
  expect(Email.unread_by(@other_reader)).to eq [@email1, @email2]
26
26
  end
27
27
 
28
+ it "should return empty array directly after marking all as read" do
29
+ Email.mark_as_read! :all, :for => @reader
30
+ expect(Email.unread_by(@reader)).to eq([])
31
+ end
32
+
28
33
  it "should not allow invalid parameter" do
29
34
  [ 42, nil, 'foo', :foo, {} ].each do |not_a_reader|
30
35
  expect {
data/spec/spec_helper.rb CHANGED
@@ -51,9 +51,15 @@ if I18n.respond_to?(:enforce_available_locales=)
51
51
  end
52
52
 
53
53
  def setup_db
54
- puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
54
+ configs = YAML.load_file('spec/database.yml')
55
+ ActiveRecord::Base.configurations = configs
55
56
 
56
- ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
57
+ db_name = ENV['DB'] || 'sqlite'
58
+
59
+ puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING} on #{db_name}"
60
+
61
+ ActiveRecord::Base.establish_connection(db_name.to_sym)
62
+ ActiveRecord::Base.default_timezone = :utc
57
63
  ActiveRecord::Migration.verbose = false
58
64
 
59
65
  require File.expand_path('../../lib/generators/unread/migration/templates/migration.rb', __FILE__)
data/unread.gemspec CHANGED
@@ -5,11 +5,13 @@ require "unread/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "unread"
7
7
  s.version = Unread::VERSION
8
+ s.licenses = ['MIT']
8
9
  s.authors = ["Georg Ledermann"]
9
10
  s.email = ["mail@georg-ledermann.de"]
10
- s.homepage = ""
11
+ s.homepage = "https://github.com/ledermann/unread"
11
12
  s.summary = %q{Manages read/unread status of ActiveRecord objects}
12
13
  s.description = %q{This gem creates a scope for unread objects and adds methods to mark objects as read }
14
+ s.required_ruby_version = '>= 1.9.3'
13
15
 
14
16
  s.rubyforge_project = "unread"
15
17
 
@@ -23,6 +25,7 @@ Gem::Specification.new do |s|
23
25
  s.add_development_dependency 'rake'
24
26
  s.add_development_dependency 'timecop'
25
27
  s.add_development_dependency 'sqlite3'
28
+ s.add_development_dependency 'mysql2'
26
29
  s.add_development_dependency 'rspec'
27
30
  s.add_development_dependency 'simplecov'
28
31
  s.add_development_dependency 'coveralls', '>= 0.8.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unread
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Ledermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +153,7 @@ files:
139
153
  - lib/unread/reader_scopes.rb
140
154
  - lib/unread/version.rb
141
155
  - spec/base_spec.rb
156
+ - spec/database.yml
142
157
  - spec/model/email.rb
143
158
  - spec/model/reader.rb
144
159
  - spec/read_mark_spec.rb
@@ -149,8 +164,9 @@ files:
149
164
  - spec/support/query_counter.rb
150
165
  - spec/support/timecop.rb
151
166
  - unread.gemspec
152
- homepage: ''
153
- licenses: []
167
+ homepage: https://github.com/ledermann/unread
168
+ licenses:
169
+ - MIT
154
170
  metadata: {}
155
171
  post_install_message:
156
172
  rdoc_options: []
@@ -160,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
176
  requirements:
161
177
  - - ">="
162
178
  - !ruby/object:Gem::Version
163
- version: '0'
179
+ version: 1.9.3
164
180
  required_rubygems_version: !ruby/object:Gem::Requirement
165
181
  requirements:
166
182
  - - ">="
@@ -168,12 +184,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
184
  version: '0'
169
185
  requirements: []
170
186
  rubyforge_project: unread
171
- rubygems_version: 2.4.7
187
+ rubygems_version: 2.4.8
172
188
  signing_key:
173
189
  specification_version: 4
174
190
  summary: Manages read/unread status of ActiveRecord objects
175
191
  test_files:
176
192
  - spec/base_spec.rb
193
+ - spec/database.yml
177
194
  - spec/model/email.rb
178
195
  - spec/model/reader.rb
179
196
  - spec/read_mark_spec.rb