ruby-station 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,2 @@
1
1
  pkg
2
2
  tmp
3
- misc
data/Rakefile CHANGED
@@ -13,9 +13,10 @@ Jeweler::Tasks.new do |gemspec|
13
13
  gemspec.homepage = "http://github.com/yhara/#{PROJECT_NAME}"
14
14
  gemspec.description = gemspec.summary
15
15
  gemspec.authors = ["Yutaka HARA"]
16
- # gemspec.add_dependency('ramaze', '= 2009.06.12')
17
- # gemspec.add_dependency('dm-core')
18
- # gemspec.add_dependency('do_sqlite3')
16
+ gemspec.add_dependency('ramaze', '= 2009.07')
17
+ gemspec.add_dependency('dm-core')
18
+ gemspec.add_dependency('do_sqlite3')
19
+ gemspec.add_development_dependency('rspec', '= 1.2.8')
19
20
  end
20
21
 
21
22
  desc "install current source as gem"
data/bin/ruby-station CHANGED
@@ -6,14 +6,22 @@ require 'ramaze'
6
6
 
7
7
  $LOAD_PATH.unshift __DIR__("../")
8
8
 
9
- require 'util/gem-manager.rb'
9
+ require 'util/gem_manager.rb'
10
10
  require 'config.rb'
11
- Conf.parse_opt
11
+ if defined?(TESTS_DIR)
12
+ Conf.set_home(TESTS_DIR/"data/conf_dir/")
13
+ else
14
+ Conf.parse_opt
15
+ end
12
16
  Conf.init
13
17
 
18
+ require 'util/servant.rb'
14
19
  require 'controller/init'
15
20
  require 'model/init'
16
21
 
22
+ if Conf.debug
23
+ Ramaze::Log.info "Starting Ramaze with dev mode"
24
+ end
17
25
  Ramaze.start :port => Conf.server_port,
18
26
  :root => __DIR__("../"),
19
- :mode => :live
27
+ :mode => (Conf.debug ? :dev : :live)
data/config.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require __DIR__("./util/gem_manager")
1
2
  require 'yaml'
2
3
  require 'fileutils'
3
4
 
@@ -9,7 +10,7 @@ module RubyStation
9
10
  end
10
11
 
11
12
  class Conf
12
- %w(ruby_command gem_command gem_dir gem_bin_dir gem_install_option data_dir server_port).each do |m|
13
+ %w(ruby_command gem_command gem_dir gem_bin_dir gem_install_option data_dir server_port debug).each do |m|
13
14
  class_eval <<-EOD
14
15
  def self.#{m}; @yaml[:#{m}]; end
15
16
  EOD
@@ -34,6 +35,11 @@ class Conf
34
35
  @opt.parse!(ARGV)
35
36
  end
36
37
 
38
+ # for unit tests
39
+ def self.set_home(path)
40
+ @home = path
41
+ end
42
+
37
43
  def self.load_yaml
38
44
  yaml_path = File.join(@home, "config.yaml")
39
45
  unless File.exist?(yaml_path)
@@ -47,7 +53,8 @@ class Conf
47
53
  end
48
54
 
49
55
  # TODO: refactor X-(
50
- def self.init
56
+ def self.init(home=nil)
57
+ @home = home if home
51
58
  @yaml = self.load_yaml
52
59
  @yaml[:gem_dir] = File.expand_path(@yaml[:gem_dir], @home)
53
60
  @yaml[:gem_bin_dir] = File.expand_path(@yaml[:gem_bin_dir], @home)
@@ -56,15 +63,26 @@ class Conf
56
63
  FileUtils.makedirs(@yaml[:gem_bin_dir])
57
64
  FileUtils.makedirs(@yaml[:data_dir])
58
65
 
59
- runtime_ver = RubyStation::RUNTIME_VERSION
60
- unless GemManager.installed?("ruby-station-runtime", runtime_ver)
61
- gem_path = __DIR__("runtime/ruby-station-runtime-#{runtime_ver}.gem")
62
- GemManager.install_file(gem_path)
63
- end
66
+ Runtime.install unless Runtime.installed?
67
+
64
68
  # unless `#{self.gem_command} sources`.include?("github")
65
69
  # cmd = "#{self.gem_command} sources -a http://gems.github.com"
66
70
  # Ramaze::Log.info cmd
67
71
  # `#{cmd}`
68
72
  # end
69
73
  end
