Permalink
Browse files

added auth routes and specs

  • Loading branch information...
1 parent f73cf97 commit cc3633a6a0f28cc5e0e0e8f0bc8dfdc78f295c32 @mattetti committed Nov 15, 2008
@@ -7,7 +7,7 @@ def authenticate_articles_route
<<-RUBY
authenticate do
#{sentinel}
-end
+ end
RUBY
end
end
@@ -2,31 +2,69 @@ module Step
def authenticated_articles_route_spec
- spec_file = "#{path}/spec/requests/articles_spec.rb"
- print " > editing requests spec #{spec_file}\n"
- old_given = <<RUBY
- given "a article exists" do
- Article.all.destroy!
- request(resource(:articles), :method => "POST",
- :params => { :article => { :id => nil }})
+ spec_file = "#{path}/spec/requests/articles_spec.rb"
+ print " > editing requests spec #{spec_file}\n"
+ old_given = <<-RUBY
+ given "a article exists" do
+ Article.all.destroy!
+ request(resource(:articles), :method => "POST",
+ :params => { :article => { :id => nil }})
+ end
+ RUBY
+
+ gsub_file spec_file, /(^given.*?end)/mi do |match|
+ <<-RUBY
+given "a article exists" do
+ Article.all.destroy!
+ User.all.detroy!
+ u = User.new(:login => "mattetti")
+ u.password = u.password_confirmation = "sekrit"
+ u.save
+ request("/login", :method => "put", :params => {"login" => "mattetti", "password" => "sekrit"})
+ request(resource(:articles), :method => "POST",
+ :params => { :article => {:title => 'intro', :author => 'Matt', :created_at => '2008-11-07 10:07:12' }})
+end
+ RUBY
+ end
+
+ add_login_spec_helpers
end
-RUBY
+
+ def add_login_spec_helpers
+ test_helpers = <<-RUBY
- gsub_file spec_file, /(#{Regexp.escape(old_given)})/mi do |match|
- <<-RUBY
- given "a article exists" do
- Article.all.destroy!
- User.all.detroy!
- u = User.new(:login => "mattetti")
- u.password = u.password_confirmation = "sekrit"
- u.save
- request("/login", :method => "put", :params => {"login" => "mattetti", "password" => "sekrit"})
- request(resource(:articles), :method => "POST",
- :params => { :article => {:title => 'intro', :author => 'Matt', :created_at => '2008-11-07 10:07:12' }})
- end
- RUBY
- end
+Merb::Test.add_helpers do
+
+ def create_default_user
+ if User.first(:login => "krusty").nil?
+ request(resource(:users), {
+ :method => "POST",
+ :params => {
+ :user => {
+ :login => "krusty",
+ :password => "klown",
+ :password_confirmation => "klown"
+ }
+ }
+ })
+ end
+ end
+
+ def login
+ @response = request("/login", {
+ :method => "PUT",
+ :params => {
+ :login => "krusty",
+ :password => "klown"
+ }
+ })
+ end
+
+end
+
+ RUBY
+ append_to_file("#{path}/spec/spec_helper.rb", "#{test_helpers}")
end
end
@@ -46,6 +46,34 @@ module Step
File.open(path, 'wb') { |file| file.write(content) }
end
+ # inserts some code at the top a file
+ def prepend_to_file(path, text_to_add)
+ add_content_to_file(path, text_to_add, :top)
+ end
+
+ # inserts some code at the bottom of a file
+ def append_to_file(path, text_to_add)
+ add_content_to_file(path, text_to_add, :bottom)
+ end
+
+ # Adds content to a file
+ # params:
+ # path: to the file to edit
+ # text_to_add: I bet you can figure this one on your own
+ # position: symbol or string, choose between :top and :bottom
+ #
+ def add_content_to_file(path, text_to_add, position)
+ case position.to_s
+ when "top"
+ content = text_to_add + File.read(path)
+ when "bottom"
+ content = File.read(path) + text_to_add
+ else
+ raise "Please specify the position to insert your content (:top or :bottom)"
+ end
+ File.open(path, 'wb') { |file| file.write(content) }
+ end
+
# initiate a local git repo
#
def git_init
@@ -81,12 +109,20 @@ module Step
end
+
+
+############################################################################################################
+#
+# => APP Generators
+#
+############################################################################################################
+
class App < Thor
include Step
- desc "generate APP_NAME", "generate a test app"
- def generate(app_name='my-first-app')
+ desc "generate APP_NAME bundling", "generate a test app, the second param sets bundling testing or not"
+ def generate(app_name='my-first-app', bundling=false)
Step.app_name = app_name
load_steps('shared-steps')
load_steps('steps')
@@ -102,12 +138,13 @@ class App < Thor
step :edit_index_view
step :make_specs_not_pending
step :edit_layout
- # step :authenticate_articles_route
- # step :run_app_specs
- # step :authenticated_articles_route_spec
- # step :run_app_specs
- step :bundling_merb
- step :run_bundled_app_specs
+ step :authenticate_articles_route
+ step :authenticated_articles_route_spec
+ step :run_app_specs
+ if bundling
+ step :bundling_merb
+ step :run_bundled_app_specs
+ end
end
desc "generate_very_flat APP_NAME", "generate a very flat test app"

0 comments on commit cc3633a

Please sign in to comment.