flowmor_router 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
 - data/README.md +212 -38
 - data/Rakefile +0 -2
 - data/config/routes.rb +12 -18
 - data/lib/flowmor_router/acts_as_routable.rb +56 -0
 - data/lib/flowmor_router/exceptions.rb +1 -0
 - data/lib/flowmor_router/foo.rb +63 -0
 - data/lib/flowmor_router/proxy_foo.rb +50 -0
 - data/lib/flowmor_router/router_classes.rb +261 -0
 - data/lib/flowmor_router/version.rb +1 -1
 - data/lib/flowmor_router.rb +2 -1
 - data/test/dummy/app/models/article.rb +7 -1
 - data/test/dummy/app/models/news_article.rb +1 -1
 - data/test/dummy/app/models/post.rb +12 -11
 - data/test/dummy/app/models/post_category.rb +2 -2
 - data/test/dummy/log/test.log +86734 -0
 - data/test/dummy/test/integration/routable_records_test.rb +2 -1
 - data/test/dummy/test/models/article_test.rb +16 -15
 - data/test/dummy/test/models/news_article_test.rb +11 -24
 - data/test/dummy/test/models/post_category_test.rb +4 -29
 - data/test/dummy/test/models/post_test.rb +10 -40
 - data/test/router_classes_test.rb +219 -0
 - metadata +8 -3
 - data/lib/flowmor_router/acts_as_flowmor_routable.rb +0 -122
 
| 
         @@ -4,7 +4,7 @@ class RoutableRecordsTest < ActionDispatch::IntegrationTest 
     | 
|
| 
       4 
4 
     | 
    
         
             
              test "/general/lets-test-this" do
         
     | 
| 
       5 
5 
     | 
    
         
             
                post = Post.create(title: "Let's Test This")
         
     | 
| 
       6 
6 
     | 
    
         
             
                assert_equal post.name, 'lets-test-this'
         
     | 
| 
       7 
     | 
    
         
            -
                assert_equal "/general/lets-test-this", post.path
         
     | 
| 
      
 7 
     | 
    
         
            +
                assert_equal "/by_category/posts/general/lets-test-this", post.path
         
     | 
| 
       8 
8 
     | 
    
         
             
                get post.path
         
     | 
| 
       9 
9 
     | 
    
         
             
                assert_response :success
         
     | 
| 
       10 
10 
     | 
    
         
             
                assert_select "h1", "Let's Test This"
         
     | 
| 
         @@ -13,6 +13,7 @@ class RoutableRecordsTest < ActionDispatch::IntegrationTest 
     | 
|
| 
       13 
13 
     | 
    
         
             
              test "only routable routes built" do 
         
     | 
| 
       14 
14 
     | 
    
         
             
                a1 = Article.create(title: "Route This", published: true)
         
     | 
| 
       15 
15 
     | 
    
         
             
                a2 = Article.create(title: "Ignore This", published: false)
         
     | 
| 
      
 16 
     | 
    
         
            +
                Rails.logger.info "\nROUTES: #{Rails.application.routes.routes.collect {|r| r.name }.inspect}"
         
     | 
| 
       16 
17 
     | 
    
         
             
                get a1.path
         
     | 
| 
       17 
18 
     | 
    
         
             
                assert_response :success
         
     | 
| 
       18 
19 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutedRecord do
         
     | 
| 
         @@ -1,22 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class ArticleTest < ActiveSupport::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
              setup do 
         
     | 
| 
      
 5 
     | 
    
         
            +
                @article = Article.create(title: "Dummy Article", published: true)
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
              test "article# 
     | 
| 
       9 
     | 
    
         
            -
                assert  
     | 
| 
      
 8 
     | 
    
         
            +
              test "article#flowmor_article_articles_router_class is a RouterClasses class" do 
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert @article.flowmor_articles_router_class.is_a?(FlowmorRouter::RouterClasses)
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
              test " 
     | 
| 
       13 
     | 
    
         
            -
                assert  
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              test "RouterClasses has Article registered" do 
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert FlowmorRouter::RouterClasses.router_classes.map(&:model).include? Article
         
     | 
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              test "article# 
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 16 
     | 
    
         
            +
              test "article#route_name" do 
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal 'articles_dummy_article', @article.route_name
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
              test "article#controller_action" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert Article.new.flowmor_articles_router_class.controller_action, "article#show"
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
              
         
     | 
| 
       20 
24 
     | 
    
         
             
              test "unpublished articles not routed" do 
         
     | 
| 
       21 
25 
     | 
    
         
             
                published = Article.create(title: "Published", published: true)
         
     | 
| 
       22 
26 
     | 
    
         
             
                unpublished = Article.create(title: "Unpublished", published: false)
         
     | 
| 
         @@ -32,11 +36,8 @@ class ArticleTest < ActiveSupport::TestCase 
     | 
|
| 
       32 
36 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       33 
37 
     | 
    
         
             
                  Article.new(title: nil).path
         
     | 
| 
       34 
38 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
       38 
     | 
    
         
            -
                assert_raise FlowmorRouter::UnroutedRecord do
         
     | 
| 
       39 
     | 
    
         
            -
                  assert Article.create(title: "Dummy Article").path, '/articles/dummy-article'
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
                titleless_article = Article.create(title: nil, published: true)
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal "/articles/#{titleless_article.id}", titleless_article.path
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert Article.create(title: "Another Article", published: true).path, '/articles/another-article'
         
     | 