74
+
75
+ module Runtime
76
+ VERSION = RubyStation::RUNTIME_VERSION
77
+
78
+ def self.installed?
79
+ GemManager.installed?("ruby-station-runtime", VERSION)
80
+ end
81
+
82
+ def self.install
83
+ path = __DIR__("runtime/ruby-station-runtime-#{VERSION}.gem")
84
+ GemManager.install_file(path)
85
+ end
86
+
87
+ end
70
88
  end
@@ -1,33 +1,46 @@
1
+ require 'json'
2
+
1
3
  class Applications < Controller
2
4
  map '/applications'
5
+ provide :json, :type => "application/json" do |action, value|
6
+ value.to_json
7
+ end
3
8
 
4
9
  layout{|path, ext|
5
- "default" unless path =~ /\Ado_/
10
+ "default" unless path =~ /\A_/
6
11
  }
7
12
 
8
13
  def install
9
- if request["name"]
14
+ session[:source_type] = request["by"]
15
+
16
+ case session[:source_type]
17
+ when "name"
10
18
  @name = request["name"]
11
19
  session[:gemname] = @name
12
- else
20
+ session[:messages] = []
21
+ when "file"
13
22
  tempfile = request["gem"][:tempfile]
14
23
  @filename = request["gem"][:filename]
15
24
  @size = tempfile.size
16
25
  session[:tempfile] = tempfile
26
+ else
27
+ raise "unknown install source type: #{session[:source_type]}"
17
28
  end
18
29
  end
19
30
 
20
- def do_install
21
- if gemname = session[:gemname]
31
+ def _install
32
+ case session[:source_type]
33
+ when "name"
34
+ gemname = session[:gemname]
22
35
  result, name, version = GemManager.install_gem(gemname)
23
- elsif session[:tempfile]
36
+ when "file"
24
37
  path = session[:tempfile].path
25
38
  result, name, version = GemManager.install_file(path)
26
39
  else
27
- raise
40
+ raise "unknown install source type: #{session[:source_type]}"
28
41
  end
29
42
 
30
- unless Application.first(:name => name, :version => version)
43
+ if result and not Application.first(:name => name, :version => version)
31
44
  Application.create({
32
45
  :pid => nil,
33
46
  :port => 30000 + rand(9999),
@@ -40,26 +53,23 @@ class Applications < Controller
40
53
  h result
41
54
  end
42
55
 
43
- def create
44
- end
45
-
46
- def show(name)
47
- end
48
-
49
56
  def uninstall(id)
50
- app = Application.get(id)
51
- raise "application not found(id=#{id})" unless app
52
-
53
- @app = app
57
+ if app = Application.get(id)
58
+ @app = app
59
+ else
60
+ flash[:error] = "The application (id=#{id}) is already uninstalled."
61
+ redirect MainController.r(:notfound)
62
+ end
54
63
  end
55
64
 
56
- def do_uninstall(id)
57
- app = Application.get(id)
58
- raise "application not found(id=#{id})" unless app
59
-
60
- result = GemManager.uninstall(app.name, app.version)
61
- app.destroy
62
- result
65
+ def _uninstall(id)
66
+ if app = Application.get(id)
67
+ result = GemManager.uninstall(app.name, app.version)
68
+ app.destroy
69
+ result
70
+ else
71
+ ""
72
+ end
63
73
  end
64
74
 
65
75
  def start(id)
@@ -80,5 +90,4 @@ class Applications < Controller
80
90
 
81
91
  redirect_referer
82
92
  end
83
-
84
93
  end
data/controller/main.rb CHANGED
@@ -5,4 +5,11 @@ class MainController < Controller
5
5
  @applications = Application.all
6
6
  end
7
7
 
8
+ def notfound
9
+ # Note: workaround for ramaze 2009.07
10
+ # response.status = 404
11
+
12
+ @message = flash[:error] || "The page you requested is not found."
13
+ end
14
+
8
15
  end
data/model/application.rb CHANGED
@@ -1,8 +1,5 @@
1
- require 'ramaze/tool/bin'
2
-
3
1
  class Application
4
2
  include DataMapper::Resource
5
- include Ramaze::Tool::Bin::Helpers
6
3
 
7
4
  property :id, Serial
8
5
  property :pid, Integer
@@ -20,24 +17,17 @@ class Application
20
17
  "--data-dir", data_dir,
21
18
  ].join(" ")
22
19
 
23
- self.pid = fork {
24
- exec(cmd)
20
+ self.pid = Servant.watch(cmd){
21
+ stopped
25
22
  }
26
23
  self.save
27
24
  end
28
25
 
29
26
  def stop
30
- return unless self.pid
31
-
32
- Process.kill("INT", self.pid)
33
- if is_running?(self.pid)
34
- sleep 2
35
- Ramaze::Log.warn "Process #{self.pid} did not die, forcing it with -9"
36
- Process.kill(9, self.pid)
27
+ if self.pid
28
+ Servant.kill(self.pid)
29
+ stopped
37
30
  end
38
-
39
- self.pid = nil
40
- self.save
41
31
  end
42
32
 
43
33
  def full_name
@@ -46,6 +36,11 @@ class Application
46
36
 
47
37
  private
48
38
 
39
+ def stopped
40
+ self.pid = nil
41
+ self.save
42
+ end
43
+
49
44
  def script_path
50
45
  File.join(Conf.gem_dir, "gems",
51
46
  full_name, "main.rb")
data/ruby-station.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ruby-station}
5
- s.version = "0.0.4"
5
+ s.version = "0.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Yutaka HARA"]
9
- s.date = %q{2009-08-15}
9
+ s.date = %q{2009-10-02}
10
10
  s.default_executable = %q{ruby-station}
