Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
Fix loading of railties; add specs for Rails::Server detection
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jun 8, 2017
1 parent 2d8ecad commit 2156ff9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ Thanks to @sponomarev !
* Added support for checking [scoped](https://docs.npmjs.com/misc/scope) npm modules (Thanks to @psdcoder !)

* npmdc now starts only with `rails server` when using Rails (Thanks to @iskvmk !)

### 0.5.1

* Fix bug with server detection (always include Railtie in Rails)
2 changes: 1 addition & 1 deletion lib/npmdc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def configure
end
end

require "npmdc/railtie" if defined?(Rails::Server)
require "npmdc/railtie" if defined?(Rails)
end
3 changes: 2 additions & 1 deletion lib/npmdc/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Railtie < Rails::Railtie # :nodoc:
end

initializer "npmdc.environment_check" do
next unless defined?(Rails::Server)
unless config.npmdc.environments.include?(Rails.env)
abort <<-END.strip_heredoc
Npmdc is trying to be activated in the #{Rails.env} environment.
Expand All @@ -27,7 +28,7 @@ class Railtie < Rails::Railtie # :nodoc:
end

initializer "npmdc.call" do
Npmdc.call
Npmdc.call if defined?(Rails::Server)
end
end
end
2 changes: 1 addition & 1 deletion lib/npmdc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Npmdc
VERSION = '0.5.0'
VERSION = '0.5.1'
end
70 changes: 49 additions & 21 deletions spec/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,71 @@ def within_new_app(root = File.expand_path('../dummy', __FILE__))
)
end

it "aborts initialization" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }
context "when Rails::Server is not defined" do
it "is skipped" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }
expect(Rails).not_to receive(:env)
initializer.run(app)
end
end
end

expect_any_instance_of(described_class).to receive(:abort)
context "when Rails::Server is defined" do
before { stub_const("Rails::Server", double) }

initializer.run(app)
it "aborts initialization" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }

expect_any_instance_of(described_class).to receive(:abort)

initializer.run(app)
end
end
end

it "allows initialization" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }
it "allows initialization" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }

expect_any_instance_of(described_class).not_to receive(:abort)
expect_any_instance_of(described_class).not_to receive(:abort)

allow(app.config.npmdc).to receive(:environments).and_return(%w(test))
allow(app.config.npmdc).to receive(:environments).and_return(%w(test))

initializer.run(app)
initializer.run(app)
end
end
end
end

context "call" do
let(:name) { 'npmdc.call'}

it "shows input" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }
context "when Rails::Server is not defined" do
it "is skipped" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }
expect(Npmdc).not_to receive(:call)
initializer.run(app)
end
end
end

context "when Rails::Server is defined" do
before { stub_const("Rails::Server", double) }

it "shows output" do
within_new_app do |app|
initializer = app.initializers.find { |i| i.name == name }

output_msg = <<-output.strip_heredoc
Checking dependencies:
✗ foo
✗ bar
output
output_msg = <<-output.strip_heredoc
Checking dependencies:
✗ foo
✗ bar
output

expect { initializer.run(app) }.to write_output(output_msg)
expect { initializer.run(app) }.to write_output(output_msg)
end
end
end
end
Expand Down

0 comments on commit 2156ff9

Please sign in to comment.