| 
       41 
42 
     | 
    
         
             
              end
         
     | 
| 
       42 
43 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,34 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class NewsArticleTest < ActiveSupport::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              test "news_article#controller_action" do
         
     | 
| 
       5 
     | 
    
         
            -
                assert_equal "news_article#show", NewsArticle.new.controller_action
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
              
         
     | 
| 
       8 
4 
     | 
    
         
             
              test "news_article#route_name" do 
         
     | 
| 
       9 
5 
     | 
    
         
             
                assert_equal 'news_articles_dummy_news_article', NewsArticle.new(caption: "Dummy News Article").route_name
         
     | 
| 
       10 
6 
     | 
    
         
             
              end
         
     | 
| 
       11 
7 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              test " 
     | 
| 
       13 
     | 
    
         
            -
                assert_equal ' 
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
              
         
     | 
| 
       16 
     | 
    
         
            -
              test "news_article#derived_name_field_value" do 
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal 'Dummy News Article', NewsArticle.new(caption: "Dummy News Article").derived_name_field_value
         
     | 
| 
      
 8 
     | 
    
         
            +
              test "NewsArticle controller_action" do 
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert_equal 'news_article#show', NewsArticle.flowmor_news_articles_router_class.controller_action
         
     | 
| 
       18 
10 
     | 
    
         
             
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              test "news_article#new_name_value" do 
         
     | 
| 
       21 
     | 
    
         
            -
                assert_equal 'dummy-news-article', NewsArticle.new(caption: "Dummy News Article").new_name_value
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
              
         
     | 
| 
       24 
     | 
    
         
            -
              test "news_article#slug" do 
         
     | 
| 
       25 
     | 
    
         
            -
                assert_equal 'dummy-news-article', NewsArticle.create(caption: "Dummy News Article").slug
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
              
         
     | 
| 
       28 
     | 
    
         
            -
              test "NewsArticle#route_model" do 
         
     | 
| 
       29 
     | 
    
         
            -
                assert_equal 'news_article', NewsArticle.route_model
         
     | 
| 
       30 
     | 
    
         
            -
              end
         
     | 
| 
       31 
     | 
    
         
            -
              
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       32 
12 
     | 
    
         
             
              test "news_article#path" do
         
     | 
| 
       33 
13 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       34 
14 
     | 
    
         
             
                  NewsArticle.new(caption: nil).path
         
     | 
| 
         @@ -36,7 +16,9 @@ class NewsArticleTest < ActiveSupport::TestCase 
     | 
|
| 
       36 
16 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       37 
17 
     | 
    
         
             
                  NewsArticle.create(caption: nil).path
         
     | 
| 
       38 
18 
     | 
    
         
             
                end
         
     | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
      
 19 
     | 
    
         
            +
                real_article = NewsArticle.create(caption: "Real News Article")
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal '/news_articles/real-news-article', Rails.application.routes.url_helpers.news_articles_real_news_article_path
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_equal '/news_articles/real-news-article', real_article.path
         
     | 
| 
       40 
22 
     | 
    
         
             
              end
         
     | 
| 
       41 
23 
     | 
    
         | 
| 
       42 
24 
     | 
    
         
             
              test "news_article#url" do 
         
     | 
| 
         @@ -46,5 +28,10 @@ class NewsArticleTest < ActiveSupport::TestCase 
     | 
|
| 
       46 
28 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       47 
29 
     | 
    
         
             
                  NewsArticle.create(caption: nil).url
         
     | 
| 
       48 
30 
     | 
    
         
             
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                real_article = NewsArticle.create(caption: "Real News Article")
         
     | 
| 
      
 33 
     | 
    
         
            +
                Thread.current[:host] = "localhost"
         
     | 
| 
      
 34 
     | 
    
         
            +
                Thread.current[:port] = "3000"
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal 'http://localhost:3000/news_articles/real-news-article', real_article.url
         
     | 
| 
       49 
36 
     | 
    
         
             
              end
         
     | 
| 
       50 
37 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,30 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class PostCategoryCategoryTest < ActiveSupport::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              test "post_category#controller_action" do
         
     | 
| 
       5 
     | 
    
         
            -
                assert_equal "blog#category", PostCategory.new.controller_action
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
              
         
     | 
| 
       8 
4 
     | 
    
         
             
              test "post_category#route_name" do 
         
     | 
| 
       9 
     | 
    
         
            -
                assert_equal ' 
     | 
| 
      
 5 
     | 
    
         
            +
                assert_equal 'category_general', PostCategory.new(name: "general").route_name
         
     | 
| 
       10 
6 
     | 
    
         
             
              end
         
     | 
| 
       11 
7 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              test " 
     | 
| 
       13 
     | 
    
         
            -
                assert_equal ' 
     | 
| 
      
 8 
     | 
    
         
            +
              test "PostCategory controller_action" do 
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert_equal 'blog#category', PostCategory.flowmor_category_router_class.controller_action
         
     | 
| 
       14 
10 
     | 
    
         
             
              end
         
     | 
| 
       15 
11 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              test "post_category#derived_name_field_value" do 
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal 'General', PostCategory.new(title: "General").derived_name_field_value
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
              
         
     | 
| 
       20 
     | 
    
         
            -
              test "post_category#new_name_value" do 
         
     | 
