pah 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/.gitignore +17 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +55 -0
  6. data/Rakefile +1 -0
  7. data/bin/pah +4 -0
  8. data/lib/pah/README.md +53 -0
  9. data/lib/pah/build +17 -0
  10. data/lib/pah/files/.gitignore +17 -0
  11. data/lib/pah/files/.rvmrc +48 -0
  12. data/lib/pah/files/Gemfile +52 -0
  13. data/lib/pah/files/Procfile +1 -0
  14. data/lib/pah/files/app/assets/stylesheets/reset.css +40 -0
  15. data/lib/pah/files/app/controllers/admin/contents_controller.rb +2 -0
  16. data/lib/pah/files/app/helpers/typus_helper.rb +32 -0
  17. data/lib/pah/files/app/models/content.rb +27 -0
  18. data/lib/pah/files/app/views/admin/dashboard/_sidebar.html.erb +0 -0
  19. data/lib/pah/files/app/views/layouts/application.html.haml +68 -0
  20. data/lib/pah/files/config/database.yml +22 -0
  21. data/lib/pah/files/config/initializers/omniauth.rb +4 -0
  22. data/lib/pah/files/config/initializers/requires.rb +1 -0
  23. data/lib/pah/files/config/locales/pt-BR.app.yml +16 -0
  24. data/lib/pah/files/config/locales/pt-BR.content.yml +12 -0
  25. data/lib/pah/files/config/locales/pt-BR.typus.yml +15 -0
  26. data/lib/pah/files/config/locales/pt-BR.yml +207 -0
  27. data/lib/pah/files/config/typus/content.yml +8 -0
  28. data/lib/pah/files/config/typus/content_roles.yml +4 -0
  29. data/lib/pah/files/config/unicorn.rb +27 -0
  30. data/lib/pah/files/db/migrate/20120605205337_create_contents.rb +11 -0
  31. data/lib/pah/files/db/seeds.rb +10 -0
  32. data/lib/pah/files/lib/tasks/integration.rake +14 -0
  33. data/lib/pah/files/public/index.html +1 -0
  34. data/lib/pah/files/spec/acceptance/dummy_spec.rb +9 -0
  35. data/lib/pah/files/spec/controllers/admin/contents_controller_spec.rb +5 -0
  36. data/lib/pah/files/spec/factories/content.rb +8 -0
  37. data/lib/pah/files/spec/helpers/typus_helper_spec.rb +71 -0
  38. data/lib/pah/files/spec/models/content_spec.rb +64 -0
  39. data/lib/pah/files/spec/spec_helper.rb +47 -0
  40. data/lib/pah/files/spec/support/README +1 -0
  41. data/lib/pah/files/spec/support/acceptance_helpers.rb +26 -0
  42. data/lib/pah/files/spec/support/acceptance_macros.rb +16 -0
  43. data/lib/pah/files/spec/support/capybara.rb +8 -0
  44. data/lib/pah/files/spec/support/deferred_garbage_collection.rb +35 -0
  45. data/lib/pah/files/spec/support/http_basic_auth.rb +26 -0
  46. data/lib/pah/files/spec/support/matchers.rb +5 -0
  47. data/lib/pah/files/spec/support/omniauth.rb +27 -0
  48. data/lib/pah/files/spec/support/paperclip.rb +4 -0
  49. data/lib/pah/files/spec/support/shared_connection.rb +12 -0
  50. data/lib/pah/files/spec/support/suppress_log.rb +5 -0
  51. data/lib/pah/files/spec/support/uploaded_file.rb +19 -0
  52. data/lib/pah/files/spec/support/vcr.rb +7 -0
  53. data/lib/pah/partials/_canonical_host.rb +14 -0
  54. data/lib/pah/partials/_capybara.rb +11 -0
  55. data/lib/pah/partials/_cleanup.rb +20 -0
  56. data/lib/pah/partials/_database.rb +6 -0
  57. data/lib/pah/partials/_default.rb +26 -0
  58. data/lib/pah/partials/_finish.rb +8 -0
  59. data/lib/pah/partials/_gems.rb +7 -0
  60. data/lib/pah/partials/_generators.rb +37 -0
  61. data/lib/pah/partials/_git.rb +7 -0
  62. data/lib/pah/partials/_heroku.rb +51 -0
  63. data/lib/pah/partials/_omniauth.rb +13 -0
  64. data/lib/pah/partials/_rspec.rb +13 -0
  65. data/lib/pah/partials/_rvm.rb +43 -0
  66. data/lib/pah/partials/_secure_headers.rb +12 -0
  67. data/lib/pah/setup.rb +17 -0
  68. data/lib/pah/template.rb +91 -0
  69. data/lib/pah/version.rb +3 -0
  70. data/pah.gemspec +27 -0
  71. metadata +205 -0
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Content do
4
+ it { should allow_mass_assignment_of(:text).as(:admin) }
5
+ [:name, :slug, :text].each do |attribute|
6
+ it { should validate_presence_of(attribute) }
7
+ end
8
+ describe ".markdown" do
9
+ context "content exists" do
10
+ before do
11
+ Factory.create(:content)
12
+ end
13
+ it "should return markdown of text of content with slug" do
14
+ Content.markdown(:tagline).should == "<p>Texto <strong>legal</strong> e <em>bacana</em></p>\n"
15
+ end
16
+ end
17
+ context "content does not exists" do
18
+ it "should return nil" do
19
+ Content.markdown(:tagline).should be_nil
20
+ end
21
+ end
22
+ end
23
+ describe ".raw" do
24
+ context "content exists" do
25
+ before do
26
+ Factory.create(:content)
27
+ end
28
+ it "should return raw text of content with slug" do
29
+ Content.raw(:tagline).should == "Texto **legal** e <em>bacana</em>"
30
+ end
31
+ end
32
+ context "content does not exists" do
33
+ it "should return nil" do
34
+ Content.raw(:tagline).should be_nil
35
+ end
36
+ end
37
+ end
38
+ describe ".ensure" do
39
+ context "content does not exists" do
40
+ it "should create content" do
41
+ expect {
42
+ Content.ensure(:tagline, 'Tagline', 'Texto legal')
43
+ }.to change(Content, :count).by(1)
44
+ end
45
+ describe "created content" do
46
+ before do
47
+ Content.ensure(:tagline, 'Tagline', 'Texto legal')
48
+ end
49
+ subject { Content.last }
50
+ its(:slug) { should == 'tagline' }
51
+ its(:name) { should == 'Tagline' }
52
+ its(:text) { should == 'Texto legal' }
53
+ end
54
+ end
55
+ context "content already exists" do
56
+ let!(:content) { Factory.create(:content) }
57
+ it "should not create content" do
58
+ expect {
59
+ Content.ensure(:tagline, 'Tagline 1', 'Texto legal 1')
60
+ }.not_to change(Content, :count)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,47 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+
3
+ if ENV['coverage'] == 'on'
4
+ require 'simplecov'
5
+ SimpleCov.start 'rails'
6
+ end
7
+
8
+ ENV["RAILS_ENV"] ||= 'test'
9
+ require File.expand_path("../../config/environment", __FILE__)
10
+ require 'rspec/rails'
11
+ require 'rspec/autorun'
12
+ require 'valid_attribute'
13
+ require "email_spec"
14
+
15
+ # Requires supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
18
+
19
+ RSpec.configure do |config|
20
+ # ## Mock Framework
21
+ #
22
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
23
+ #
24
+ # config.mock_with :mocha
25
+ # config.mock_with :flexmock
26
+ # config.mock_with :rr
27
+
28
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
29
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
30
+
31
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
32
+ # examples within a transaction, remove the following line or assign false
33
+ # instead of true.
34
+ config.use_transactional_fixtures = true
35
+
36
+ config.order = "random"
37
+ config.render_views
38
+ config.treat_symbols_as_metadata_keys_with_true_values = true
39
+ config.include FactoryGirl::Syntax::Methods
40
+ config.include EmailSpec::Helpers
41
+ config.include EmailSpec::Matchers
42
+
43
+ # If true, the base class of anonymous controllers will be inferred
44
+ # automatically. This will be the default behavior in future versions of
45
+ # rspec-rails.
46
+ config.infer_base_class_for_anonymous_controllers = false
47
+ end
@@ -0,0 +1 @@
1
+ ADD HERE SUPPORT FILES FOR OMNIAUTH, PAPERCLIP, CAPYBARA, ETC
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module AcceptanceHelpers
3
+ def saop
4
+ save_and_open_page
5
+ end
6
+ def handle_js_confirm(message = nil, accept = true)
7
+ page.execute_script("window.original_confirm_function = window.confirm")
8
+ page.execute_script("window.confirm = function(msg) { $.cookie('confirm_message', msg); return #{!!accept}; }")
9
+ yield
10
+ page.evaluate_script("$.cookie('confirm_message')").should == message unless message.nil?
11
+ ensure
12
+ page.evaluate_script "window.confirm = window.original_confirm_function"
13
+ end
14
+ def fill_in_autocomplete(capybara_selector, jquery_selector, value)
15
+ fill_in capybara_selector, :with => value
16
+ page.execute_script %Q{$('#{jquery_selector}').keydown()}
17
+ end
18
+ def choose_autocomplete(text)
19
+ find('ul.ui-autocomplete').should have_content(text)
20
+ page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()")
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.include AcceptanceHelpers, :type => :request
26
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module AcceptanceMacros
3
+ def login!
4
+ before(:each) do
5
+ @current_user = User.make(:email => 'x@example.com', :password => 'senha123', :password_confirmation => 'senha123')
6
+ visit new_user_session_path
7
+ fill_in 'Email', :with => 'x@example.com'
8
+ fill_in 'Senha', :with => 'senha123'
9
+ click_button 'Entrar'
10
+ end
11
+ end
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.extend AcceptanceMacros, :type => :request
16
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'capybara/rspec'
3
+ require 'capybara/rails'
4
+ require 'capybara/poltergeist'
5
+ Capybara.javascript_driver = :poltergeist
6
+ RSpec.configure do |config|
7
+ config.include Capybara::DSL, :example_group => { :file_path => /\bspec\/acceptance\// }
8
+ end
@@ -0,0 +1,35 @@
1
+ # Joe Van Dyk discovered that running the Ruby garbage collector only every X seconds can speed up your tests.
2
+ # I found that deferring garbage collection would speed up my RSpec examples by about 15%,
3
+ # but it probably depends on the nature of your tests.
4
+ # https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
5
+
6
+ class DeferredGarbageCollection
7
+ RESERVED_IVARS = %w(@loaded_fixtures)
8
+ DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f
9
+ @@last_gc_run = Time.now
10
+ def self.start
11
+ GC.disable if DEFERRED_GC_THRESHOLD > 0
12
+ end
13
+ def self.reconsider
14
+ if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
15
+ GC.enable
16
+ GC.start
17
+ GC.disable
18
+ @@last_gc_run = Time.now
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.before(:all) do
25
+ DeferredGarbageCollection.start
26
+ end
27
+ config.after(:each) do
28
+ (instance_variables - DeferredGarbageCollection::RESERVED_IVARS).each do |ivar|
29
+ instance_variable_set(ivar, nil)
30
+ end
31
+ end
32
+ config.after(:all) do
33
+ DeferredGarbageCollection.reconsider
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module AuthSpec
2
+ def http_basic_login!
3
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('usuario','senha')
4
+ end
5
+ end
6
+
7
+ module CapybaraAuthSpec
8
+ def http_basic_login!
9
+ name = 'usuario'
10
+ password = 'senha'
11
+ if page.driver.respond_to?(:basic_auth)
12
+ page.driver.basic_auth(name, password)
13
+ elsif page.driver.respond_to?(:basic_authorize)
14
+ page.driver.basic_authorize(name, password)
15
+ elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize)
16
+ page.driver.browser.basic_authorize(name, password)
17
+ else
18
+ raise "I don't know how to log in!"
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.include AuthSpec, type: :controller
25
+ config.include CapybaraAuthSpec, type: :request
26
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_bad_request do
2
+ match do |response|
3
+ response.code.to_s =~ /^4/
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module OmniauthLoginTestHelper
3
+ def current_user
4
+ @current_user ||= Factory.create(:user)
5
+ end
6
+
7
+ def login!
8
+ session[:user_id] = current_user.id
9
+ end
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.include OmniauthLoginTestHelper, :type => :controller
14
+ config.include OmniauthLoginTestHelper, :type => :helper
15
+ end
16
+
17
+ shared_examples_for "authentication_required_action" do
18
+ context "not logged in" do
19
+ before do
20
+ http_basic_login!
21
+ request.env["HTTP_REFERER"] = '/back'
22
+ do_action
23
+ end
24
+ it { should redirect_to("/back") }
25
+ it { flash[:notice].should == "Você precisa estar logado..." }
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ require "paperclip/matchers"
2
+ RSpec.configure do |config|
3
+ config.include Paperclip::Shoulda::Matchers
4
+ end
@@ -0,0 +1,12 @@
1
+ class ActiveRecord::Base
2
+ mattr_accessor :shared_connection
3
+ @@shared_connection = nil
4
+
5
+ def self.connection
6
+ @@shared_connection || retrieve_connection
7
+ end
8
+ end
9
+
10
+ # Forces all threads to share the same connection. This works on
11
+ # Capybara because it starts the web server in a thread.
12
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@@ -0,0 +1,5 @@
1
+ # Rails by default logs everything that is happening in your test environment to “log/test.log”.
2
+ # By increasing the logger level, you will be able to reduce the IO during your tests.
3
+ # The only downside of this approach is that, if a test is failing, you won’t have anything logged.
4
+ # In such cases, just comment the configuration option above and run your tests again.
5
+ Rails.logger.level = 4 unless ENV['WITH_LOG']
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module UploadFileTestHelper
3
+ def uploaded_file(filename, content_type = "text/csv")
4
+ t = Tempfile.new([filename.split("/").last, filename.split(".").last])
5
+ t.binmode
6
+ path = File.join(Rails.root, "spec", "fixtures", filename)
7
+ FileUtils.copy_file(path, t.path)
8
+ ActionDispatch::Http::UploadedFile.new({
9
+ filename: filename,
10
+ head: "Content-Disposition: form-data; name=\"file\"; filename=\"#{filename}\"\r\nContent-Type: #{content_type}\r\n",
11
+ type: content_type,
12
+ tempfile: t
13
+ })
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.include UploadFileTestHelper
19
+ end
@@ -0,0 +1,7 @@
1
+ # require 'vcr'
2
+ #
3
+ # VCR.configure do |c|
4
+ # c.allow_http_connections_when_no_cassette = true
5
+ # c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
6
+ # c.hook_into :webmock
7
+ # end
@@ -0,0 +1,14 @@
1
+ puts "Configuring canonical hosts... ".magenta
2
+ rack_canonical = <<CANONICAL
3
+
4
+ #Run heroku config:add CANONICAL_HOST=yourdomain.com
5
+ #For more information, see: https://github.com/tylerhunt/rack-canonical-host#usage
6
+ use Rack::CanonicalHost, ENV['CANONICAL_HOST'] if ENV['CANONICAL_HOST']
7
+ CANONICAL
8
+ in_root do
9
+ inject_into_file 'config.ru', rack_canonical, {after: "require ::File.expand_path('../config/environment', __FILE__)", verbose: false}
10
+ end
11
+ git :add => 'config.ru'
12
+ git :commit => "-qm 'Adding rack-canonical-host.'"
13
+
14
+ puts "\n"
@@ -0,0 +1,11 @@
1
+ puts "Adding capybara helpers...".magenta
2
+
3
+ copy_static_file 'spec/support/acceptance_helpers.rb'
4
+ copy_static_file 'spec/support/acceptance_macros.rb'
5
+ copy_static_file 'spec/support/capybara.rb'
6
+ copy_static_file 'spec/support/shared_connection.rb'
7
+ copy_static_file 'spec/acceptance/dummy_spec.rb'
8
+
9
+ git :add => '.'
10
+ git :commit => "-aqm 'Add capybara helpers.'"
11
+ puts "\n"
@@ -0,0 +1,20 @@
1
+ puts "Commiting new rails app ... ".magenta
2
+
3
+ git :add => '.'
4
+ git :commit => "-aqm 'Commit new rails app.'"
5
+
6
+ puts "Removing unnecessary files ... ".magenta
7
+
8
+ remove_file "README"
9
+ remove_file "app/views/layouts/application.html.erb"
10
+ remove_file "app/assets/images/rails.png"
11
+
12
+ inside "public" do
13
+ remove_file "index.html"
14
+ remove_file "favicon.ico"
15
+ remove_file "robots.txt"
16
+ end
17
+
18
+ git :add => '.'
19
+ git :commit => "-aqm 'Removed unnecessary files left over from initial app generation.'"
20
+ puts "\n"
@@ -0,0 +1,6 @@
1
+ copy_static_file 'config/database.yml'
2
+ gsub_file 'config/database.yml', /PROJECT/, @app_name
3
+ git :add => 'config/database.yml'
4
+ git :commit => "-qm 'Adding config/database.yml.'"
5
+
6
+ puts "\n"
@@ -0,0 +1,26 @@
1
+ puts "Adding default files ...".magenta
2
+
3
+ copy_static_file 'app/assets/stylesheets/reset.css'
4
+ copy_static_file 'app/views/layouts/application.html.haml'
5
+ copy_static_file 'config/unicorn.rb'
6
+ copy_static_file 'Procfile'
7
+ copy_static_file "config/initializers/requires.rb"
8
+ copy_static_file "lib/tasks/integration.rake"
9
+
10
+ copy_static_file 'config/locales/pt-BR.yml'
11
+ copy_static_file 'public/index.html' if ENV['RAILS_TEMPLATE_TEST'] == 'true'
12
+
13
+ gsub_file 'lib/tasks/integration.rake', /PROJECT/, @app_name
14
+
15
+ copy_static_file '.gitignore'
16
+
17
+ create_file ".env" do
18
+ <<-EOF
19
+ export PRODUCTION_APP=#{@app_name}
20
+ export STAGING_APP=#{@app_name}-staging
21
+ EOF
22
+ end
23
+
24
+ git :add => '.'
25
+ git :commit => "-aqm 'Add default stuff.'"
26
+ puts "\n"
@@ -0,0 +1,8 @@
1
+ in_root do
2
+ run "rake db:create db:migrate db:test:clone"
3
+ end
4
+
5
+ git :add => 'db/schema.rb'
6
+ git :commit => "-qm 'Create database, adding db/schema.rb.'"
7
+
8
+ puts "\n"
@@ -0,0 +1,7 @@
1
+ puts "Adding Gemfile... ".magenta
2
+
3
+ copy_static_file 'Gemfile'
4
+
5
+ git :add => 'Gemfile'
6
+ git :commit => "-qm 'Adding Gemfile.'"
7
+ puts "\n"
@@ -0,0 +1,37 @@
1
+ puts "Adding generators... ".magenta
2
+
3
+ generators = <<GENERATORS
4
+
5
+ # Do not generate specs for views and requests. Also, do not generate assets.
6
+ config.generators do |g|
7
+ g.helper false
8
+ g.view_specs false
9
+ g.assets false
10
+ g.integration_tool false
11
+ end
12
+ config.app_generators do |g|
13
+ g.test_framework :rspec
14
+ end
15
+
16
+ # Prevent initializing your application and connect to the database on assets precompile.
17
+ config.assets.initialize_on_precompile = false
18
+ GENERATORS
19
+
20
+ in_root do
21
+ inject_into_file 'config/application.rb', generators, {after: "Rails::Application", verbose: false}
22
+ end
23
+
24
+ git :add => 'config/application.rb'
25
+ git :commit => "-qm 'Adding generators.'"
26
+
27
+ letter_opener_config = <<LETTER_OPENER
28
+ config.action_mailer.delivery_method = :letter_opener
29
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
30
+ LETTER_OPENER
31
+
32
+ in_root do
33
+ inject_into_file 'config/environments/development.rb', letter_opener_config, { before: "end", verbose: false }
34
+ end
35
+
36
+ git :add => 'config/environments/development.rb'
37
+ git :commit => "-qm 'Adding letter_opener config.'"