Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application id suffix command #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/replicant/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
require_relative "commands/package_command"
require_relative "commands/reset_command"
require_relative "commands/restart_command"
require_relative "commands/suffix_command"
19 changes: 19 additions & 0 deletions lib/replicant/commands/suffix_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SuffixCommand < Command

def description
"set an application id suffix"
end

def usage
"#{name} .development"
end

def valid_args?
args.present? && /^\.\w+(\.\w+)*$/ =~ args
end

def run
output "Setting application id suffix to \"#{@repl.default_package+args}\""
@repl.default_package += args
end
end
39 changes: 39 additions & 0 deletions test/commands/suffix_command_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'helper'

class SuffixCommandSpec < CommandSpecBase

describe "with valid arguments" do
it "accepts a suffix with one element" do
@repl.default_package = 'myapp'
command = silent SuffixCommand.new(@repl, ".debug")
command.execute
@repl.default_package.must_equal "myapp.debug"
end

it "accepts a package with two elements" do
@repl.default_package = 'myapp'
command = silent SuffixCommand.new(@repl, ".debug.me")
command.execute
@repl.default_package.must_equal "myapp.debug.me"
end
end

describe "with invalid arguments" do
it "refuses a suffix not starting with a dot" do
@repl.default_package = 'myapp'
command = silent SuffixCommand.new(@repl, 'debug')
command.expects(:run).never
command.execute
@repl.default_package.must_equal 'myapp'
end

it "refuses a suffix containing non-alphanumeric characters" do
@repl.default_package = 'myapp'
command = silent PackageCommand.new(@repl, ".myapp.some$thing")
command.expects(:run).never
command.execute
@repl.default_package.must_equal 'myapp'
end
end
end