| 
       21 
     | 
    
         
            -
                assert_equal 'general', PostCategory.new(title: "General").new_name_value
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
              
         
     | 
| 
       24 
     | 
    
         
            -
              test "PostCategory#route_model" do 
         
     | 
| 
       25 
     | 
    
         
            -
                assert_equal 'category', PostCategory.route_model
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
              
         
     | 
| 
       28 
12 
     | 
    
         
             
              test "post_category#path" do
         
     | 
| 
       29 
13 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       30 
14 
     | 
    
         
             
                  PostCategory.new(title: nil).path
         
     | 
| 
         @@ -32,15 +16,6 @@ class PostCategoryCategoryTest < ActiveSupport::TestCase 
     | 
|
| 
       32 
16 
     | 
    
         
             
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       33 
17 
     | 
    
         
             
                  PostCategory.create(title: nil).path
         
     | 
| 
       34 
18 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
                assert_equal '/ 
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
              
         
     | 
| 
       38 
     | 
    
         
            -
              test "post_category#url" do 
         
     | 
| 
       39 
     | 
    
         
            -
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       40 
     | 
    
         
            -
                  PostCategory.new(title: nil).url
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       43 
     | 
    
         
            -
                  PostCategory.create(title: nil).url
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_equal '/category/general', PostCategory.create(title: "General").path
         
     | 
| 
       45 
20 
     | 
    
         
             
              end
         
     | 
| 
       46 
21 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,54 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class PostTest < ActiveSupport::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              
         
     | 
| 
       8 
     | 
    
         
            -
              test "default category is 'general'" do 
         
     | 
| 
       9 
     | 
    
         
            -
                assert_equal 'general', Post.new.category_name
         
     | 
| 
      
 4 
     | 
    
         
            +
              setup do
         
     | 
| 
      
 5 
     | 
    
         
            +
                @category = PostCategory.create(name: "general")
         
     | 
| 
      
 6 
     | 
    
         
            +
                @post = Post.create(title: "Once Upon a Time")
         
     | 
| 
       10 
7 
     | 
    
         
             
              end
         
     | 
| 
       11 
8 
     | 
    
         | 
| 
       12 
9 
     | 
    
         
             
              test "post#route_name" do 
         
     | 
| 
       13 
     | 
    
         
            -
                assert_equal ' 
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
              
         
     | 
| 
       16 
     | 
    
         
            -
              test "post#route_name_prefix" do
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal 'posts_general', Post.new(title: "Dummy Post").route_name_prefix
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              test "post#derived_name_field_value" do 
         
     | 
| 
       21 
     | 
    
         
            -
                assert_equal 'Dummy Post', Post.new(title: "Dummy Post").derived_name_field_value
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert_equal 'by_category_posts_general_once_upon_a_time', @post.route_name
         
     | 
| 
       22 
11 
     | 
    
         
             
              end
         
     | 
| 
       23 
12 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
              test " 
     | 
| 
       25 
     | 
    
         
            -
                assert_equal ' 
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
              
         
     | 
| 
       28 
     | 
    
         
            -
              test "Post#route_model" do 
         
     | 
| 
       29 
     | 
    
         
            -
                assert_equal 'post', Post.route_model
         
     | 
| 
       30 
     | 
    
         
            -
              end
         
     | 
| 
       31 
     | 
    
         
            -
              
         
     | 
| 
       32 
     | 
    
         
            -
              test "post#route" do
         
     | 
| 
       33 
     | 
    
         
            -
                assert_equal Post.new(title: "Dummy Post", name: "dummy-post").route, '/general/dummy-post'
         
     | 
| 
      
 13 
     | 
    
         
            +
              test "Post controller_action" do 
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_equal 'blog#show', Post.flowmor_posts_router_class.controller_action
         
     | 
| 
       34 
15 
     | 
    
         
             
              end
         
     | 
| 
       35 
16 
     | 
    
         | 
| 
       36 
17 
     | 
    
         
             
              test "post#path" do
         
     | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
       38 
     | 
    
         
            -
                  Post.new(title: nil).path
         
     | 
| 
       39 
     | 
    
         
            -
                end
         
     | 
| 
       40 
     | 
    
         
            -
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       41 
     | 
    
         
            -
                  Post.create(title: nil).path
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
                assert_equal '/general/dummy-post', Post.create(title: "Dummy Post").path
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal '/by_category/posts/general/once-upon-a-time', @post.path
         
     | 
| 
       44 
19 
     | 
    
         
             
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              test "post# 
     | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
       48 
     | 
    
         
            -
                  Post.new(title: nil).url
         
     | 
| 
       49 
     | 
    
         
            -
                end
         
     | 
| 
       50 
     | 
    
         
            -
                assert_raise FlowmorRouter::UnroutableRecord do
         
     | 
| 
       51 
     | 
    
         
            -
                  Post.create(title: nil).url
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              test "post#archive_path" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal '/archive/once-upon-a-time', @post.archive_path
         
     | 
| 
       53 
23 
     | 
    
         
             
              end
         
     | 
| 
       54 
24 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,219 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'flowmor_router'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            # require 'action_dispatch/routing/inspector'
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Rails.application.routes_reloader.reload!
         
     | 
| 
      
 6 
     | 
    
         
            +
            # puts "ROUTES: #{Rails.application.routes.routes.collect {|r| r.name }.inspect}"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            module FlowmorRouter 
         
     | 
