-
Notifications
You must be signed in to change notification settings - Fork 51
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 #51 from elbartostrikesagain/humanizer_helper_class
Adds a helper class as an alternative way to use the gem if users don…
- Loading branch information
Showing
8 changed files
with
135 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby ${{ matrix.ruby-version }} | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true | ||
|
||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Run tests | ||
run: bundle exec rspec |
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
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,4 @@ | ||
# encoding: UTF-8 | ||
require File.expand_path("../lib/humanizer/version", __FILE__) | ||
|
||
Gem::Specification.new do |s| | ||
|
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,3 +1,3 @@ | ||
module Humanizer | ||
VERSION = "2.7.0" | ||
VERSION = "2.7.1" | ||
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,17 @@ | ||
class HumanizerHelper | ||
include ActiveModel::Validations | ||
include Humanizer | ||
|
||
def initialize(options={}) | ||
options[:humanizer_question_id] = options[:humanizer_question_id].to_i unless options[:humanizer_question_id].nil? | ||
options.each do |k, v| | ||
self.send("#{k}=", v) | ||
end | ||
|
||
humanizer_question_id | ||
end | ||
|
||
def get_correct_humanizer_answer | ||
humanizer_answers_for_id(humanizer_question_id.to_i)[0] | ||
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,38 @@ | ||
require 'spec_helper' | ||
require 'humanizer_helper' | ||
|
||
describe HumanizerHelper do | ||
|
||
context "initialized with variables" do | ||
let(:incorrect_humanizer_answer) {"this is a wrong answer"} | ||
let(:humanizer_question_id) {1} | ||
let(:humanize_helper) {HumanizerHelper.new(humanizer_answer: incorrect_humanizer_answer, humanizer_question_id: humanizer_question_id.to_s)} | ||
|
||
it "works as a placeholder class to humanizer using the variables passed in" do | ||
expect(humanize_helper.humanizer_answer).to eq(incorrect_humanizer_answer) | ||
expect(humanize_helper.humanizer_question_id).to eq(humanizer_question_id) | ||
expect(humanize_helper.humanizer_correct_answer?).to be_falsey | ||
expect(humanize_helper.humanizer_question).to eq('Jack and Jill went up the...') | ||
|
||
expect(humanize_helper.get_correct_humanizer_answer).to eq('hill') | ||
humanize_helper.humanizer_answer = "hill" | ||
expect(humanize_helper.humanizer_correct_answer?).to be true | ||
|
||
humanize_helper.change_humanizer_question(humanizer_question_id) | ||
expect(humanize_helper.humanizer_question_id).to_not eq(humanizer_question_id) | ||
end | ||
end | ||
|
||
context "initialized without variables" do | ||
let(:humanize_helper) {HumanizerHelper.new} | ||
|
||
it "works as a placeholder class to humanizer" do | ||
expect(humanize_helper.humanizer_answer).to be_nil | ||
expect(humanize_helper.humanizer_question_id).to be_present | ||
expect(humanize_helper.humanizer_correct_answer?).to be_falsey | ||
|
||
humanize_helper.humanizer_answer = humanize_helper.get_correct_humanizer_answer | ||
expect(humanize_helper.humanizer_correct_answer?).to be true | ||
end | ||
end | ||
end |