Skip to content

Commit

Permalink
Merge pull request #4 from arkbot/semi_breaking_changes_and_updates
Browse files Browse the repository at this point in the history
Might break some things.
  • Loading branch information
aeberlin committed Feb 22, 2016
2 parents e15689a + eef5555 commit 12b9053
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 99 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.2.4
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: ruby

bundler_args: '--with=development --jobs=3 --retry=3 --verbose'

rvm:
- 2.2.4

sudo: false

cache:
bundler: true

git:
depth: 15

notifications:
email: false

script: bundle exec rspec spec/

matrix:
fast_finish: true
2 changes: 1 addition & 1 deletion config/locales/en-US.yml → config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

en-US:
en:
development:
lorem_ipsum_1: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce id lobortis tortor. Nam cursus pharetra purus non elementum. Sed eu libero leo. Aliquam eget justo vel odio consectetur facilisis id a sapien. Duis pulvinar tincidunt suscipit. Quisque volutpat justo vitae fringilla lacinia. Aenean semper, nulla at mattis sagittis, purus felis aliquet lorem, sit amet suscipit dolor elit nec tellus. Pellentesque interdum nulla maximus massa elementum, at posuere augue scelerisque.
lorem_ipsum_2: Nulla sagittis quam at est tincidunt, at consectetur leo vehicula. Vestibulum et faucibus odio. Vivamus interdum consectetur metus vitae aliquam. Integer vitae felis diam. Vestibulum consectetur dictum magna eget finibus. Integer sit amet interdum augue. Nullam ultricies malesuada odio, at tincidunt nisi semper nec. Pellentesque vitae convallis ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut vitae risus blandit, sodales nulla at, placerat dui.
Expand Down
2 changes: 1 addition & 1 deletion flash_messenger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.0.0'

spec.add_dependency 'rails', '>= 4.0'
spec.add_dependency 'rails', '~> 4.2'
spec.add_dependency 'activesupport', '>= 4.0'

spec.add_development_dependency 'factory_girl'
Expand Down
6 changes: 0 additions & 6 deletions lib/flash_messenger.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
require 'flash_messenger/engine'
require 'flash_messenger/controller_injection'

module FlashMessenger
Rails.configuration.tap do |c|
DEFAULT_LOCALE = c.flash_messenger.default_locale || c.i18n.default_locale || :'en-US'
end
end
11 changes: 11 additions & 0 deletions lib/flash_messenger/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,16 @@ class Engine < ::Rails::Engine
g.assets false
g.helper false
end

initializer 'flash_messenger.default_locale' do |app|
app.config.tap do |c|
default_locale = \
c.try(:flash_messenger).try(:default_locale) ||
c.try(:i18n).try(:default_locale) ||
:en

::FlashMessenger::DEFAULT_LOCALE = default_locale
end
end
end
end
8 changes: 5 additions & 3 deletions lib/flash_messenger/messages/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ def eql?(other)
end

def match?(other)
if other.is_a?(Base)
if other.is_a?(self.class)
us = "#{self.class_name}, #{self.level}, #{self.message}"
them = "#{self.class_name}, #{self.level}, #{self.message}"
us =~ them
return us =~ them
elsif other.is_a?(String)
self.to_s =~ other
return self.to_s =~ %r(#{other})
end

nil
end

alias_method :match, :match?
alias_method :==, :eql?

#
Expand Down
2 changes: 1 addition & 1 deletion lib/flash_messenger/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FlashMessenger
VERSION = '0.0.2'
VERSION = '0.1.0'
end
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Application < Rails::Application

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.default_locale = :en
end
end
4 changes: 4 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test:
<<: *default
database: db/test.sqlite3

travis:
<<: *default
database: ':memory:'

production:
<<: *default
database: db/production.sqlite3
2 changes: 1 addition & 1 deletion spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
config.eager_load = false

# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'

# Show full error reports and disable caching.
Expand Down
27 changes: 0 additions & 27 deletions spec/examples/shared_examples.rb

This file was deleted.

56 changes: 0 additions & 56 deletions spec/features/messages/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,5 @@
require 'rails_helper'

RSpec.shared_examples 'a helper which yields message of kind' do |klass, target, *args|
let(:klazz) { public_send(klass) }

let(:instance) do
subject.public_send(target, *(args.map { |i| public_send(i) }))
end

it_behaves_like 'a message instance of kind', :klazz, :instance
end

RSpec.shared_examples 'a message instance of kind' do |klass, target|
let(:kind) { public_send(klass) }
let(:victim) { public_send(target) }

it "returns an instance of #{klass}" do
expect(victim).to be_a(kind)
end

context '#serialization' do
it 'serializes and deserializes properly' do
expect(victim.to_session).to be_a(String)

another_victim = victim.class.from_session(victim.to_session)

expect(another_victim).to eq(victim)
end
end

# Note: inherits default_message from calling context
context '#message' do
it 'has the expected message' do
expect(victim.message).to eq(default_message)
end
end

context '#eql?' do
it 'equals another message instance with the same string' do
another_victim = victim.dup
expect(another_victim).to eq(victim)
expect(another_victim.__id__).not_to eq(victim.__id__)
end
end

context '#match?' do
it 'matches the string value' do
expect(victim).to match(victim.message)
end
end

context '#type?' do
it 'exposes its type helper properly' do
expect(victim.public_send("#{victim.level}?")).to be_truthy
end
end
end

RSpec.describe FlashMessenger::Messages::Base do
subject { FlashMessenger::Messages::Base }

Expand Down
2 changes: 1 addition & 1 deletion spec/features/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

let(:expected_json) do
{
"locale" => "en-US",
"locale" => "en",
"messages" => [
{
"i18n_params" => { "raise" => true },
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

require 'i18n'
I18n.load_path = Dir['config/locales/**/*.yml']
I18n.default_locale = :'en-US'
I18n.default_locale = :en

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
Expand Down
56 changes: 56 additions & 0 deletions spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,59 @@
expect(result).to eq(expected)
end
end

RSpec.shared_examples 'a helper which yields message of kind' do |klass, target, *args|
let(:klazz) { public_send(klass) }

let(:instance) do
subject.public_send(target, *(args.map { |i| public_send(i) }))
end

it_behaves_like 'a message instance of kind', :klazz, :instance
end

RSpec.shared_examples 'a message instance of kind' do |klass, target|
let(:kind) { public_send(klass) }
let(:victim) { public_send(target) }

it "returns an instance of #{klass}" do
expect(victim).to be_a(kind)
end

context '#serialization' do
it 'serializes and deserializes properly' do
expect(victim.to_session).to be_a(String)

another_victim = victim.class.from_session(victim.to_session)

expect(another_victim).to eq(victim)
end
end

# Note: inherits default_message from calling context
context '#message' do
it 'has the expected message' do
expect(victim.message).to eq(default_message)
end
end

context '#eql?' do
it 'equals another message instance with the same string' do
another_victim = victim.dup
expect(another_victim).to eq(victim)
expect(another_victim.__id__).not_to eq(victim.__id__)
end
end

context '#match?' do
it 'matches the string value' do
expect(victim).to match(victim.message)
end
end

context '#type?' do
it 'exposes its type helper properly' do
expect(victim.public_send("#{victim.level}?")).to be_truthy
end
end
end

0 comments on commit 12b9053

Please sign in to comment.