| 
      
 9 
     | 
    
         
            +
              class RouterClassesTest < ActiveSupport::TestCase
         
     | 
| 
      
 10 
     | 
    
         
            +
                
         
     | 
| 
      
 11 
     | 
    
         
            +
                class Foo 
         
     | 
| 
      
 12 
     | 
    
         
            +
                  include ActiveModel::AttributeMethods
         
     | 
| 
      
 13 
     | 
    
         
            +
                  define_attribute_methods :title, :slug, :name, :alt_name, :caption, :id
         
     | 
| 
      
 14 
     | 
    
         
            +
                  attr_accessor :title, :slug, :name, :alt_name, :caption, :id
         
     | 
| 
      
 15 
     | 
    
         
            +
                  
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @@routable = []
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 19 
     | 
    
         
            +
                    def after_save *args
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    alias :before_save :after_save
         
     | 
| 
      
 22 
     | 
    
         
            +
                    alias :scope :after_save
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def self.routable
         
     | 
| 
      
 26 
     | 
    
         
            +
                    @@routable
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  def initialize(title, slug)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @id = 1
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @title = title
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @caption = "#{title} (captioned)"
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @slug = slug
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @name = slug
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @alt_name = "alt-#{slug}"
         
     | 
| 
      
 36 
     | 
    
         
            +
                    self.class.routable << self
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  
         
     | 
| 
      
 39 
     | 
    
         
            +
                  include FlowmorRouter::ActsAsRoutable
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
                test "defined correctly" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  assert_kind_of Class, FlowmorRouter::RouterClasses
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              
         
     | 
| 
      
 46 
     | 
    
         
            +
                test "can register a class" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 48 
     | 
    
         
            +
                    RouterClasses.register :obj, Object, {}
         
     | 
| 
      
 49 
     | 
    
         
            +
                    assert RouterClasses.router_classes.map(&:model).include?(Object)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    assert RouterClasses.router_classes.map(&:actor).include?("obj")
         
     | 
| 
      
 51 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 52 
     | 
    
         
            +
                    RouterClasses.unregister Object
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
                
         
     | 
| 
      
 56 
     | 
    
         
            +
                test "Bar becomes routable" do
         
     | 
| 
      
 57 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 58 
     | 
    
         
            +
                    class Bar < Foo
         
     | 
| 
      
 59 
     | 
    
         
            +
                      acts_as_routable
         
     | 
| 
      
 60 
     | 
    
         
            +
                    end
         
     | 
| 
      
 61 
     | 
    
         
            +
                  
         
     | 
| 
      
 62 
     | 
    
         
            +
                    item = Bar.new("FooBar", "foo-bar")
         
     | 
| 
      
 63 
     | 
    
         
            +
                    rc = RouterClasses.router_classes.detect{|d| d.model == Bar}
         
     | 
| 
      
 64 
     | 
    
         
            +
                    
         
     | 
| 
      
 65 
     | 
    
         
            +
                    assert_equal Bar,                     rc.model
         
     | 
| 
      
 66 
     | 
    
         
            +
                    assert_equal "bars",                  rc.actor
         
     | 
| 
      
 67 
     | 
    
         
            +
                    assert_equal "bar#show",              rc.controller_action
         
     | 
| 
      
 68 
     | 
    
         
            +
                    assert_equal "bars",                  rc.route_base_name
         
     | 
| 
      
 69 
     | 
    
         
            +
                    assert_equal "/bars",                 rc.route_base_path
         
     | 
| 
      
 70 
     | 
    
         
            +
                    assert_equal "foo-bar",               rc.name(item)
         
     | 
| 
      
 71 
     | 
    
         
            +
                    assert_equal "flowmor_bars_routable", rc.scope_name
         
     | 
| 
      
 72 
     | 
    
         
            +
                    assert_equal "/bars/foo-bar",         rc.route_path(item)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    assert_equal "path",                  rc.path_method_name
         
     | 
| 
      
 74 
     | 
    
         
            +
                    assert_equal "url",                   rc.url_method_name
         
     | 
| 
      
 75 
     | 
    
         
            +
                    assert_equal "bars_foo_bar",          rc.route_name(item)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 77 
     | 
    
         
            +
                    RouterClasses.unregister Bar
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
                
         
     | 
| 
      
 81 
     | 
    
         
            +
                test "Baz becomes routable with named model" do
         
     | 
| 
      
 82 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 83 
     | 
    
         
            +
                    class Baz < Foo
         
     | 
| 
      
 84 
     | 
    
         
            +
                      acts_as_routable :foobaz, 
         
     | 
| 
      
 85 
     | 
    
         
            +
                        prefix: [:foo, :bazs], 
         
     | 
| 
      
 86 
     | 
    
         
            +
                        name_field: :alt_name,
         
     | 
| 
      
 87 
     | 
    
         
            +
                        title_field: :caption
         
     | 
| 
      
 88 
     | 
    
         
            +
                    end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                    item = Baz.new("FooBaz", "foo-baz")
         
     | 
| 
      
 91 
     | 
    
         
            +
                    rc = RouterClasses.router_classes.detect{|d| d.model == Baz}
         
     | 
| 
      
 92 
     | 
    
         
            +
                    
         
     | 
| 
      
 93 
     | 
    
         
            +
                    assert_equal Baz,                                 rc.model
         
     | 
