simple_hashtag 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74437104ecf0ee1acfa40e6764e6c802a9eb02fe
4
- data.tar.gz: 954eee25094360ae8cf157f48919463278817695
3
+ metadata.gz: cc85a0f8c27f897cd9ec7b4a8c6d723538b86783
4
+ data.tar.gz: 0f3566639a3ab1056ff7bf400d78ed20c83d77c8
5
5
  SHA512:
6
- metadata.gz: b7db642ed1c8c08b5af09157cf4299a9b31bd563069d6b12f75c94d93b0b0da025ab59a332bef330217c90b8305125fb4e4e6835ba1e2e43c3185e692b6738ad
7
- data.tar.gz: 68edcf1890776324cc59bd2fb4aeeda8e3885132d0fd9f12fb1ca082540a296ea1613e4500520e565f5961653104faa5ae0b2e900bca0095adf57628be0b0f44
6
+ metadata.gz: d808068477f4ec677356bf7c6dcefe73f8a6d5cd3115444e3b0e0608686af7b6a2a8cd3459d887275ddc3c15f65fa90842bdffc7b85489f1acf7abba0ba5aa5e
7
+ data.tar.gz: ee55a55cd807ec34ad8e9c16477cf46c8b860dfc3d502f0566f8c4d4126a57615b1388a7a62b2928d6da74388b80625a58dadfcefe9862c900d516ede932617e
@@ -4,6 +4,8 @@ module SimpleHashtag
4
4
 
5
5
  has_many :hashtaggings
6
6
 
7
+ validates :name, uniqueness: true
8
+
7
9
  # TODO Beef up the regex (ie.:what if content is HTML)
8
10
  # this is how Twitter does it:
9
11
  # https://github.com/twitter/twitter-text-rb/blob/master/lib/twitter-text/regex.rb
@@ -12,6 +14,10 @@ module SimpleHashtag
12
14
  def self.find_by_name(name)
13
15
  Hashtag.where("lower(name) =?", name.downcase).first
14
16
  end
17
+ def self.find_or_create_by_name(name, &block)
18
+ find_by_name(name) || create(name: name, &block)
19
+ end
20
+
15
21
 
16
22
  def name=(val)
17
23
  write_attribute(:name, val.downcase)
@@ -22,7 +22,7 @@ module SimpleHashtag
22
22
  parsed_hashtags = []
23
23
  array_of_hashtags_as_string = scan_for_hashtags(hashtaggable_content)
24
24
  array_of_hashtags_as_string.each do |s|
25
- parsed_hashtags << Hashtag.find_or_create_by(name: s[1])
25
+ parsed_hashtags << Hashtag.find_or_create_by_name(s[1])
26
26
  end
27
27
  parsed_hashtags
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleHashtag
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -99,5 +99,16 @@ describe SimpleHashtag do
99
99
  p.hashtags.count.should eq 3
100
100
  p.hashtags.map(&:to_s).should eq ["rain-curtain", "silver", "see"]
101
101
  end
102
+
103
+ it "doesn't duplicate on mixed case" do
104
+ ActiveRecord::Base.subclasses.each(&:delete_all)
105
+ Post.create(body: "Certainty of death, small #chance of success.")
106
+ Post.create(body: "Certainty of death, small #Chance of success.")
107
+
108
+ SimpleHashtag::Hashtag.count.should eq 1
109
+ h = SimpleHashtag::Hashtag.last
110
+ h.name.should eq "chance"
111
+ h.hashtaggables.count.should eq 2
112
+ end
102
113
  end
103
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_hashtag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Campardou