Fix tests for Localizer (#689)

* Fix tests for Localizer

* Fix spec/unit/inspection_multiple_spec.rb

* Fix spec/unit/state_spec.rb

* Remove spec/en_deprecated_style.yml

* restrict codecov version to "< 0.1.20"
This commit is contained in:
Nikolay Markov 2020-08-05 17:57:12 +03:00 committed by GitHub
parent 6690ed5b54
commit 23210e8f31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 33 deletions

View File

@ -4,9 +4,6 @@ en:
localizer_test_model:
close: "Let's close it!"
attributes:
localizer_test_model:
aasm_state/opened: "It's open now!"
errors:
messages:
record_invalid: "Invalid record"

View File

@ -1,9 +1,5 @@
en:
activerecord:
events:
localizer_test_model:
close: "Let's close it!"
attributes:
localizer_test_model:
aasm_state:

View File

@ -0,0 +1,5 @@
en:
activerecord:
attributes:
localizer_test_model:
aasm_state/opened: "It's open now!"

View File

@ -11,13 +11,13 @@ end
describe 'localized state names' do
before(:all) do
I18n.load_path << 'spec/en.yml'
I18n.default_locale = :en
I18n.load_path << 'spec/localizer_test_model_new_style.yml'
I18n.reload!
end
after(:all) do
I18n.load_path.clear
I18n.load_path.delete('spec/localizer_test_model_new_style.yml')
I18n.backend.load_translations
end
it 'should localize' do

View File

@ -13,6 +13,7 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
require 'aasm'
require 'rspec'
require 'aasm/rspec'
require 'i18n'
require 'pry'
# require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
@ -34,3 +35,7 @@ Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require Fi
# example model classes
Dir[File.dirname(__FILE__) + "/models/*.rb"].sort.each { |f| require File.expand_path(f) }
I18n.load_path << 'spec/en.yml'
I18n.enforce_available_locales = false
I18n.default_locale = :en

View File

@ -166,11 +166,15 @@ describe "special cases" do
end
describe 'aasm.states_for_select' do
it "should return a select friendly array of states" do
expect(FooMultiple.aasm(:left)).to respond_to(:states_for_select)
expect(FooMultiple.aasm(:left).states_for_select).to eq(
[['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']]
)
context 'without I18n' do
before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
it "should return a select friendly array of states" do
expect(FooMultiple.aasm(:left)).to respond_to(:states_for_select)
expect(FooMultiple.aasm(:left).states_for_select).to eq(
[['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']]
)
end
end
end

View File

@ -102,9 +102,13 @@ describe "special cases" do
end
describe 'aasm.states_for_select' do
it "should return a select friendly array of states" do
expect(Foo.aasm).to respond_to(:states_for_select)
expect(Foo.aasm.states_for_select).to eq([['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']])
context 'without I18n' do
before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
it "should return a select friendly array of states" do
expect(Foo.aasm).to respond_to(:states_for_select)
expect(Foo.aasm.states_for_select).to eq([['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']])
end
end
end

View File

@ -1,20 +1,18 @@
require 'spec_helper'
if defined?(ActiceRecord)
require 'i18n'
I18n.enforce_available_locales = false
if defined?(ActiveRecord)
require 'models/active_record/localizer_test_model'
load_schema
describe AASM::Localizer, "new style" do
before(:all) do
I18n.load_path << 'spec/en.yml'
I18n.default_locale = :en
I18n.load_path << 'spec/localizer_test_model_new_style.yml'
I18n.reload!
end
after(:all) do
I18n.load_path.clear
I18n.load_path.delete('spec/localizer_test_model_new_style.yml')
I18n.backend.load_translations
end
let (:foo_opened) { LocalizerTestModel.new }
@ -43,13 +41,14 @@ if defined?(ActiceRecord)
describe AASM::Localizer, "deprecated style" do
before(:all) do
I18n.load_path << 'spec/en_deprecated_style.yml'
I18n.default_locale = :en
I18n.load_path << 'spec/localizer_test_model_deprecated_style.yml'
I18n.reload!
I18n.backend.load_translations
end
after(:all) do
I18n.load_path.clear
I18n.load_path.delete('spec/localizer_test_model_deprecated_style.yml')
I18n.backend.load_translations
end
let (:foo_opened) { LocalizerTestModel.new }

View File

@ -17,12 +17,28 @@ describe AASM::Core::State do
expect(state.name).to eq(:astate)
end
it 'should set the display_name from name' do
expect(new_state.display_name).to eq('Astate')
end
describe '#display_name' do
subject(:display_name) { new_state(options).display_name }
it 'should set the display_name from options' do
expect(new_state(:display => "A State").display_name).to eq('A State')
context 'without options' do
let(:options) { {} }
context 'without I18n' do
before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
it 'should set the display_name from name' do
expect(display_name).to eq('Astate')
end
end
end
context 'with :display option' do
let(:options) { { display: "A State" } }
it 'should set the display_name from options' do
expect(display_name).to eq('A State')
end
end
end
it 'should set the options and expose them as options' do