| 
      
 94 
     | 
    
         
            +
                    assert_equal "foobaz",                            rc.actor
         
     | 
| 
      
 95 
     | 
    
         
            +
                    assert_equal "foobaz#show",                       rc.controller_action
         
     | 
| 
      
 96 
     | 
    
         
            +
                    assert_equal [:foo, :bazs],                       rc.route_prefix(item)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    assert_equal "foobaz",                            rc.route_base_name
         
     | 
| 
      
 98 
     | 
    
         
            +
                    assert_equal "/foobaz",                           rc.route_base_path
         
     | 
| 
      
 99 
     | 
    
         
            +
                    assert_equal "alt-foo-baz",                       rc.name(item)
         
     | 
| 
      
 100 
     | 
    
         
            +
                    assert_equal "flowmor_foobaz_routable",           rc.scope_name
         
     | 
| 
      
 101 
     | 
    
         
            +
                    assert_equal "/foo/bazs/foobaz/alt-foo-baz",      rc.route_path(item)
         
     | 
| 
      
 102 
     | 
    
         
            +
                    assert_equal "path",                              rc.path_method_name
         
     | 
| 
      
 103 
     | 
    
         
            +
                    assert_equal "url",                               rc.url_method_name
         
     | 
| 
      
 104 
     | 
    
         
            +
                    assert_equal "foo_bazs_foobaz_alt_foo_baz",       rc.route_name(item)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 106 
     | 
    
         
            +
                    RouterClasses.unregister Baz
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
                
         
     | 
| 
      
 110 
     | 
    
         
            +
                test "Bat becomes routable with named model" do
         
     | 
| 
      
 111 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 112 
     | 
    
         
            +
                    class Bat < Foo
         
     | 
| 
      
 113 
     | 
    
         
            +
                      def batty
         
     | 
| 
      
 114 
     | 
    
         
            +
                        "coo_coo-for-coco_puffs"
         
     | 
| 
      
 115 
     | 
    
         
            +
                      end
         
     | 
| 
      
 116 
     | 
    
         
            +
                      
         
     | 
| 
      
 117 
     | 
    
         
            +
                      def custom_route
         
     | 
| 
      
 118 
     | 
    
         
            +
                        "/foo/#{batty}"
         
     | 
| 
      
 119 
     | 
    
         
            +
                      end
         
     | 
| 
      
 120 
     | 
    
         
            +
                      
         
     | 
| 
      
 121 
     | 
    
         
            +
                      def category 
         
     | 
| 
      
 122 
     | 
    
         
            +
                        :crazy
         
     | 
| 
      
 123 
     | 
    
         
            +
                      end
         
     | 
| 
      
 124 
     | 
    
         
            +
                      
         
     | 
| 
      
 125 
     | 
    
         
            +
                      acts_as_routable route: :custom_route, prefix: -> { :category }
         
     | 
| 
      
 126 
     | 
    
         
            +
                    end
         
     | 
| 
      
 127 
     | 
    
         
            +
                   
         
     | 
| 
      
 128 
     | 
    
         
            +
                    item = Bat.new("FooBar", "foo-bar")
         
     | 
| 
      
 129 
     | 
    
         
            +
                    rc = RouterClasses.router_classes.detect{|d| d.model == Bat}
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                    assert_equal Bat,                           rc.model
         
     | 
| 
      
 132 
     | 
    
         
            +
                    assert_equal "flowmor_bats_routable",       rc.scope_name
         
     | 
| 
      
 133 
     | 
    
         
            +
                    assert_equal "bats",                        rc.actor
         
     | 
| 
      
 134 
     | 
    
         
            +
                    assert_equal "bat#show",                    rc.controller_action
         
     | 
| 
      
 135 
     | 
    
         
            +
                    assert_equal "bats",                        rc.route_base_name
         
     | 
| 
      
 136 
     | 
    
         
            +
                    assert_equal "/bats",                       rc.route_base_path
         
     | 
| 
      
 137 
     | 
    
         
            +
                    assert_equal "foo-bar",                     rc.name(item)
         
     | 
| 
      
 138 
     | 
    
         
            +
                    assert_equal "/foo/coo_coo-for-coco_puffs", rc.route_path(item)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    assert_equal "path",                        rc.path_method_name
         
     | 
| 
      
 140 
     | 
    
         
            +
                    assert_equal "url",                         rc.url_method_name
         
     | 
| 
      
 141 
     | 
    
         
            +
                    assert_equal "crazy_bats_foo_bar",          rc.route_name(item)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    assert_equal [:crazy],                      rc.route_prefix(item)
         
     | 
| 
      
 143 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 144 
     | 
    
         
            +
                    RouterClasses.unregister Bat
         
     | 
| 
      
 145 
     | 
    
         
            +
                  end
         
     | 
| 
      
 146 
     | 
    
         
            +
                end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                test "Down becomes routable with named model" do
         
     | 
| 
      
 149 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 150 
     | 
    
         
            +
                    class Down < Foo
         
     | 
| 
      
 151 
     | 
    
         
            +
                      
         
     | 
| 
      
 152 
     | 
    
         
            +
                      acts_as_routable delimiter: "_"
         
     | 
| 
      
 153 
     | 
    
         
            +
                    end
         
     | 
| 
      
 154 
     | 
    
         
            +
                   
         
     | 
| 
      
 155 
     | 
    
         
            +
                    item = Down.new("A Serious Downer", nil)
         
     | 
