-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from fjuan/add_test_coverage_to_codeclimate
Add specs and a minimum test coverage
- Loading branch information
Showing
11 changed files
with
199 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*.gem | ||
Gemfile.lock | ||
.byebug_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ruby: | ||
config_file: .ruby-style.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Style/StringLiterals: | ||
Enabled: true | ||
EnforcedStyle: single_quotes | ||
Style/DotPosition: | ||
Enabled: true | ||
EnforcedStyle: leading | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
require 'acts_as_tokenizable/acts_as_tokenizable' | ||
$LOAD_PATH << File.dirname(__FILE__) | ||
|
||
module ActiveRecord | ||
class Base | ||
def self.acts_as_tokenizable(field_name = :token) | ||
include ActsAsTokenizable | ||
self.token_field_name = field_name | ||
before_save :tokenize | ||
end | ||
end | ||
end | ||
require 'acts_as_tokenizable/base' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'active_record' | ||
require 'acts_as_tokenizable/acts_as_tokenizable' | ||
|
||
module ActiveRecord | ||
class Base | ||
def self.acts_as_tokenizable(field_name = :token) | ||
include ActsAsTokenizable | ||
self.token_field_name = field_name | ||
before_save :tokenize | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,34 @@ | ||
require 'spec_helper' | ||
require 'support_helper' | ||
|
||
describe ActiveRecord do | ||
it 'does stuff' do | ||
pending # no code yet | ||
describe 'classes with acts_as_tokenizable' do | ||
it 'does include to_token and tokenize methods' do | ||
expect(Friend.instance_methods) | ||
.to include(:tokenize, :tokenize!, :to_token) | ||
end | ||
|
||
it 'updates the token field after creating an object' do | ||
friend = Friend.new name: 'John', email: 'john@example.com' | ||
expect(friend.token).to be_nil | ||
friend.save | ||
expect(friend.token).to eq('john') | ||
end | ||
|
||
it 'allows different token field name' do | ||
malmo = City.create name: 'Malmö' | ||
expect(malmo.tokenized_name).to eq('malmo') | ||
end | ||
|
||
it 'raises an error if `to_token` method is not defined' do | ||
expect { Enemy.to_token }.to raise_error(NoMethodError) | ||
end | ||
end | ||
|
||
describe 'classes without acts_as_tokenizable' do | ||
it 'does not include to_token and tokenize methods' do | ||
expect(Pet.instance_methods) | ||
.to_not include(:tokenize, :tokenize!, :to_token) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
require 'coveralls' | ||
Coveralls.wear! | ||
|
||
$LOAD_PATH << File.dirname(__FILE__) + '/../lib' | ||
|
||
require 'acts_as_tokenizable' | ||
require 'byebug' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'spec_helper' | ||
|
||
module ActsAsTokenizable | ||
describe StringUtils do | ||
describe '.numeric?' do | ||
it 'returns true with a float' do | ||
expect(described_class.numeric?('1.2')).to be_truthy | ||
end | ||
|
||
it 'returns true with an integer' do | ||
expect(described_class.numeric?('1')).to be_truthy | ||
end | ||
|
||
it 'returns true with a negative number' do | ||
expect(described_class.numeric?('-11')).to be_truthy | ||
end | ||
|
||
it 'returns false with a string' do | ||
expect(described_class.numeric?('1a')).to be_falsy | ||
end | ||
end | ||
|
||
describe '.words' do | ||
it 'splits a string into by word separators' do | ||
example = 'una mamá española aterrizó en Götemborg-int, Suecia.' | ||
|
||
expect(described_class.words(example)) | ||
.to match_array %w(una mamá española aterrizó en Götemborg-int Suecia) | ||
end | ||
end | ||
|
||
describe '.remove_words' do | ||
it 'returns a string without the specified list of words' do | ||
sentence = 'a b c d e f g' | ||
words_to_remove = %w(c e f) | ||
expect(described_class.remove_words(sentence, words_to_remove, ' ')) | ||
.to eq('a b d g') | ||
end | ||
|
||
it 'remove multiples occurences of a word' do | ||
sentence = 'a b a d a f g' | ||
words_to_remove = %w(a f) | ||
expect(described_class.remove_words(sentence, words_to_remove, ' ')) | ||
.to eq('b d g') | ||
end | ||
end | ||
|
||
describe '.to_token' do | ||
it 'transforms tildes and letter modifications' do | ||
examples = { | ||
'mamá' => 'mama', | ||
'éxtasis' => 'extasis', | ||
'maría' => 'maria', | ||
'camión' => 'camion', | ||
'Úrsula' => 'ursula', | ||
'Umeå' => 'umea', | ||
'Gävle' => 'gavle', | ||
'Malmö' => 'malmo', | ||
'terraza' => 'teraza', | ||
'España' => 'espana' | ||
} | ||
|
||
examples.each do |string, expected_token| | ||
expect(described_class.to_token(string)).to eq(expected_token) | ||
end | ||
end | ||
|
||
it 'removes duplicate characters' do | ||
expect(described_class.to_token('terraza')).to eq('teraza') | ||
end | ||
end | ||
|
||
describe '.words_to_token' do | ||
it 'converts a string into something that can be used as an index key' do | ||
example = 'una mamá española aterrizó en Götemborg-int, Suecia.' | ||
|
||
expect(described_class.words_to_token(example)) | ||
.to eq('una mama espanola aterizo en gotemborg-int suecia') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class Pet < ActiveRecord::Base | ||
end | ||
|
||
class Enemy < ActiveRecord::Base | ||
acts_as_tokenizable :token | ||
end | ||
|
||
class Friend < ActiveRecord::Base | ||
acts_as_tokenizable :token | ||
|
||
def to_token | ||
ActsAsTokenizable::StringUtils.words_to_token(name) | ||
end | ||
end | ||
|
||
class City < ActiveRecord::Base | ||
acts_as_tokenizable :tokenized_name | ||
|
||
def to_token | ||
ActsAsTokenizable::StringUtils.words_to_token(name) | ||
end | ||
end | ||
|
||
ActiveRecord::Base.establish_connection( | ||
adapter: 'sqlite3', | ||
database: ':memory:' | ||
) | ||
|
||
ActiveRecord::Base.logger | ||
ActiveRecord::Schema.define do | ||
self.verbose = false | ||
end | ||
|
||
ActiveRecord::Schema.define(version: 1) do | ||
create_table :pets do |t| | ||
t.column :name, :string | ||
t.column :owner, :string | ||
end | ||
end | ||
|
||
ActiveRecord::Schema.define(version: 2) do | ||
create_table :friends do |t| | ||
t.column :name, :string | ||
t.column :email, :string | ||
t.column :age, :integer | ||
t.column :token, :text | ||
end | ||
end | ||
|
||
ActiveRecord::Schema.define(version: 3) do | ||
create_table :cities do |t| | ||
t.column :name, :string | ||
t.column :tokenized_name, :text | ||
end | ||
end |