nesta 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -11
  3. data/.hound.yml +2 -0
  4. data/.travis.yml +2 -1
  5. data/CHANGES +43 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +18 -23
  8. data/lib/nesta/app.rb +0 -5
  9. data/lib/nesta/commands.rb +5 -288
  10. data/lib/nesta/commands/command.rb +58 -0
  11. data/lib/nesta/commands/demo.rb +1 -0
  12. data/lib/nesta/commands/demo/content.rb +38 -0
  13. data/lib/nesta/commands/edit.rb +21 -0
  14. data/lib/nesta/commands/new.rb +57 -0
  15. data/lib/nesta/commands/plugin.rb +1 -0
  16. data/lib/nesta/commands/plugin/create.rb +82 -0
  17. data/lib/nesta/commands/theme.rb +3 -0
  18. data/lib/nesta/commands/theme/create.rb +36 -0
  19. data/lib/nesta/commands/theme/enable.rb +22 -0
  20. data/lib/nesta/commands/theme/install.rb +29 -0
  21. data/lib/nesta/config.rb +1 -6
  22. data/lib/nesta/models.rb +18 -20
  23. data/lib/nesta/version.rb +1 -1
  24. data/nesta.gemspec +1 -0
  25. data/smoke-test.sh +24 -19
  26. data/spec/commands/demo/content_spec.rb +65 -0
  27. data/spec/commands/edit_spec.rb +27 -0
  28. data/spec/commands/new_spec.rb +88 -0
  29. data/spec/commands/plugin/create_spec.rb +97 -0
  30. data/spec/commands/system_spec.rb +25 -0
  31. data/spec/commands/theme/create_spec.rb +41 -0
  32. data/spec/commands/theme/enable_spec.rb +44 -0
  33. data/spec/commands/theme/install_spec.rb +56 -0
  34. data/spec/config_spec.rb +3 -3
  35. data/spec/models_spec.rb +43 -25
  36. data/spec/page_spec.rb +18 -2
  37. data/spec/spec_helper.rb +23 -0
  38. data/templates/Gemfile +1 -1
  39. data/templates/plugins/Gemfile +4 -0
  40. data/templates/plugins/README.md +13 -0
  41. data/templates/plugins/Rakefile +58 -0
  42. data/templates/plugins/gitignore +3 -0
  43. data/templates/plugins/lib/init.rb +13 -0
  44. data/templates/plugins/lib/required.rb +3 -0
  45. data/templates/plugins/lib/version.rb +5 -0
  46. data/templates/plugins/plugin.gemspec +28 -0
  47. data/views/analytics.haml +9 -10
  48. data/views/master.sass +1 -1
  49. metadata +53 -5
  50. data/spec/commands_spec.rb +0 -395
@@ -1,3 +1,3 @@
1
1
  module Nesta
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
@@ -32,6 +32,7 @@ EOF
32
32
  s.require_paths = ["lib"]
33
33
 
34
34
  s.add_dependency('haml', '>= 3.1')
35
+ s.add_dependency('haml-contrib', '>= 1.0')
35
36
  s.add_dependency('sass', '>= 3.1')
36
37
  s.add_dependency('rdiscount', '~> 2.1')
37
38
  s.add_dependency('RedCloth', '~> 4.2')
@@ -5,10 +5,12 @@
5
5
  # Ruby.
6
6
  #
7
7
  # It assumes you've got the relevant versions of Ruby installed locally
8
- # via rbenv.
8
+ # via chruby.
9
9
 
10
10
 
11
- RUBIES="1.9.3-p392 2.0.0-p353 2.1.0 2.1.1"
11
+ source /usr/local/opt/chruby/share/chruby/chruby.sh
12
+
13
+ RUBIES="ruby-2.0.0-p598 ruby-2.1.5 ruby-2.2.1"
12
14
 
13
15
 
14
16
  ## Functions
@@ -36,27 +38,32 @@ gem_file()
36
38
  echo "nesta-$(nesta_version).gem"
37
39
  }
38
40
 
41
+ run_with_ruby()
42
+ {
43
+ chruby-exec $RUBY_VERSION -- $@
44
+ }
45
+
39
46
  get_ruby()