| 
      
 156 
     | 
    
         
            +
                    rc = RouterClasses.router_classes.detect{|d| d.model == Down}
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                    assert_equal Down,                      rc.model
         
     | 
| 
      
 159 
     | 
    
         
            +
                    assert_equal "flowmor_downs_routable",  rc.scope_name
         
     | 
| 
      
 160 
     | 
    
         
            +
                    assert_equal "downs",                   rc.actor
         
     | 
| 
      
 161 
     | 
    
         
            +
                    assert_equal "down#show",               rc.controller_action
         
     | 
| 
      
 162 
     | 
    
         
            +
                    assert_equal "downs",                   rc.route_base_name
         
     | 
| 
      
 163 
     | 
    
         
            +
                    assert_equal "/downs",                  rc.route_base_path
         
     | 
| 
      
 164 
     | 
    
         
            +
                    assert_equal "a_serious_downer",        rc.name(item)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    assert_equal "/downs/a_serious_downer", rc.route_path(item)
         
     | 
| 
      
 166 
     | 
    
         
            +
                    assert_equal "path",                    rc.path_method_name
         
     | 
| 
      
 167 
     | 
    
         
            +
                    assert_equal "url",                     rc.url_method_name
         
     | 
| 
      
 168 
     | 
    
         
            +
                    assert_equal "downs_a_serious_downer",  rc.route_name(item)
         
     | 
| 
      
 169 
     | 
    
         
            +
                    assert_equal nil,                       rc.route_prefix(item)
         
     | 
| 
      
 170 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 171 
     | 
    
         
            +
                    RouterClasses.unregister Down
         
     | 
| 
      
 172 
     | 
    
         
            +
                  end
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                test "Fib becomes routable with named model" do
         
     | 
| 
      
 176 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 177 
     | 
    
         
            +
                    class Fib < Foo
         
     | 
| 
      
 178 
     | 
    
         
            +
                      
         
     | 
| 
      
 179 
     | 
    
         
            +
                      def custom_name
         
     | 
| 
      
 180 
     | 
    
         
            +
                        ["so_called", name.parameterize].join("-")
         
     | 
| 
      
 181 
     | 
    
         
            +
                      end
         
     | 
| 
      
 182 
     | 
    
         
            +
                      
         
     | 
| 
      
 183 
     | 
    
         
            +
                      acts_as_routable name: :custom_name
         
     | 
| 
      
 184 
     | 
    
         
            +
                      acts_as_routable :archive, controller_action: "fib#archive", name: :custom_name
         
     | 
| 
      
 185 
     | 
    
         
            +
                    end
         
     | 
| 
      
 186 
     | 
    
         
            +
                   
         
     | 
| 
      
 187 
     | 
    
         
            +
                    item = Fib.new("FooBar", "foo-bar")
         
     | 
| 
      
 188 
     | 
    
         
            +
                    rc = Fib.flowmor_fibs_router_class
         
     | 
| 
      
 189 
     | 
    
         
            +
                    rca = Fib.flowmor_fibs_archive_router_class
         
     | 
| 
      
 190 
     | 
    
         
            +
                    
         
     | 
| 
      
 191 
     | 
    
         
            +
                    assert_equal Fib,                       rc.model
         
     | 
| 
      
 192 
     | 
    
         
            +
                    assert_equal "fibs",                    rc.actor
         
     | 
| 
      
 193 
     | 
    
         
            +
                    assert_equal "fib#show",                rc.controller_action
         
     | 
| 
      
 194 
     | 
    
         
            +
                    assert_equal "fibs",                    rc.route_base_name
         
     | 
| 
      
 195 
     | 
    
         
            +
                    assert_equal "/fibs",                   rc.route_base_path
         
     | 
| 
      
 196 
     | 
    
         
            +
                    assert_equal "so_called-foo-bar",       rc.name(item)
         
     | 
| 
      
 197 
     | 
    
         
            +
                    assert_equal "flowmor_fibs_routable",   rc.scope_name
         
     | 
| 
      
 198 
     | 
    
         
            +
                    assert_equal "/fibs/so_called-foo-bar", rc.route_path(item)
         
     | 
| 
      
 199 
     | 
    
         
            +
                    assert_equal "path",                    rc.path_method_name
         
     | 
| 
      
 200 
     | 
    
         
            +
                    assert_equal "url",                     rc.url_method_name
         
     | 
| 
      
 201 
     | 
    
         
            +
                    assert_equal "fibs_so_called_foo_bar",  rc.route_name(item)
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
                    assert_equal Fib,                               rca.model
         
     | 
| 
      
 204 
     | 
    
         
            +
                    assert_equal "archive",                         rca.actor
         
     | 
| 
      
 205 
     | 
    
         
            +
                    assert_equal "fib#archive",                     rca.controller_action
         
     | 
| 
      
 206 
     | 
    
         
            +
                    assert_equal "fibs_archive",                    rca.route_base_name
         
     | 
| 
      
 207 
     | 
    
         
            +
                    assert_equal "/archive",                        rca.route_base_path
         
     | 
| 
      
 208 
     | 
    
         
            +
                    assert_equal "so_called-foo-bar",               rca.name(item)
         
     | 
| 
      
 209 
     | 
    
         
            +
                    assert_equal "flowmor_fibs_archive_routable",   rca.scope_name
         
     | 
