partial_path_customizer 0.1.0

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 (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +8 -0
  4. data/Appraisals +5 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +90 -0
  7. data/LICENSE +20 -0
  8. data/README.md +76 -0
  9. data/Rakefile +18 -0
  10. data/gemfiles/rails_3.2.gemfile +7 -0
  11. data/gemfiles/rails_4.0.gemfile +7 -0
  12. data/gemfiles/rails_4.1.gemfile +7 -0
  13. data/lib/partial_path_customizer.rb +5 -0
  14. data/lib/partial_path_customizer/partial_path_helper.rb +19 -0
  15. data/lib/partial_path_customizer/presenter.rb +34 -0
  16. data/lib/partial_path_customizer/railtie.rb +9 -0
  17. data/lib/partial_path_customizer/version.rb +3 -0
  18. data/lib/tasks/partial_path_customizer_tasks.rake +4 -0
  19. data/partial_path_customizer.gemspec +29 -0
  20. data/spec/dummy/.rspec +2 -0
  21. data/spec/dummy/README.rdoc +28 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/images/.keep +0 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  27. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  28. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  29. data/spec/dummy/app/mailers/.keep +0 -0
  30. data/spec/dummy/app/models/.keep +0 -0
  31. data/spec/dummy/app/models/concerns/.keep +0 -0
  32. data/spec/dummy/app/models/dealer.rb +2 -0
  33. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/spec/dummy/bin/bundle +3 -0
  35. data/spec/dummy/bin/rails +4 -0
  36. data/spec/dummy/bin/rake +4 -0
  37. data/spec/dummy/config.ru +4 -0
  38. data/spec/dummy/config/application.rb +31 -0
  39. data/spec/dummy/config/boot.rb +5 -0
  40. data/spec/dummy/config/database.yml +25 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/development.rb +37 -0
  43. data/spec/dummy/config/environments/production.rb +78 -0
  44. data/spec/dummy/config/environments/test.rb +39 -0
  45. data/spec/dummy/config/initializers/assets.rb +8 -0
  46. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  47. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/spec/dummy/config/initializers/inflections.rb +16 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  51. data/spec/dummy/config/initializers/session_store.rb +3 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +23 -0
  54. data/spec/dummy/config/routes.rb +56 -0
  55. data/spec/dummy/config/secrets.yml +22 -0
  56. data/spec/dummy/db/migrate/20141009025609_create_dealers.rb +9 -0
  57. data/spec/dummy/lib/assets/.keep +0 -0
  58. data/spec/dummy/log/.keep +0 -0
  59. data/spec/dummy/public/404.html +67 -0
  60. data/spec/dummy/public/422.html +67 -0
  61. data/spec/dummy/public/500.html +66 -0
  62. data/spec/dummy/public/favicon.ico +0 -0
  63. data/spec/helpers/partial_path_helper_spec.rb +37 -0
  64. data/spec/partial_path_customizer/presenter_spec.rb +82 -0
  65. data/spec/rails_helper.rb +55 -0
  66. data/spec/spec_helper.rb +85 -0
  67. metadata +240 -0
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: e3ad1d307f69d0d9992aa9fcc1a5a283d20667e831488ed96f1751e1bf4eb0b1198a620978f3644532775c55f6823afc9a261ed9a26715737a5f91b0e0914ea0
15
+
16
+ test:
17
+ secret_key_base: 51f80dda1417436539b8692a9f85674e389a401e0fd7992e171460892a3b6e29f68990f50afb6780d3a802ed37241ced8d2fa75092a8540534b2f016b1828087
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,9 @@
1
+ class CreateDealers < ActiveRecord::Migration
2
+ def change
3
+ create_table :dealers do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,37 @@
1
+ require 'rails_helper'
2
+
3
+ describe PartialPathCustomizer::PartialPathHelper, ".customize_partial_path" do
4
+ context "with a single object" do
5
+ it "returns an object whose #to_partial_path returns <model_name pluralized>/<partial_name>" do
6
+ seller = Dealer.new
7
+
8
+ wrapped_obj = helper.customize_partial_path seller, "seller_price_box_info"
9
+
10
+ expect(wrapped_obj.to_partial_path).to eq("dealers/seller_price_box_info")
11
+ end
12
+
13
+ it "returns an object whose #to_partial_path returns the result of the passed in callable" do
14
+ seller = Dealer.new name: "ACL"
15
+
16
+ wrapped_obj = helper.customize_partial_path seller, ->(model){"dealer/#{model.name}"}
17
+
18
+ expect(wrapped_obj.to_partial_path).to eq("dealer/ACL")
19
+ end
20
+ end
21
+
22
+ context "with a collection" do
23
+ it "returns collection of objects whose #to_partial_path returns <model_name pluralized>/<partial_name>" do
24
+ dealer = Dealer.new
25
+ bike = mock_model "Bike"
26
+ brand = mock_model "Brand"
27
+
28
+ collection = [dealer, bike, brand]
29
+
30
+ wrapped_collection = helper.customize_partial_path collection, "tile"
31
+
32
+ partial_paths = wrapped_collection.collect(&:to_partial_path)
33
+
34
+ expect(partial_paths).to eq(["dealers/tile", "bikes/tile", "brands/tile"])
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,82 @@
1
+ require 'rails_helper'
2
+
3
+ describe PartialPathCustomizer::Presenter do
4
+
5
+ describe "delegations" do
6
+ it "delegates undefined methods to object" do
7
+ business = mock_model("Business", name: "Animas Code Labs")
8
+
9
+ presenter = described_class.new business
10
+
11
+ expect(presenter.name).to eq("Animas Code Labs")
12
+ end
13
+ end
14
+
15
+ describe "#to_partial_path" do
16
+ it "defaults to the default #to_partial_path" do
17
+ business = mock_model("Business", name: "Fred", to_partial_path: "businesses/business")
18
+
19
+ presenter = described_class.new business
20
+
21
+ expect(presenter.to_partial_path).to eq(business.to_partial_path)
22
+ end
23
+
24
+ it "generates a partial_path based on the block passed in" do
25
+ business_contact = mock_model("BusinessContact", name: "Fred", to_partial_path: "businesses/business")
26
+
27
+ presenter = described_class.new business_contact do |model|
28
+ "#{model.class.model_name.singular}/hello"
29
+ end
30
+
31
+ expect(presenter.to_partial_path).to eq("business_contact/hello")
32
+ end
33
+ end
34
+
35
+ describe "#to_model" do
36
+ it "returns the presenter object with a working to_partial_path method" do
37
+ dealer = Dealer.new
38
+ presenter = described_class.new dealer do |model|
39
+ "test"
40
+ end
41
+
42
+ expect(presenter.to_model.to_partial_path).to eq("test")
43
+ end
44
+ end
45
+
46
+ describe ".wrap_collection" do
47
+ it "wraps a collection" do
48
+ business = mock_model("Business")
49
+ business_contact = mock_model("BusinessContact")
50
+
51
+ collection_to_wrap = [business, business_contact]
52
+
53
+ wrapped_collection = described_class.wrap_collection collection_to_wrap do|model|
54
+ "#{model.class.model_name.plural}/summary"
55
+ end
56
+
57
+ returned_partial_paths = wrapped_collection.collect(&:to_partial_path)
58
+ expect(returned_partial_paths).to eq(["businesses/summary", "business_contacts/summary"])
59
+ end
60
+ end
61
+
62
+ describe ".model_name" do
63
+ it "delegates to the class of the source object" do
64
+ dealer = Dealer.new
65
+
66
+ presenter = described_class.new dealer
67
+
68
+ expect(presenter.class.model_name).to eq(dealer.class.model_name)
69
+ end
70
+ end
71
+
72
+ describe "integration with other rails helpers" do
73
+ it "works properly when passing the presenter into the div_for helper" do
74
+ dealer = Dealer.create
75
+ presenter = described_class.new dealer
76
+
77
+ rendered_html = ApplicationController.helpers.div_for presenter
78
+
79
+ expect(rendered_html).to eq("<div class=\"dealer\" id=\"dealer_#{dealer.id}\"></div>")
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,55 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require 'spec_helper'
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'rspec/active_model/mocks'
7
+ require 'pry'
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
24
+
25
+ # Checks for pending migrations before tests are run.
26
+ # If you are not using ActiveRecord, you can remove this line.
27
+ # ActiveRecord::Migration.maintain_test_schema!
28
+
29
+ # Run any available migration
30
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
31
+
32
+ RSpec.configure do |config|
33
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
34
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
35
+
36
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
37
+ # examples within a transaction, remove the following line or assign false
38
+ # instead of true.
39
+ config.use_transactional_fixtures = true
40
+
41
+ # RSpec Rails can automatically mix in different behaviours to your tests
42
+ # based on their file location, for example enabling you to call `get` and
43
+ # `post` in specs under `spec/controllers`.
44
+ #
45
+ # You can disable this behaviour by removing the line below, and instead
46
+ # explicitly tag your specs with their type, e.g.:
47
+ #
48
+ # RSpec.describe UsersController, :type => :controller do
49
+ # # ...
50
+ # end
51
+ #
52
+ # The different available types are documented in the features, such as in
53
+ # https://relishapp.com/rspec/rspec-rails/docs
54
+ config.infer_spec_type_from_file_location!
55
+ end
@@ -0,0 +1,85 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # Many RSpec users commonly either run the entire suite or an individual
59
+ # file, and it's useful to allow more verbose output when running an
60
+ # individual spec file.
61
+ if config.files_to_run.one?
62
+ # Use the documentation formatter for detailed output,
63
+ # unless a formatter has already been configured
64
+ # (e.g. via a command-line flag).
65
+ config.default_formatter = 'doc'
66
+ end
67
+
68
+ # Print the 10 slowest examples and example groups at the
69
+ # end of the spec run, to help surface which specs are running
70
+ # particularly slow.
71
+ config.profile_examples = 10
72
+
73
+ # Run specs in random order to surface order dependencies. If you find an
74
+ # order dependency and want to debug it, you can fix the order by providing
75
+ # the seed, which is printed after each run.
76
+ # --seed 1234
77
+ config.order = :random
78
+
79
+ # Seed global randomization in this process using the `--seed` CLI option.
80
+ # Setting this allows you to use `--seed` to deterministically reproduce
81
+ # test failures related to randomization by passing the same `--seed` value
82
+ # as the one that triggered the failure.
83
+ Kernel.srand config.seed
84
+ =end
85
+ end