40
47
  {
41
- # Why not just use RUBY_VERSION? Because tmux can prevent rbenv from
42
- # changing the local version if the RBENV_VERSION variable is set in
43
- # another session. If we don't notice we'll think we've been testing
44
- # Nesta under multiple versions, but in fact we'll just have been
45
- # testing it under the same copy of Ruby every time.
46
- ruby --version | cut -f 2 -d ' '
48
+ # Why not just use RUBY_VERSION? Because tmux can prevent child
49
+ # processes from changing the local version if the RBENV_VERSION
50
+ # variable is set in another session. If we don't notice we'll think
51
+ # we've been testing Nesta under multiple versions, but in fact
52
+ # we'll just have been testing it under the same copy of Ruby every
53
+ # time.
54
+ run_with_ruby ruby --version | cut -f 2 -d ' '
47
55
  }
48
56
 
49
57
  run_tests()
50
58
  {
51
- bundle install
52
- bundle exec rake spec
59
+ run_with_ruby bundle install
60
+ run_with_ruby bundle exec rake spec
53
61
  }
54
62
 
55
63
  build_and_install()
56
64
  {
57
65
  echo rm -f pkg/$(gem_file)
58
- bundle install
59
- bundle exec rake install
66
+ run_with_ruby bundle exec rake install
60
67
  }
61
68
 
62
69
  site_folder()
@@ -66,15 +73,14 @@ site_folder()
66
73
 
67
74
  create_and_test_new_site()