| 
      
 210 
     | 
    
         
            +
                    assert_equal "/archive/so_called-foo-bar",      rca.route_path(item)
         
     | 
| 
      
 211 
     | 
    
         
            +
                    assert_equal "archive_path",                    rca.path_method_name
         
     | 
| 
      
 212 
     | 
    
         
            +
                    assert_equal "archive_url",                     rca.url_method_name
         
     | 
| 
      
 213 
     | 
    
         
            +
                    assert_equal "fibs_archive_so_called_foo_bar",  rca.route_name(item)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 215 
     | 
    
         
            +
                    RouterClasses.unregister Fib
         
     | 
| 
      
 216 
     | 
    
         
            +
                  end
         
     | 
| 
      
 217 
     | 
    
         
            +
                end
         
     | 
| 
      
 218 
     | 
    
         
            +
              end
         
     | 
| 
      
 219 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: flowmor_router
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Michael Lang
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-04- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-04-13 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -56,9 +56,12 @@ files: 
     | 
|
| 
       56 
56 
     | 
    
         
             
            - bin/rails
         
     | 
| 
       57 
57 
     | 
    
         
             
            - config/routes.rb
         
     | 
| 
       58 
58 
     | 
    
         
             
            - lib/flowmor_router.rb
         
     | 
| 
       59 
     | 
    
         
            -
            - lib/flowmor_router/ 
     | 
| 
      
 59 
     | 
    
         
            +
            - lib/flowmor_router/acts_as_routable.rb
         
     | 
| 
       60 
60 
     | 
    
         
             
            - lib/flowmor_router/engine.rb
         
     | 
| 
       61 
61 
     | 
    
         
             
            - lib/flowmor_router/exceptions.rb
         
     | 
| 
      
 62 
     | 
    
         
            +
            - lib/flowmor_router/foo.rb
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/flowmor_router/proxy_foo.rb
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/flowmor_router/router_classes.rb
         
     | 
| 
       62 
65 
     | 
    
         
             
            - lib/flowmor_router/version.rb
         
     | 
| 
       63 
66 
     | 
    
         
             
            - lib/tasks/flowmor_router_tasks.rake
         
     | 
| 
       64 
67 
     | 
    
         
             
            - test/dummy/README.rdoc
         
     | 
| 
         @@ -149,6 +152,7 @@ files: 
     | 
|
| 
       149 
152 
     | 
    
         
             
            - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
         
     | 
| 
       150 
153 
     | 
    
         
             
            - test/flowmor_router_test.rb
         
     | 
| 
       151 
154 
     | 
    
         
             
            - test/integration/navigation_test.rb
         
     | 
| 
      
 155 
     | 
    
         
            +
            - test/router_classes_test.rb
         
     | 
| 
       152 
156 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       153 
157 
     | 
    
         
             
            homepage: https://github.com/mwlang/flowmor_router
         
     | 
| 
       154 
158 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -263,5 +267,6 @@ test_files: 
     | 
|
| 
       263 
267 
     | 
    
         
             
            - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
         
     | 
| 
       264 
268 
     | 
    
         
             
            - test/flowmor_router_test.rb
         
     | 
| 
       265 
269 
     | 
    
         
             
            - test/integration/navigation_test.rb
         
     | 
| 
      
 270 
     | 
    
         
            +
            - test/router_classes_test.rb
         
     | 
| 
       266 
271 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       267 
272 
     | 
    
         
             
            has_rdoc: 
         
     | 
| 
         @@ -1,122 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module FlowmorRouter
         
     | 
| 
       2 
     | 
    
         
            -
              module ActsAsFlowmorRoutable
         
     | 
| 
       3 
     | 
    
         
            -
                extend ActiveSupport::Concern
         
     | 
| 
       4 
     | 
    
         
            -
                
         
     | 
| 
       5 
     | 
    
         
            -
                def controller_action
         
     | 
| 
       6 
     | 
    
         
            -
                  self.class.controller_action
         
     | 
| 
       7 
     | 
    
         
            -
                end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                included do
         
     | 
| 
       10 
     | 
    
         
            -
                  
         
     | 
| 
       11 
     | 
    
         
            -
                  after_save :reload_routes
         
     | 
| 
       12 
     | 
    
         
            -
                  before_save :populate_name
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                  def derived_name_field_value
         
     | 
| 
       15 
     | 
    
         
            -
                    send(self.derived_name_field)
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                  def reload_routes
         
     | 
| 
       19 
     | 
    
         
            -
                    Rails.application.routes_reloader.reload!
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  def populate_name
         
     | 
| 
       23 
     | 
    
         
            -
                    if attributes[name_field].blank? || name_field_changed?
         
     | 
| 
       24 
     | 
    
         
            -
                      send("#{name_field}=", new_name_value)
         
     | 
| 
       25 
     | 
    
         
            -
                    end
         
     | 
| 
       26 
     | 
    
         
            -
                  end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                  def route_prefix
         
     | 
| 
       29 
     | 
    
         
            -
                    "/#{self.route_model.pluralize.gsub('_', '-')}"
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                  def route
         
     | 
| 
       33 
     | 
    
         
            -
                    "#{route_prefix}/#{new_name_value}"
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  def default_url_options
         
     | 
| 
       37 
     | 
    
         
            -
                    { :host => Thread.current[:host], :port => Thread.current[:port] }
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                  def url
         
     | 