11
11
  s.description = %q{Create, Distribute, and Install Ruby applications easily}
12
12
  s.email = %q{yutaka.hara/at/gmail.com}
@@ -35,32 +35,55 @@ Gem::Specification.new do |s|
35
35
  "runtime/lib/ruby-station.rb",
36
36
  "runtime/lib/ruby-station/helper.rb",
37
37
  "runtime/lib/ruby-station/helper/rails.rb",
38
- "runtime/ruby-station-runtime-0.0.3.gem",
39
38
  "runtime/ruby-station-runtime-0.0.4.gem",
40
39
  "sample.config.yaml",
41
- "spec/main.rb",
42
- "util/gem-manager.rb",
40
+ "tests/README",
41
+ "tests/Rakefile",
42
+ "tests/data/conf_dir/config.yaml",
43
+ "tests/features/install_file.feature",
44
+ "tests/features/install_name.feature",
45
+ "tests/features/list.feature",
46
+ "tests/features/step_definitions/application_steps.rb",
47
+ "tests/features/step_definitions/curelity_steps.rb",
48
+ "tests/features/support/env.rb",
49
+ "tests/features/uninstall.feature",
50
+ "tests/features/upgrade.feature",
51
+ "tests/spec/gem_manager.rb",
52
+ "tests/test_helper.rb",
53
+ "util/gem_manager.rb",
54
+ "util/servant.rb",
43
55
  "view/applications/do_install.xhtml",
56
+ "view/applications/foo.xhtml",
44
57
  "view/applications/install.xhtml",
45
58
  "view/applications/uninstall.xhtml",
46
- "view/index.xhtml"
59
+ "view/index.xhtml",
60
+ "view/notfound.xhtml"
47
61
  ]