68
75
  {
69
- bundle exec nesta new $(site_folder)
76
+ run_with_ruby bundle exec nesta new $(site_folder)
70
77
  cd $(site_folder)
71
- echo "gem 'haml-contrib'" >> Gemfile
72
- bundle install
73
- bundle exec nesta demo:content
78
+ run_with_ruby bundle install
79
+ run_with_ruby bundle exec nesta demo:content
74
80
 
75
81
  log "Starting server in $(site_folder)"
76
82
  set +e
77
- bundle exec mr-sparkle
83
+ run_with_ruby bundle exec mr-sparkle
78
84
  set -e
79
85
 
80
86
  cd - >/dev/null
@@ -85,10 +91,9 @@ create_and_test_new_site()
85
91
  ## Main program
86
92
 
87
93
  set -e
88
- [ -n "$DEBUG" ] && set -x
94
+ [ "$DEBUG" ] && set -x
89
95
 
90
96
  for RUBY_VERSION in $RUBIES; do
91
- rbenv local $RUBY_VERSION
92
97
  log "Rebuilding nesta gem with Ruby $(get_ruby)"
93
98
 
94
99
  run_tests
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ describe "nesta:demo:content" do
5
+ include_context "temporary working directory"
6
+
7
+ before(:each) do
8
+ @config_path = project_path('config/config.yml')
9
+ FileUtils.mkdir_p(File.dirname(@config_path))
10
+ Nesta::Config.stub(:yaml_path).and_return(@config_path)
11
+ create_config_yaml('content: path/to/content')
12
+ Nesta::App.stub(:root).and_return(@project_path)
13
+ @repo_url = 'git://github.com/gma/nesta-demo-content.git'
14
+ @demo_path = project_path('content-demo')
15
+ @command = Nesta::Commands::Demo::Content.new
16
+ @command.stub(:run_process)
17
+ end
18
+
19
+ it "should clone the repository" do
20
+ @command.should_receive(:run_process).with(
21
+ 'git', 'clone', @repo_url, @demo_path)
22
+ @command.execute
23
+ end
24
+
25
+ it "should configure the content directory" do
26
+ @command.execute
27
+ File.read(@config_path).should match(/^content: content-demo/)
28
+ end
29
+
30
+ describe "when repository already exists" do
31
+ before(:each) do
32
+ FileUtils.mkdir_p(@demo_path)
33
+ end
34
+
35
+ it "should update the repository" do
36
+ @command.should_receive(:run_process).with(
37
+ 'git', 'pull', 'origin', 'master')
38
+ @command.execute
39
+ end
40
+ end
41
+
42
+ describe "when site versioned with git" do
43
+ before(:each) do
44
+ @exclude_path = project_path('.git/info/exclude')
45
+ FileUtils.mkdir_p(File.dirname(@exclude_path))
46
+ File.open(@exclude_path, 'w') { |file| file.puts '# Excludes' }
47
+ end
48
+
49
+ it "should tell git to ignore content-demo" do
50
+ @command.execute
51
+ File.read(@exclude_path).should match(/content-demo/)
52
+ end
53
+
54
+ describe "and content-demo already ignored" do
55
+ before(:each) do
56
+ File.open(@exclude_path, 'w') { |file| file.puts 'content-demo' }
57
+ end
58
+
59
+ it "shouldn't tell git to ignore it twice" do
60
+ @command.execute
61
+ File.read(@exclude_path).scan('content-demo').size.should == 1
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ describe "nesta:edit" do
5
+ include_context "temporary working directory"
6
+
7
+ before(:each) do
8
+ Nesta::Config.stub(:content_path).and_return('content')
9
+ @page_path = 'path/to/page.mdown'
10
+ @command = Nesta::Commands::Edit.new(@page_path)
11
+ @command.stub(:run_process)
12
+ end
13
+
14
+ it "should launch the editor" do
15
+ ENV['EDITOR'] = 'vi'
16
+ full_path = File.join('content/pages', @page_path)
17
+ @command.should_receive(:run_process).with(ENV['EDITOR'], full_path)
18
+ @command.execute
19
+ end
20
+
21
+ it "should not try and launch an editor if environment not setup" do
22
+ ENV.delete('EDITOR')
23
+ @command.should_not_receive(:run_process)
24
+ $stderr.stub(:puts)
25
+ @command.execute
26
+ end
27
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ describe "nesta:new" do
5
+ include_context "temporary working directory"
6
+
7
+ def gemfile_source
8
+ File.read(project_path('Gemfile'))
9
+ end
10
+
11
+ def rakefile_source
12
+ File.read(project_path('Rakefile'))
13
+ end
14
+
15
+ describe "without options" do
16
+ before(:each) do
17
+ Nesta::Commands::New.new(@project_path).execute
18
+ end
19
+
20
+ it "should create the content directories" do
21
+ should_exist('content/attachments')
22
+ should_exist('content/pages')
23
+ end
24
+
25
+ it "should create the home page" do
26
+ should_exist('content/pages/index.haml')
27
+ end
28
+
29
+ it "should create the rackup file" do
30
+ should_exist('config.ru')
31
+ end
32
+
33
+ it "should create the config.yml file" do
34
+ should_exist('config/config.yml')
35
+ end
36
+
37
+ it "should add a Gemfile" do
38
+ should_exist('Gemfile')
39
+ gemfile_source.should match(/gem 'nesta'/)
40
+ end
41
+ end
42
+
43
+ describe "--git" do
44
+ before(:each) do
45
+ @command = Nesta::Commands::New.new(@project_path, 'git' => '')
46
+ @command.stub(:run_process)
47
+ end
48
+
49
+ it "should create a .gitignore file" do
50
+ @command.execute
51
+ File.read(project_path('.gitignore')).should match(/\.bundle/)
52
+ end
53
+
54
+ it "should create a git repo" do
55
+ @command.should_receive(:run_process).with('git', 'init')
56
+ @command.execute
57
+ end
58
+
59
+ it "should commit the blank project" do
60
+ @command.should_receive(:run_process).with('git', 'add', '.')
61
+ @command.should_receive(:run_process).with(
62
+ 'git', 'commit', '-m', 'Initial commit')
63
+ @command.execute
64
+ end
65
+ end
66
+
67
+ describe "--vlad" do
68
+ before(:each) do
69
+ Nesta::Commands::New.new(@project_path, 'vlad' => '').execute
70
+ end
71
+
72
+ it "should add vlad to Gemfile" do
73
+ gemfile_source.should match(/gem 'vlad', '2.1.0'/)
74
+ gemfile_source.should match(/gem 'vlad-git', '2.2.0'/)
75
+ end
76
+
77
+ it "should configure the vlad rake tasks" do
78
+ should_exist('Rakefile')
79
+ rakefile_source.should match(/require 'vlad'/)
80
+ end
81
+
82
+ it "should create deploy.rb" do
83
+ should_exist('config/deploy.rb')
84
+ deploy_source = File.read(project_path('config/deploy.rb'))
85
+ deploy_source.should match(/set :application, 'mysite.com'/)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ describe 'nesta:plugin:create' do
5
+ include_context 'temporary working directory'
6
+
7
+ def path_in_gem(path)
8
+ File.join(@gem_name, path)
9
+ end
10
+
11
+ def should_exist(path)
12
+ File.exist?(path_in_gem(path)).should be_true
13
+ end
14
+
15
+ def should_contain(path, pattern)
16
+ contents = File.read(path_in_gem(path))
17
+ contents.should match(pattern)
18
+ end
19
+
20
+ before(:each) do
21
+ @name = 'my-feature'
22
+ @gem_name = "nesta-plugin-#{@name}"
23
+ @plugins_path = temp_path('plugins')
24
+ @working_dir = Dir.pwd
25
+ Dir.mkdir(@plugins_path)
26
+ Dir.chdir(@plugins_path)
27
+ Nesta::Commands::Plugin::Create.any_instance.stub(:system)
28
+ Nesta::Commands::Plugin::Create.new(@name).execute
29
+ end
30
+
31
+ after(:each) do
32
+ Dir.chdir(@working_dir)
33
+ FileUtils.rm_r(@plugins_path)
34
+ end
35
+
36
+ it "creates the gem's directory" do
37
+ File.directory?(@gem_name).should be_true
38
+ end
39
+
40
+ it 'creates a README.md file with installation instructions' do
41
+ should_exist('README.md')
42
+ should_contain('README.md', %r{echo 'gem "#{@gem_name}"' >> Gemfile})
43
+ end
44
+
45
+ it 'creates .gitignore' do
46
+ should_exist('.gitignore')
47
+ end
48
+
49
+ it 'creates the gemspec' do
50
+ path = "#{@gem_name}.gemspec"
51
+ should_exist(path)
52
+ should_contain(path, %r{require "#{@gem_name}/version"})
53
+ should_contain(path, %r{Nesta::Plugin::My::Feature::VERSION})
54
+ end
55
+
56
+ it 'creates a Gemfile' do
57
+ should_exist('Gemfile')
58
+ end
59
+
60
+ it 'creates Rakefile that helps with packaging the gem' do
61
+ should_exist("Rakefile")
62
+ end
63
+
64
+ it 'creates default folder for Ruby files' do
65
+ code_directory = File.join(@gem_name, 'lib', @gem_name)
66
+ File.directory?(code_directory).should be_true
67
+ end
68
+
69
+ it 'creates file required when gem loaded' do
70
+ path = "#{File.join('lib', @gem_name)}.rb"
71
+ should_exist(path)
72
+ should_contain(path, %r{require "#{@gem_name}/version"})
73
+ end
74
+
75
+ it 'creates version.rb' do
76
+ path = File.join('lib', @gem_name, 'version.rb')
77
+ should_exist(path)
78
+ should_contain path, <<-EOF
79
+ module Nesta
80
+ module Plugin
81
+ module My
82
+ module Feature
83
+ VERSION = '0.1.0'
84
+ end
85
+ end
86
+ end
87
+ end
88
+ EOF
89
+ end
90
+
91
+ it 'creates skeleton code for the plugin in init.rb' do
92
+ path = File.join('lib', @gem_name, 'init.rb')
93
+ should_exist(path)
94
+ should_contain(path, "module Nesta\n module Plugin\n module My::Feature")
95
+ should_contain(path, 'helpers Nesta::Plugin::My::Feature::Helpers')
96
+ end
97
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ class TestCommand
5
+ include Nesta::Commands::Command
6
+ end
7
+
8
+ describe "Nesta::Commands::Command.run_process" do
9
+ before do
10
+ @stderr = $stderr
11
+ $stderr = File.new('/dev/null', 'w')
12
+ end
13
+
14
+ after do
15
+ $stderr.close
16
+ $stderr = @stderr
17
+ end
18
+
19
+ it 'can run an external process and catch errors' do
20
+ TestCommand.new.run_process('ls / >/dev/null')
21
+ expect {
22
+ TestCommand.new.run_process('ls /no-such-file 2>/dev/null')
23
+ }.to raise_error(SystemExit)
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
+
4
+ describe "nesta:theme:create" do
5
+ include_context "temporary working directory"
6
+
7
+ def should_exist(file)
8
+ File.exist?(Nesta::Path.themes(@name, file)).should be_true
9
+ end
10
+
11
+ before(:each) do
12
+ Nesta::App.stub(:root).and_return(TempFileHelper::TEMP_DIR)
13
+ @name = 'my-new-theme'
14
+ Nesta::Commands::Theme::Create.new(@name).execute
15
+ end
16
+
17
+ it "should create the theme directory" do
18
+ File.directory?(Nesta::Path.themes(@name)).should be_true
19
+ end
20
+
21
+ it "should create a dummy README file" do
22
+ should_exist('README.md')
23
+ text = File.read(Nesta::Path.themes(@name, 'README.md'))
24
+ text.should match(/#{@name} is a theme/)
25
+ end
26
+
27
+ it "should create a default app.rb file" do
28
+ should_exist('app.rb')
29
+ end
30
+
31
+ it "should create public and views directories" do
32
+ should_exist("public/#{@name}")
33
+ should_exist('views')
34
+ end
35
+
36
+ it "should copy the default view templates into views" do
37
+ %w(layout.haml page.haml master.sass).each do |file|
38
+ should_exist("views/#{file}")
39
+ end
40
+ end
41
+ end