| 
       41 
     | 
    
         
            -
                    begin
         
     | 
| 
       42 
     | 
    
         
            -
                      FlowmorRouter::Engine.routes.url_helpers.send("#{route_name}_url", default_url_options)
         
     | 
| 
       43 
     | 
    
         
            -
                    rescue NoMethodError
         
     | 
| 
       44 
     | 
    
         
            -
                      raise FlowmorRouter::UnroutedRecord.new("#{self.inspect} was not routed.")
         
     | 
| 
       45 
     | 
    
         
            -
                    end
         
     | 
| 
       46 
     | 
    
         
            -
                  end
         
     | 
| 
       47 
     | 
    
         
            -
                  def name_field
         
     | 
| 
       48 
     | 
    
         
            -
                    self.class.name_field
         
     | 
| 
       49 
     | 
    
         
            -
                  end
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  def name_field_value
         
     | 
| 
       52 
     | 
    
         
            -
                    attributes[name_field]
         
     | 
| 
       53 
     | 
    
         
            -
                  end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                  def path
         
     | 
| 
       56 
     | 
    
         
            -
                    begin
         
     | 
| 
       57 
     | 
    
         
            -
                      Rails.application.routes.url_helpers.send("#{route_name}_path")
         
     | 
| 
       58 
     | 
    
         
            -
                    rescue NoMethodError
         
     | 
| 
       59 
     | 
    
         
            -
                      raise FlowmorRouter::UnroutedRecord.new("#{self.inspect} was not routed.")
         
     | 
| 
       60 
     | 
    
         
            -
                    end
         
     | 
| 
       61 
     | 
    
         
            -
                  end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                  def route_name
         
     | 
| 
       64 
     | 
    
         
            -
                    name_suffix = new_name_value
         
     | 
| 
       65 
     | 
    
         
            -
                    raise UnroutableRecord if name_suffix.blank?
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                    "#{route_name_prefix}_#{name_suffix}".underscore
         
     | 
| 
       68 
     | 
    
         
            -
                  end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                  def route_name_prefix
         
     | 
| 
       71 
     | 
    
         
            -
                    "#{self.route_model.pluralize}"
         
     | 
| 
       72 
     | 
    
         
            -
                  end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                  def new_name_value
         
     | 
| 
       75 
     | 
    
         
            -
                    if value = derived_name_field_value and !value.blank?
         
     | 
| 
       76 
     | 
    
         
            -
                      value.downcase.gsub(/[^\w\s\d\_\-]/,'').gsub(/\s\s+/,' ').gsub(/[^\w\d]/, '-')
         
     | 
| 
       77 
     | 
    
         
            -
                    else
         
     | 
| 
       78 
     | 
    
         
            -
                      raise FlowmorRouter::UnroutableRecord if value.blank?
         
     | 
| 
       79 
     | 
    
         
            -
                    end
         
     | 
| 
       80 
     | 
    
         
            -
                  end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                  def name_field_changed?
         
     | 
| 
       83 
     | 
    
         
            -
                    new_name_value != attributes[name_field]
         
     | 
| 
       84 
     | 
    
         
            -
                  end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                module LocalInstanceMethods
         
     | 
| 
       89 
     | 
    
         
            -
                end
         
     | 
| 
       90 
     | 
    
         
            -
                
         
     | 
| 
       91 
     | 
    
         
            -
                module ClassMethods
         
     | 
| 
       92 
     | 
    
         
            -
                  def default_controller_action
         
     | 
| 
       93 
     | 
    
         
            -
                    "#{self.route_model.underscore}#show"
         
     | 
| 
       94 
     | 
    
         
            -
                  end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                  def controller_action
         
     | 
| 
       97 
     | 
    
         
            -
                    @controller_action || default_controller_action
         
     | 
| 
       98 
     | 
    
         
            -
                  end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                  def acts_as_routable(options = {})
         
     | 
| 
       101 
     | 
    
         
            -
                    ROUTABLE_MODEL_CLASSES << self
         
     | 
| 
       102 
     | 
    
         
            -
                    scope :routable, options[:scope] || lambda {}
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                    class_attribute :route_model
         
     | 
| 
       105 
     | 
    
         
            -
                    self.route_model = options[:route_model] || name.underscore.downcase
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                    class_attribute :name_field
         
     | 
| 
       108 
     | 
    
         
            -
                    self.name_field = (options[:name_field] || :name).to_s
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                    class_attribute :derived_name_field
         
     | 
| 
       111 
     | 
    
         
            -
                    self.derived_name_field = (options[:derived_name_field] || :title).to_s
         
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                    class_attribute :controller_action
         
     | 
| 
       114 
     | 
    
         
            -
                    self.controller_action = (options[:controller_action] || default_controller_action)
         
     | 
| 
       115 
     | 
    
         
            -
                    
         
     | 
| 
       116 
     | 
    
         
            -
                    include LocalInstanceMethods
         
     | 
| 
       117 
     | 
    
         
            -
                  end
         
     | 
| 
       118 
     | 
    
         
            -
                end
         
     | 
| 
       119 
     | 
    
         
            -
              end
         
     | 
| 
       120 
     | 
    
         
            -
            end
         
     | 
| 
       121 
     | 
    
         
            -
             
         
     | 
| 
       122 
     | 
    
         
            -
            ActiveRecord::Base.send :include, FlowmorRouter::ActsAsFlowmorRoutable
         
     |