-
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.
- Loading branch information
1 parent
dd213c4
commit 91a39a8
Showing
7 changed files
with
102 additions
and
38 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,4 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class TextSample < ApplicationRecord | ||
validates :description, presence: true | ||
validates :text, presence: true | ||
|
||
def build_word_chunks | ||
chunk_sizes = 2..8 | ||
|
||
chunk_sizes.each do |chunk_size| | ||
build_word_chunks_of_size(chunk_size) unless text.size < chunk_size | ||
end | ||
end | ||
|
||
def build_word_chunks_of_size(chunk_size); 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,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class WordChunk < ApplicationRecord | ||
belongs_to :text_sample | ||
|
||
|
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,24 +1,37 @@ | ||
example_id | status | run_time | | ||
--------------------------------------------- | ------- | --------------- | | ||
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.02027 seconds | | ||
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.0024 seconds | | ||
./spec/models/text_sample_spec.rb[1:2:1] | passed | 0.03488 seconds | | ||
./spec/models/text_sample_spec.rb[1:2:2] | pending | 0.00001 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:1] | passed | 0.00441 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:2] | passed | 0.00293 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:3] | passed | 0.00311 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:4] | passed | 0.0458 seconds | | ||
./spec/requests/text_samples_spec.rb[1:1:1] | passed | 0.01542 seconds | | ||
./spec/requests/text_samples_spec.rb[1:2:1] | passed | 0.01541 seconds | | ||
./spec/requests/text_samples_spec.rb[1:3:1] | passed | 0.01303 seconds | | ||
./spec/requests/text_samples_spec.rb[1:4:1] | passed | 2.21 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:1] | passed | 0.00878 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:2] | failed | 0.00064 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:3] | passed | 0.00876 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:2:1] | passed | 0.016 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:2:2] | passed | 0.01428 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:1:1] | pending | 0.00949 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:1:2] | passed | 0.01169 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:2:1] | passed | 0.0159 seconds | | ||
./spec/requests/text_samples_spec.rb[1:7:1] | passed | 0.01494 seconds | | ||
./spec/requests/text_samples_spec.rb[1:7:2] | passed | 0.01152 seconds | | ||
example_id | status | run_time | | ||
----------------------------------------------------- | ------- | --------------- | | ||
./spec/helpers/text_samples_helper_spec.rb[1:1] | pending | 0.00003 seconds | | ||
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.00371 seconds | | ||
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.00463 seconds | | ||
./spec/models/text_sample_spec.rb[1:2:1:1] | passed | 0.03304 seconds | | ||
./spec/models/text_sample_spec.rb[1:2:1:2] | passed | 0.0036 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:1] | passed | 0.00654 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:2] | passed | 0.0232 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:3] | passed | 0.00385 seconds | | ||
./spec/models/word_chunk_spec.rb[1:1:4] | passed | 0.0031 seconds | | ||
./spec/requests/text_samples_spec.rb[1:1:1] | passed | 0.02365 seconds | | ||
./spec/requests/text_samples_spec.rb[1:2:1] | passed | 0.01393 seconds | | ||
./spec/requests/text_samples_spec.rb[1:3:1] | passed | 2.24 seconds | | ||
./spec/requests/text_samples_spec.rb[1:4:1] | passed | 0.03572 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:1] | passed | 0.00784 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:2] | failed | 0.01819 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:1:3] | passed | 0.00772 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:2:1] | passed | 0.01638 seconds | | ||
./spec/requests/text_samples_spec.rb[1:5:2:2] | passed | 0.01606 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:1:1] | pending | 0.01364 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:1:2] | passed | 0.01511 seconds | | ||
./spec/requests/text_samples_spec.rb[1:6:2:1] | passed | 0.04019 seconds | | ||
./spec/requests/text_samples_spec.rb[1:7:1] | passed | 0.01801 seconds | | ||
./spec/requests/text_samples_spec.rb[1:7:2] | passed | 0.01515 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:1] | passed | 0.00081 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:2] | passed | 0.00114 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:3] | passed | 0.00078 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:4] | passed | 0.00087 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:5] | passed | 0.00143 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:6] | passed | 0.00099 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:7] | passed | 0.0039 seconds | | ||
./spec/routing/text_samples_routing_spec.rb[1:1:8] | passed | 0.00101 seconds | | ||
./spec/views/text_samples/edit.html.erb_spec.rb[1:1] | passed | 0.00769 seconds | | ||
./spec/views/text_samples/index.html.erb_spec.rb[1:1] | passed | 0.01657 seconds | | ||
./spec/views/text_samples/new.html.erb_spec.rb[1:1] | passed | 0.02457 seconds | | ||
./spec/views/text_samples/show.html.erb_spec.rb[1:1] | passed | 0.01983 seconds | |
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
# This will guess the TextSample class | ||
FactoryBot.define do | ||
factory :text_sample_simple, class: TextSample do | ||
description { 'Simple' } | ||
text { 'The man in the mirror' } | ||
factory :text_sample_two_chars, class: TextSample do | ||
description { 'Two characters' } | ||
text { 'At' } | ||
end | ||
|
||
factory :text_sample_three_chars, class: TextSample do | ||
description { 'Three characters' } | ||
text { 'The' } | ||
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,14 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe TextSample, type: :model do | ||
RSpec.describe TextSample, type: :model do # rubocop:disable Metrics/BlockLength | ||
describe 'validations' do | ||
it { should validate_presence_of(:description) } | ||
it { should validate_presence_of(:text) } | ||
end | ||
|
||
# describe '::class_method' do | ||
describe '#build_word_chunks' do | ||
let(:text_sample){ create(:text_sample_simple) } | ||
it 'counts word chunks' | ||
it 'assigns the word chunks to this text sample' | ||
describe 'builds different sized chunks' do | ||
it 'handles 2 character chunks' do | ||
text_sample = create(:text_sample_two_chars) | ||
allow(text_sample).to receive(:build_word_chunks_of_size) | ||
text_sample.build_word_chunks | ||
|
||
expect(text_sample).to( | ||
have_received(:build_word_chunks_of_size).with(2).once | ||
) | ||
expect(text_sample).not_to( | ||
have_received(:build_word_chunks_of_size).with(3) | ||
) | ||
end | ||
|
||
it 'handles 3 character chunks' do | ||
text_sample = create(:text_sample_three_chars) | ||
allow(text_sample).to receive(:build_word_chunks_of_size) | ||
text_sample.build_word_chunks | ||
|
||
expect(text_sample).to( | ||
have_received(:build_word_chunks_of_size).with(2).once | ||
) | ||
expect(text_sample).to( | ||
have_received(:build_word_chunks_of_size).with(3).once | ||
) | ||
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
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,5 +1,3 @@ | ||
puts "ljksfdlkfjlkjsdlkfdklfj" | ||
|
||
RSpec.configure do |config| | ||
config.include FactoryBot::Syntax::Methods | ||
end | ||
end |