48
62
  s.homepage = %q{http://github.com/yhara/ruby-station}
49
63
  s.rdoc_options = ["--charset=UTF-8"]
50
64
  s.require_paths = ["lib"]
51
65
  s.rubygems_version = %q{1.3.5}
52
66
  s.summary = %q{Create, Distribute, and Install Ruby applications easily}
53
- s.test_files = [
54
- "spec/main.rb"
55
- ]
56
67
 
57
68
  if s.respond_to? :specification_version then
58
69
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
70
  s.specification_version = 3
60
71
 
61
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_runtime_dependency(%q<ramaze>, ["= 2009.07"])
74
+ s.add_runtime_dependency(%q<dm-core>, [">= 0"])
75
+ s.add_runtime_dependency(%q<do_sqlite3>, [">= 0"])
76
+ s.add_development_dependency(%q<rspec>, ["= 1.2.8"])
62
77
  else
78
+ s.add_dependency(%q<ramaze>, ["= 2009.07"])
79
+ s.add_dependency(%q<dm-core>, [">= 0"])
80
+ s.add_dependency(%q<do_sqlite3>, [">= 0"])
81
+ s.add_dependency(%q<rspec>, ["= 1.2.8"])
63
82
  end
64
83
  else
84
+ s.add_dependency(%q<ramaze>, ["= 2009.07"])
85
+ s.add_dependency(%q<dm-core>, [">= 0"])
86
+ s.add_dependency(%q<do_sqlite3>, [">= 0"])
87
+ s.add_dependency(%q<rspec>, ["= 1.2.8"])
65
88
  end
66
89
  end
data/sample.config.yaml CHANGED
@@ -2,6 +2,6 @@
2
2
  :gem_command: "gem"
3
3
  :gem_dir: "./gem_home"
4
4
  :gem_bin_dir: "./gem_bin"
5
- :gem_install_option: "--no-rdoc --no-ri"
5
+ :gem_install_option: "--no-rdoc --no-ri --verbose"
6
6
  :data_dir: "./data"
7
7
  :server_port: 2534
data/tests/README ADDED
@@ -0,0 +1,29 @@
1
+ Unit tests for RubyStation
2
+ ==========================
3
+
4
+ spec
5
+ ----
6
+
7
+ $ gem intall rspec
8
+
9
+ rspec spec/*
10
+
11
+
12
+ features
13
+ --------
14
+
15
+ 1. install cucumber:
16
+ $ gem install cucumber
17
+
18
+ 2. install jruby:
19
+ TODO
20
+
21
+ JRuby must be executable by 'jruby'.
22
+
23
+ 3. install culerity:
24
+ $ gem install langalex-culerity --source http://gems.github.com
25
+
26
+
27
+
28
+
29
+
data/tests/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = %w{--format pretty}
6
+ end
7
+
8
+ desc "run rspec"
9
+ task "spec" do
10
+ sh "spec spec/*.rb"
11
+ end
@@ -0,0 +1,7 @@
1
+ :ruby_command: "ruby"
2
+ :gem_command: "gem"
3
+ :gem_dir: "../../tmp/gem_home"
4
+ :gem_bin_dir: "../../tmp/gem_bin"
5
+ :gem_install_option: "--no-rdoc --no-ri --verbose"
6
+ :data_dir: "../../tmp/data"
7
+ :server_port: 25341
@@ -0,0 +1,14 @@
1
+ Feature: Install by file
2
+ In order to test new applications
3
+ As an application developer
4
+ I want to install a new gem file
5
+
6
+ Scenario: Install a gem by file
7
+ Given I do not have 'hello 0.2.0'
8
+ And I visit the index page
9
+ And I check 'by file'
10
+ And I fill in the path of 'data/hello/pkg/hello-0.2.0.gem' for 'gem'
11
+ When I press 'install'
12
+ And I wait while the spinner is shown
13
+ Then I should see 'Installing'
14
+ And I should have 'hello 0.2.0'
@@ -0,0 +1,13 @@
1
+ Feature: Install by name
2
+ In order to use new applications
3
+ As an application user
4
+ I want to install a new application
5
+
6
+ Scenario: Install a gem by name
7
+ Given I do not have 'hello-ruby-station 0.3.0'
8
+ And I visit the index page
9
+ And I fill in 'hello-ruby-station' for 'name'
10
+ When I press 'install'
11
+ And I wait while the spinner is shown
12
+ Then I should see 'Installing'
13
+ And I should have 'hello-ruby-station 0.3.0'
@@ -0,0 +1,11 @@
1
+ Feature: List
2
+ In order to know which application is installed
3
+ As an application user
4
+ I want to list my applications
5
+
6
+ Scenario: View the list of applications
7
+ Given I visit the index page
8
+ # And I fill in '50' for 'first'
9
+ # And I fill in '70' for 'second'
10
+ # When I press 'Add'
11
+ # Then I should see 'Answer: 120'
@@ -0,0 +1,26 @@
1
+ Given /^I have '(.*) (.*)'$/ do |name, version|
2
+ GemManager.installed?(name, version)
3
+ end
4
+
5
+ Given /^I do not have '(.*) (.*)'$/ do |name, version|
6
+ if GemManager.installed?(name, version)
7
+ GemManager.uninstall(name, version)
8
+ end
9
+ end
10
+
11
+ When /^I install '(.*) (.*)'$/ do |name, version|
12
+ pending
13
+ end
14
+
15
+ Then /^I should (?:still )?have '(.*) (.*)'$/ do |name, version|
16
+ GemManager.installed?(name, version).should be_true
17
+ end
18
+
19
+ Then /^I should not have '(.*) (.*)'$/ do |name, version|
20
+ GemManager.installed?(name, version).should be_false
21
+ end
22
+
23
+ Then /^data files of 'hello 0\.2\.0' is same as data files of 'hello 0\.1\.0'$/ do
24
+ pending
25
+ end
26
+
@@ -0,0 +1,117 @@
1
+ require 'tempfile'
2
+ require 'culerity'
3
+ require __DIR__('../../test_helper.rb')
4
+
5
+ Before do
6
+ # TODO: start ramaze app in 7001, in test environment
7
+ # unless $rails_server
8
+ # $rails_server = Culerity::run_rails
9
+ # sleep 5
10
+ # end
11
+
12
+ # invoke jruby eval server (communicate via pipe)
13
+ # the server has instances of Celerity::Browser
14
+ $server ||= Culerity::run_server
15
+
16
+ # get the viatual browser, running in the server
17
+ $browser = Culerity::RemoteBrowserProxy.new $server, {:browser => :firefox}
18
+
19
+ # is needed to open pages
20
+ @host = "http://localhost:#{Conf.server_port}"
21
+ end
22
+
23
+ at_exit do
24
+ $browser.exit if $browser
25
+ $server.exit_server if $server
26
+ # TODO: stop ramaze app
27
+ #Process.kill(6, $rails_server.pid.to_i) if $rails_server
28
+ end
29
+
30
+ When /I press '(.*)'/ do |value|
31
+ $browser.button(:value, value).click
32
+ assert_successful_response
33
+ end
34
+
35
+ When /I follow '(.*)'/ do |link|
36
+ $browser.link(:text, /#{link}/).click
37
+ assert_successful_response
38
+ end
39
+
40
+ When /I fill in '(.*)' for '(.*)'/ do |value, name|
41
+ $browser.text_field(:name, name).set(value)
42
+ end
43
+
44
+ When /I fill in the path of '(.*)' for '(.*)'/ do |file, name|
45
+ $browser.file_field(:name, name).set(TESTS_DIR/file)
46
+ end
47
+
48
+ When /I check '(.*)'/ do |field|
49
+ $browser.check_box(:id, find_label(field).for).set(true)
50
+ end
51
+
52
+ When /^I uncheck '(.*)'$/ do |field|
53
+ $browser.check_box(:id, find_label(field).for).set(false)
54
+ end
55
+
56
+ When /I select '(.*)' from '(.*)'/ do |value, field|
57
+ $browser.select_list(:id, find_label(field).for).select value
58
+ end
59
+
60
+ When /I choose '(.*)'/ do |field|
61
+ $browser.radio(:id, find_label(field).for).set(true)
62
+ end
63
+
64
+ When /I visit the (.+) page/ do |name|
65
+ path = case name
66
+ when 'index' then '/'
67
+ else raise "unknown page name: #{name}"
68
+ end
69
+ $browser.goto "#{@host}#{path}"
70
+ assert_successful_response
71
+ end
72
+
73
+ When /I wait while the spinner is shown/ do
74
+ $browser.wait_while(60 * 3){ # 3 minutes
75
+ $browser.image(:id, 'spinner').exist?
76
+ }
77
+ end
78
+
79
+ When /I wait for the AJAX call to finish/ do
80
+ $browser.wait
81
+ end
82
+
83
+ Then /I should see '(.*)'/ do |text|
84
+ # if we simply check for the browser.html content we don't find content that has been added dynamically, e.g. after an ajax call
85
+ div = $browser.div(:text, /#{text}/)
86
+ begin
87
+ div.html
88
+ rescue
89
+ #puts $browser.html
90
+ raise("div with '#{text}' not found")
91
+ end
92
+ end
93
+
94
+ Then /I should not see '(.*)'/ do |text|
95
+ div = $browser.div(:text, /#{text}/).html rescue nil
96
+ div.should be_nil
97
+ end
98
+
99
+ def find_label(text)
100
+ $browser.label :text, text
101
+ end
102
+
103
+ def assert_successful_response
104
+ status = $browser.page.web_response.status_code
105
+ if(status == 302 || status == 301)
106
+ location = $browser.page.web_response.get_response_header_value('Location')
107
+ puts "Being redirected to #{location}"
108
+ $browser.goto location
109
+ assert_successful_response
110
+ elsif status != 200
111
+ tmp = Tempfile.new 'culerity_results'
112
+ tmp << $browser.html
113
+ tmp.close
114
+ `open -a /Applications/Safari.app #{tmp.path}`
115
+ raise "Brower returned Response Code #{$browser.page.web_response.status_code}"
116
+ end
117
+ end
@@ -0,0 +1,33 @@
1
+ # See http://wiki.github.com/aslakhellesoy/cucumber/ramaze
2
+ # for more details about Ramaze with Cucumber
3
+
4
+ gem 'ramaze', '>= 2009.07'
5
+ gem 'rack-test', '>= 0.5.0'
6
+ gem 'webrat', '>= 0.5.3'
7
+
8
+ require 'ramaze'
9
+ Ramaze.options.started = true
10
+ require __DIR__("../../test_helper.rb")
11
+ load TESTS_DIR/"../bin/ruby-station"
12
+
13
+ require 'spec/expectations'
14
+ require 'rack/test'
15
+ require 'webrat'
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :rack
19
+ end
20
+
21
+ class MyWorld
22
+ include Rack::Test::Methods
23
+ include Webrat::Methods
24
+ include Webrat::Matchers
25
+
26
+ Webrat::Methods.delegate_to_session :response_code, :response_body
27
+
28
+ def app
29
+ Ramaze::middleware
30
+ end
31
+ end
32
+
33
+ World{MyWorld.new}
@@ -0,0 +1,13 @@
1
+ Feature: Uninstall
2
+ In order to clean my application list
3
+ As an application user
4
+ I want to uninstall an unused application
5
+
6
+ Scenario: Uninstall a gem
7
+ Given I visit the index page
8
+ When I press the uninstall link
9
+ # Given I visit the calculator page
10
+ # And I fill in '50' for 'first'
11
+ # And I fill in '70' for 'second'
12
+ # When I press 'Add'
13
+ # Then I should see 'Answer: 120'
@@ -0,0 +1,11 @@
1
+ Feature: Upgrade
2
+ In order to use new version of an application
3
+ As an application user
4
+ I want to install the new version
5
+
6
+ Scenario: Upgrade a gem
7
+ Given I have 'hello 0.1.0'
8
+ And I do not have 'hello 0.2.0'
9
+ When I install 'hello 0.2.0'
10
+ Then I should still have 'hello 0.1.0'
11
+ And data files of 'hello 0.2.0' is same as data files of 'hello 0.1.0'
@@ -0,0 +1,27 @@
1
+ require "#{File.dirname(__FILE__)}/../test_helper.rb"
2
+ require TESTS_DIR/"../util/gem_manager.rb"
3
+
4
+ # helpers
5
+
6
+ describe GemManager do
7
+ it "should install a gem via file" do
8
+ path = TESTS_DIR/"data/hello/pkg/hello-0.2.0.gem"
9
+ result, name, version = GemManager.install_file(path)
10
+
11
+ result.should be_instance_of(String)
12
+ name.should == "hello"
13
+ version.should == "0.2.0"
14
+
15
+ GemManager.installed?("hello", "0.2.0").should be_true
16
+ end
17
+
18
+ it "should install a gem via network" do
19
+ pending
20
+ end
21
+
22
+ it "should uninstall a gem" do
23
+ GemManager.uninstall("hello", "0.2.0")
24
+
25
+ GemManager.installed?("hello", "0.2.0").should be_false
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'fileutils'
2
+ require 'ramaze'
3
+ Ramaze.options.started = true
4
+
5
+ TESTS_DIR = __DIR__
6
+ def TESTS_DIR./(*paths)
7
+ File.expand_path(File.join(*paths), TESTS_DIR)
8
+ end
9
+
10
+ def clear_tmp(tmp_dir)
11
+ if File.exist?(tmp_dir)
12
+ puts "removing all files under #{tmp_dir}..."
13
+ puts "are you sure? [just push enter if so]"
14
+ if STDIN.gets.chomp.empty?
15
+ FileUtils.rm_r(tmp_dir)
16
+ else
17
+ raise "user chose not to clear the temporary directory"
18
+ end
19
+ else
20
+ Dir.mkdir(tmp_dir)
21
+ end
22
+ end
23
+
24
+ clear_tmp(TESTS_DIR/"tmp/")
25
+ require TESTS_DIR/"../config.rb"
26
+ Conf.init TESTS_DIR/"data/conf_dir"
27
+
@@ -53,7 +53,7 @@ module GemManager
53
53
  result = `#{cmd}`
54
54
 
55
55
  # make data dir
56
- raise unless result =~ /installed #{name}-(.*)/
56
+ raise "installation failed" unless result =~ /installed #{name}-(.*)/
57
57
  version = $1
58
58
  data_dir = File.join(Conf.data_dir, "#{name}-#{version}")
59
59
  unless File.directory?(data_dir)
data/util/servant.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'open3'
2
+ require 'ramaze/tool/bin'
3
+
4
+ # class Servant provides process invocations.
5
+ #
6
+ # @example
7
+ # pid = Servant.watch("some-app -p 12345"){
8
+ # # this block is called when app finishes
9
+ # }
10
+ #
11
+ # Servant.kill(pid) #=> stop the app immediately
12
+ #
13
+ # Servant.communicate("gem install foobar"){|line|
14
+ # # each line is yielded form process
15
+ # }
16
+ class Servant
17
+ extend Ramaze::Tool::Bin::Helpers # provides is_running?
18
+
19
+ def self.watch(cmd, args=[], &block)
20
+ begin
21
+ pid = Process.spawn(cmd, *args)
22
+ rescue SystemCallError
23
+ return nil
24
+ end
25
+
26
+ Thread.new{
27
+ Process.waitpid(pid)
28
+ block.call
29
+ }
30
+ return pid
31
+ end
32
+
33
+ def self.communicate(cmd, args=[])
34
+ command = cmd + args.map{|x| ' '+x}.join
35
+ Open3.popen3(command){|stdin, stdout, stderr|
36
+ stdin.close
37
+ while line = stdout.gets
38
+ yield line
39
+ end
40
+ while line = stderr.gets
41
+ yield line
42
+ end
43
+ }
44
+ end
45
+
46
+ def self.kill(pid)
47
+ Process.kill("INT", pid)
48
+
49
+ if is_running?(pid)
50
+ sleep 2
51
+ Ramaze::Log.warn "Process #{pid} did not die, forcing it with -9"
52
+ Process.kill(9, pid)
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,19 @@
1
+ <h3>foo</h3>
2
+ <div id="result">
3
+ waiting..
4
+ </div>
5
+ <script>
6
+ $(function(){
7
+ $.get("#{r :_foo_gen}");
8
+ var loop = function(){
9
+ $.getJSON("#{r '_foo_get.json'}", function(result){
10
+ console.debug(result[0], result[1]);
11
+ $("#result").append(result[1]);
12
+ if (!result[0]) {
13
+ setTimeout(loop, 2000);
14
+ }
15
+ });
16
+ };
17
+ loop();
18
+ });
19
+ </script>
@@ -1,6 +1,10 @@
1
1
  <div id="install">
2
2
  <h2>Installing application</h2>
3
3
 
4
+ <p>
5
+ This may take some minutes. Please be patient.
6
+ </p>
7
+
4
8
  <?r if @name ?>
5
9
  <p>Installing gem '#{@name}'...</p>
6
10
  <?r else ?>
@@ -8,7 +12,7 @@
8
12
  <?r end ?>
9
13
 
10
14
  <pre id="result">
11
- <img src='/spinner.gif'>
15
+ <img id="spinner" src='/spinner.gif'>
12
16
  </pre>
13
17
 
14
18
  <a href='/'>back</a>
@@ -16,6 +20,6 @@
16
20
 
17
21
  <script type="text/javascript">
18
22
  $(document).ready(function(){
19
- $("#result").load("#{r(:do_install)}");
23
+ $("#result").load("#{r(:_install)}");
20
24
  });
21
25
  </script>
@@ -1,5 +1,5 @@
1
1
  <div id="uninstall">
2
- <h2>アプリケーションの削除</h2>
2
+ <h2>Uninstall</h2>
3
3
 
4
4
  <p>uninstalling #{@app.full_name} ..</p>
5
5
 
@@ -12,6 +12,6 @@
12
12
 
13
13
  <script type="text/javascript">
14
14
  $(document).ready(function(){
15
- $("#result").load("#{r(:do_uninstall, @app.id)}");
15
+ $("#result").load("#{r(:_uninstall, @app.id)}");
16
16
  });
17
17
  </script>
data/view/index.xhtml CHANGED
@@ -45,35 +45,35 @@
45
45
  </div>
46
46
  <div id="new">
47
47
  <h2>Installing Applications</h2>
48
- <input type="radio" id="by_name_button" checked>
49
- <label for="by_name_button">by name</label>
50
- <input type="radio" id="by_file_button">
51
- <label for="by_file_button">by file</label>
48
+ <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
49
+ <input type="radio" name="by" value="name" id="by_name_button" checked>
50
+ <label for="by_name_button">by name</label>
51
+ <input type="radio" name="by" value="file" id="by_file_button">
52
+ <label for="by_file_button">by file</label>
52
53
 
53
- <div id="by_name">
54
- <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
54
+ <div id="by_name">
55
55
  <input type="text" name="name" size="30">
56
56
  <input type="submit" value="install">
57
- </form>
58
- </div>
57
+ </div>
59
58
 
60
- <div id="by_file" style="display: none;">
61
- <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
59
+ <div id="by_file" style="display: none;">
62
60
  <input type="file" name="gem" size="50">
63
61
  <input type="submit" value="install">
64
- </form>
65
- </div>
62
+ </div>
63
+ </form>
66
64
  </div>
67
65
 
68
66
  <script type="text/javascript">
69
67
  $(function(){
70
- $("#by_name_button").change(function(){
68
+ $("#by_name_button").click(function(){
71
69
  $("#by_name").show();
72
70
  $("#by_file").hide();
71
+ return true;
73
72
  });
74
- $("#by_file_button").change(function(){
73
+ $("#by_file_button").click(function(){
75
74
  $("#by_name").hide();
76
75
  $("#by_file").show();
76
+ return true;
77
77
  });
78
78
  });
79
79
  </script>
@@ -0,0 +1,3 @@
1
+ <div>
2
+ #{h @message}
3
+ </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-station
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka HARA
@@ -9,10 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-15 00:00:00 +09:00
12
+ date: 2009-10-02 00:00:00 +09:00
13
13
  default_executable: ruby-station
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ramaze
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: "2009.07"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: dm-core
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: do_sqlite3
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.8
54
+ version:
16
55
  description: Create, Distribute, and Install Ruby applications easily
17
56
  email: yutaka.hara/at/gmail.com
18
57
  executables:
@@ -45,15 +84,29 @@ files:
45
84
  - runtime/lib/ruby-station.rb
46
85
  - runtime/lib/ruby-station/helper.rb
47
86
  - runtime/lib/ruby-station/helper/rails.rb
48
- - runtime/ruby-station-runtime-0.0.3.gem
49
87
  - runtime/ruby-station-runtime-0.0.4.gem
50
88
  - sample.config.yaml
51
- - spec/main.rb
52
- - util/gem-manager.rb
89
+ - tests/README
90
+ - tests/Rakefile
91
+ - tests/data/conf_dir/config.yaml
92
+ - tests/features/install_file.feature
93
+ - tests/features/install_name.feature
94
+ - tests/features/list.feature
95
+ - tests/features/step_definitions/application_steps.rb
96
+ - tests/features/step_definitions/curelity_steps.rb
97
+ - tests/features/support/env.rb
98
+ - tests/features/uninstall.feature
99
+ - tests/features/upgrade.feature
100
+ - tests/spec/gem_manager.rb
101
+ - tests/test_helper.rb
102
+ - util/gem_manager.rb
103
+ - util/servant.rb
53
104
  - view/applications/do_install.xhtml
105
+ - view/applications/foo.xhtml
54
106
  - view/applications/install.xhtml
55
107
  - view/applications/uninstall.xhtml
56
108
  - view/index.xhtml
109
+ - view/notfound.xhtml
57
110
  has_rdoc: true
58
111
  homepage: http://github.com/yhara/ruby-station
59
112
  licenses: []
@@ -82,5 +135,5 @@ rubygems_version: 1.3.5
82
135
  signing_key:
83
136
  specification_version: 3
84
137
  summary: Create, Distribute, and Install Ruby applications easily
85
- test_files:
86
- - spec/main.rb
138
+ test_files: []
139
+
Binary file
data/spec/main.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'ramaze'
2
- require 'ramaze/spec/helper'
3
-
4
- require __DIR__('../start')
5
-
6
- describe MainController do
7
- behaves_like 'http', 'xpath'
8
- ramaze :view_root => __DIR__('../view'),
9
- :public_root => __DIR__('../public')
10
-
11
- it 'should show start page' do
12
- got = get('/')
13
- got.status.should == 200
14
- puts got.body
15
- got.at('//title').text.strip.should ==
16
- MainController.new.index
17
- end
18
-
19
- it 'should show /notemplate' do
20
- got = get('/notemplate')
21
- got.status.should == 200
22
- got.at('//div').text.strip.should ==
23
- MainController.new.notemplate
24
- end
25
- end