brightcontent-core 2.0.33 → 2.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/app/assets/javascripts/brightcontent/brightcontent.js.erb +8 -0
  4. data/app/assets/javascripts/brightcontent/core.js.coffee +28 -0
  5. data/app/assets/javascripts/brightcontent/wysithtml5-parser-rules.js +519 -0
  6. data/app/assets/stylesheets/brightcontent/brightcontent.css.erb +10 -0
  7. data/app/assets/stylesheets/brightcontent/core.css.sass +61 -0
  8. data/app/assets/stylesheets/brightcontent/signin.css.sass +34 -0
  9. data/app/controllers/brightcontent/admin_users_controller.rb +1 -3
  10. data/app/controllers/brightcontent/application_controller.rb +12 -2
  11. data/app/controllers/brightcontent/base_controller.rb +7 -18
  12. data/app/controllers/brightcontent/sessions_controller.rb +1 -1
  13. data/app/helpers/brightcontent/application_helper.rb +4 -0
  14. data/app/helpers/brightcontent/base_helper.rb +6 -18
  15. data/app/helpers/brightcontent/translation_helper.rb +38 -0
  16. data/app/views/brightcontent/application/_menu.html.erb +9 -2
  17. data/app/views/brightcontent/application/_resource.html.erb +3 -0
  18. data/app/views/brightcontent/application/_show_flash_names.html.erb +2 -1
  19. data/app/views/brightcontent/application/_user_menu.html.erb +4 -0
  20. data/app/views/brightcontent/base/_form.html.erb +16 -11
  21. data/app/views/brightcontent/base/_list_actions.html.erb +2 -2
  22. data/app/views/brightcontent/base/_list_filters.html.erb +12 -0
  23. data/app/views/brightcontent/base/_list_header.html.erb +6 -0
  24. data/app/views/brightcontent/base/_list_item.html.erb +6 -0
  25. data/app/views/brightcontent/base/edit.html.erb +0 -2
  26. data/app/views/brightcontent/{fields → base/form_fields}/_file.html.erb +0 -0
  27. data/app/views/brightcontent/base/index.html.erb +9 -11
  28. data/app/views/brightcontent/base/list_fields/_boolean.html.erb +5 -0
  29. data/app/views/brightcontent/base/new.html.erb +0 -2
  30. data/app/views/brightcontent/sessions/new.html.erb +5 -11
  31. data/app/views/layouts/brightcontent/application.html.erb +34 -29
  32. data/bin/autospec +16 -0
  33. data/bin/rspec +16 -0
  34. data/brightcontent-core.gemspec +11 -6
  35. data/config/initializers/simple_form.rb +18 -15
  36. data/config/initializers/simple_form_bootstrap.rb +46 -30
  37. data/config/locales/brightcontent_core.en.yml +30 -0
  38. data/config/locales/brightcontent_core.nl.yml +30 -0
  39. data/config/routes.rb +1 -1
  40. data/db/migrate/20121206121725_create_brightcontent_admin_users.rb +1 -1
  41. data/lib/brightcontent/base_controller_ext/default_actions.rb +35 -0
  42. data/lib/brightcontent/base_controller_ext/fields.rb +36 -0
  43. data/lib/brightcontent/base_controller_ext/filtering.rb +21 -0
  44. data/lib/brightcontent/base_controller_ext/pagination.rb +29 -0
  45. data/lib/brightcontent/base_controller_ext.rb +8 -0
  46. data/lib/brightcontent/core.rb +24 -10
  47. data/lib/brightcontent/engine.rb +6 -0
  48. data/lib/brightcontent/resource.rb +15 -0
  49. data/lib/brightcontent/resources.rb +25 -0
  50. data/lib/brightcontent/routes_parser.rb +9 -17
  51. data/lib/brightcontent/view_lookup/abstract.rb +49 -0
  52. data/lib/brightcontent/view_lookup/filter_field.rb +57 -0
  53. data/lib/brightcontent/view_lookup/form_field.rb +14 -0
  54. data/lib/brightcontent/view_lookup/list_field.rb +13 -0
  55. data/lib/brightcontent/view_lookup.rb +8 -0
  56. data/lib/generators/brightcontent/templates/brightcontent_controller.rb +1 -1
  57. data/lib/generators/brightcontent/templates/initializer.rb +14 -2
  58. data/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +1 -1
  59. data/spec/dummy/app/models/author.rb +7 -0
  60. data/spec/dummy/app/models/blog.rb +2 -1
  61. data/spec/dummy/config/application.rb +2 -6
  62. data/spec/dummy/config/environments/development.rb +1 -10
  63. data/spec/dummy/config/environments/production.rb +0 -4
  64. data/spec/dummy/config/environments/test.rb +2 -6
  65. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  66. data/spec/dummy/db/migrate/20130720211920_create_comments.rb +0 -1
  67. data/spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb +5 -0
  68. data/spec/dummy/db/migrate/20140512090832_create_authors.rb +9 -0
  69. data/spec/dummy/db/schema.rb +19 -12
  70. data/spec/factories.rb +15 -0
  71. data/spec/features/login_spec.rb +3 -3
  72. data/spec/features/menu_spec.rb +2 -4
  73. data/spec/features/nested_resource_spec.rb +1 -1
  74. data/spec/features/resources_form_spec.rb +1 -3
  75. data/spec/features/resources_index_spec.rb +30 -6
  76. data/spec/helpers/brightcontent/translation_helper_spec.rb +27 -0
  77. data/spec/lib/brightcontent/model_extensions_spec.rb +1 -1
  78. data/spec/lib/brightcontent/resource_spec.rb +16 -0
  79. data/spec/lib/brightcontent/resources_spec.rb +67 -0
  80. data/spec/lib/brightcontent/routes_parser_spec.rb +4 -9
  81. data/spec/lib/brightcontent/view_lookup/abstract_spec.rb +40 -0
  82. metadata +159 -70
  83. data/app/assets/images/brightcontent/.gitkeep +0 -0
  84. data/app/assets/images/brightcontent/glyphicons-halflings-white.png +0 -0
  85. data/app/assets/images/brightcontent/glyphicons-halflings.png +0 -0
  86. data/app/assets/javascripts/brightcontent/attachments.js +0 -0
  87. data/app/assets/javascripts/brightcontent/bootstrap.min.js +0 -6
  88. data/app/assets/javascripts/brightcontent/brightcontent.js +0 -21
  89. data/app/assets/javascripts/brightcontent/main.js +0 -26
  90. data/app/assets/javascripts/brightcontent/pages.js +0 -0
  91. data/app/assets/stylesheets/brightcontent/attachments.css +0 -0
  92. data/app/assets/stylesheets/brightcontent/bootstrap-responsive.min.css +0 -9
  93. data/app/assets/stylesheets/brightcontent/bootstrap.min.css +0 -9
  94. data/app/assets/stylesheets/brightcontent/brightcontent.css +0 -19
  95. data/app/assets/stylesheets/brightcontent/main.css +0 -95
  96. data/app/assets/stylesheets/brightcontent/pages.css +0 -0
  97. data/app/views/brightcontent/base/_index_top.html.erb +0 -0
  98. data/app/views/brightcontent/base/_list.html.erb +0 -8
  99. data/app/views/brightcontent/base/_scope_filters.html.erb +0 -9
  100. data/config/initializers/will_paginate.rb +0 -28
  101. data/config/locales/brightcontent.en.yml +0 -10
  102. data/config/locales/brightcontent.nl.yml +0 -10
  103. data/lib/brightcontent/default_actions.rb +0 -28
  104. data/lib/brightcontent/pagination.rb +0 -28
  105. data/spec/features/scope_spec.rb +0 -27
@@ -43,15 +43,11 @@ module Dummy
43
43
  # like if you have constraints or database-specific column types
44
44
  # config.active_record.schema_format = :sql
45
45
 
46
- # Enforce whitelist mode for mass assignment.
47
- # This will create an empty whitelist of attributes available for mass-assignment for all models
48
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
- # parameters by using an attr_accessible or attr_protected declaration.
50
- config.active_record.whitelist_attributes = false
51
-
52
46
  # Enable the asset pipeline
53
47
  config.assets.enabled = true
54
48
 
49
+ # config.i18n.enforce_available_locales = true
50
+
55
51
  # Version of your assets, change this if you want to expire all your assets
56
52
  config.assets.version = '1.0'
57
53
  end
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.configure do
2
+ config.eager_load = false
2
3
  # Settings specified here will take precedence over those in config/application.rb
3
4
 
4
5
  # In the development environment your application's code is reloaded on
@@ -6,9 +7,6 @@ Dummy::Application.configure do
6
7
  # since you don't have to restart the web server when you make code changes.
7
8
  config.cache_classes = false
8
9
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
10
  # Show full error reports and disable caching
13
11
  config.consider_all_requests_local = true
14
12
  config.action_controller.perform_caching = false
@@ -22,13 +20,6 @@ Dummy::Application.configure do
22
20
  # Only use best-standards-support built into browsers
23
21
  config.action_dispatch.best_standards_support = :builtin
24
22
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
31
-
32
23
  # Do not compress assets
33
24
  config.assets.compress = false
34
25
 
@@ -60,8 +60,4 @@ Dummy::Application.configure do
60
60
 
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
-
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
63
  end
@@ -1,4 +1,6 @@
1
1
  Dummy::Application.configure do
2
+ config.eager_load = false
3
+
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
4
6
  # The test environment is used exclusively to run your application's
@@ -11,9 +13,6 @@ Dummy::Application.configure do
11
13
  config.serve_static_assets = true
12
14
  config.static_cache_control = "public, max-age=3600"
13
15
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
16
  # Show full error reports and disable caching
18
17
  config.consider_all_requests_local = true
19
18
  config.action_controller.perform_caching = false
@@ -29,9 +28,6 @@ Dummy::Application.configure do
29
28
  # ActionMailer::Base.deliveries array.
30
29
  config.action_mailer.delivery_method = :test
31
30
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
31
  # Print deprecation notices to the stderr
36
32
  config.active_support.deprecation = :stderr
37
33
  end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '1582af16879d84e4319aa02ea51964c7c27576e6468838ea1bcadf1286623d44e9117613a747386fde1bc2253a9a49c291a2c100fec64ae5c2cc5c75efa553ef'
7
+ Dummy::Application.config.secret_key_base = '1582af16879d84e4319aa02ea51964c7c27576e6468838ea1bcadf1286623d44e9117613a747386fde1bc2253a9a49c291a2c100fec64ae5c2cc5c75efa553ef'
@@ -1,7 +1,6 @@
1
1
  class CreateComments < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :comments do |t|
4
- t.string :id
5
4
  t.text :text
6
5
  t.integer :blog_id
7
6
 
@@ -0,0 +1,5 @@
1
+ class AddAuthorIdToBlogs < ActiveRecord::Migration
2
+ def change
3
+ add_reference :blogs, :author
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAuthors < ActiveRecord::Migration
2
+ def change
3
+ create_table :authors do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -9,32 +9,39 @@
9
9
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
10
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
11
  #
12
- # It's strongly recommended to check this file into your version control system.
12
+ # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130720211920) do
14
+ ActiveRecord::Schema.define(version: 20140512090832) do
15
15
 
16
- create_table "blogs", :force => true do |t|
16
+ create_table "authors", force: true do |t|
17
+ t.string "name"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "blogs", force: true do |t|
17
23
  t.string "name"
18
24
  t.text "body"
19
- t.datetime "created_at", :null => false
20
- t.datetime "updated_at", :null => false
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
21
27
  t.boolean "featured"
28
+ t.integer "author_id"
22
29
  end
23
30
 
24
- create_table "brightcontent_admin_users", :force => true do |t|
31
+ create_table "brightcontent_admin_users", force: true do |t|
25
32
  t.string "email"
26
33
  t.string "password_digest"
27
- t.datetime "created_at", :null => false
28
- t.datetime "updated_at", :null => false
34
+ t.datetime "created_at"
35
+ t.datetime "updated_at"
29
36
  end
30
37
 
31
- create_table "comments", :force => true do |t|
38
+ create_table "comments", force: true do |t|
32
39
  t.text "text"
33
40
  t.integer "blog_id"
34
- t.datetime "created_at", :null => false
35
- t.datetime "updated_at", :null => false
41
+ t.datetime "created_at"
42
+ t.datetime "updated_at"
36
43
  end
37
44
 
38
- add_index "comments", ["blog_id"], :name => "index_comments_on_blog_id"
45
+ add_index "comments", ["blog_id"], name: "index_comments_on_blog_id"
39
46
 
40
47
  end
data/spec/factories.rb CHANGED
@@ -13,5 +13,20 @@ FactoryGirl.define do
13
13
  name "Blogname"
14
14
  body "Inhoud"
15
15
  featured false
16
+
17
+ factory :featured_blog do
18
+ featured true
19
+ end
20
+ end
21
+
22
+ factory :author do
23
+ factory :author_with_blogs do
24
+ ignore do
25
+ blogs_count 5
26
+ end
27
+ after(:create) do |author, evaluator|
28
+ create_list(:blog, evaluator.blogs_count, author: author)
29
+ end
30
+ end
16
31
  end
17
32
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Login" do
4
-
5
4
  scenario "Login with invalid credentials" do
6
5
  sign_in_with_invalid_email
7
6
  page.should have_content "invalid"
@@ -9,7 +8,9 @@ feature "Login" do
9
8
 
10
9
  scenario "Login with valid credentials" do
11
10
  sign_in
12
- page.should have_content "Admin users"
11
+ within "h1" do
12
+ page.should have_content "Blogs"
13
+ end
13
14
  end
14
15
 
15
16
  scenario "User logs out" do
@@ -25,5 +26,4 @@ feature "Login" do
25
26
  fill_in "Password", with: "wrongpass"
26
27
  click_button "Login"
27
28
  end
28
-
29
29
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Menu" do
4
-
5
4
  scenario "Shows default menu" do
6
5
  sign_in
7
6
  menu_should_not_have_link "Sessions"
@@ -13,15 +12,14 @@ feature "Menu" do
13
12
  end
14
13
 
15
14
  def menu_should_have_link(link_name)
16
- within "#menu" do
15
+ within ".js-menu" do
17
16
  page.should have_link link_name
18
17
  end
19
18
  end
20
19
 
21
20
  def menu_should_not_have_link(link_name)
22
- within "#menu" do
21
+ within ".js-menu" do
23
22
  page.should have_no_link link_name
24
23
  end
25
24
  end
26
-
27
25
  end
@@ -23,7 +23,7 @@ feature "Nested resource" do
23
23
 
24
24
  def create_comment(title)
25
25
  visit brightcontent.blog_comments_path(blog)
26
- click_link "Create new Comment"
26
+ click_link "Create new comment"
27
27
  fill_in "Text", with: title
28
28
  click_button "Create Comment"
29
29
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Resources form" do
4
-
5
4
  scenario "Adds a new item" do
6
5
  sign_in
7
6
  create_blog "Name for blogitem"
@@ -24,7 +23,7 @@ feature "Resources form" do
24
23
 
25
24
  def create_blog(title)
26
25
  visit brightcontent.blogs_url
27
- click_link "Create new Blog"
26
+ click_link "Create new blog"
28
27
  fill_in "Name", with: title
29
28
  click_button "Create Blog"
30
29
  end
@@ -47,5 +46,4 @@ feature "Resources form" do
47
46
  yield
48
47
  end
49
48
  end
50
-
51
49
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  feature "Resources index" do
4
-
5
4
  background do
6
5
  sign_in
7
6
  end
@@ -23,15 +22,31 @@ feature "Resources index" do
23
22
  given_10_per_page
24
23
  given_31_blog_items
25
24
  visit_blogs_page
26
- page.should have_css("tbody tr", :count => 10)
25
+ page_should_have_n_rows 10
26
+ end
27
+
28
+ scenario "Filter by 'featured'" do
29
+ given_31_blog_items
30
+ visit_blogs_page
31
+ select "true", from: "Featured"
32
+ click_button "Search"
33
+ page_should_have_n_rows 6
34
+ end
35
+
36
+ scenario "Filter by author" do
37
+ given_20_blogs_from_two_authors
38
+ visit_blogs_page
39
+ select "Bob", from: "Author"
40
+ click_button "Search"
41
+ page_should_have_n_rows 9
27
42
  end
28
43
 
29
44
  def visit_blogs_page
30
- click_link "Blog"
45
+ click_link "Blogs"
31
46
  end
32
47
 
33
48
  def page_should_have_valid_table
34
- within "#overview" do
49
+ within ".panel" do
35
50
  page.should have_content "Blogs"
36
51
  page.should have_content "Name"
37
52
  page.should have_content "Body"
@@ -39,12 +54,21 @@ feature "Resources index" do
39
54
  end
40
55
  end
41
56
 
57
+ def page_should_have_n_rows(n)
58
+ page.should have_css("tbody tr", :count => n)
59
+ end
60
+
42
61
  def given_31_blog_items
43
- 31.times { create :blog }
62
+ 25.times { create :blog }
63
+ 6.times { create :featured_blog }
64
+ end
65
+
66
+ def given_20_blogs_from_two_authors
67
+ create(:author_with_blogs, blogs_count: 11, name: "Alice")
68
+ create(:author_with_blogs, blogs_count: 9, name: "Bob")
44
69
  end
45
70
 
46
71
  def given_10_per_page
47
72
  Brightcontent::BlogsController.class_eval { per_page 10 }
48
73
  end
49
-
50
74
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brightcontent::TranslationHelper do
4
+ let(:string) { "thing" }
5
+ let(:model) { Brightcontent::AdminUser }
6
+
7
+ describe '#nominative_plural' do
8
+ it "pluralizes strings" do
9
+ expect(nominative_plural(string)).to eq("things")
10
+ end
11
+
12
+ it "pluralizes active record models" do
13
+ expect(nominative_plural(model)).to eq("Admins")
14
+ end
15
+ end
16
+
17
+ describe '#nominative_singular' do
18
+ it "returns a singular strings" do
19
+ expect(nominative_singular(string)).to eq("thing")
20
+ end
21
+
22
+ it "deals with active record models" do
23
+ expect(nominative_singular(model)).to eq("Admin")
24
+ end
25
+ end
26
+
27
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module Brightcontent
4
4
  describe ModelExtensions do
5
- let(:columns) { ["id", "name", "body", "created_at", "updated_at", "featured"] }
5
+ let(:columns) { ["id", "name", "body", "created_at", "updated_at", "featured", "author_id"] }
6
6
  subject(:blog) { Blog }
7
7
  its(:brightcontent_columns) { should eq columns }
8
8
 
@@ -0,0 +1,16 @@
1
+ require 'brightcontent/resource'
2
+
3
+ describe Brightcontent::Resource do
4
+ FakeBlog = Module.new
5
+ Brightcontent::FakeComment = Module.new
6
+
7
+ describe '.klass' do
8
+ it 'returns the class of the path' do
9
+ expect(described_class.new('fake_blog').klass).to eq FakeBlog
10
+ end
11
+
12
+ it 'returns the brightcontent namespaces path if not exist' do
13
+ expect(described_class.new('fake_comment').klass).to eq Brightcontent::FakeComment
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,67 @@
1
+ require 'brightcontent/resources'
2
+
3
+ module Brightcontent
4
+ describe Resources do
5
+
6
+ let(:array) { [1, 2, 3, 4, 5] }
7
+ let(:resources) { Resources.new(array) }
8
+
9
+ it 'behaves like an array' do
10
+ expect(resources).to eq array
11
+ end
12
+
13
+ context 'main menu count of 4' do
14
+ before do
15
+ allow(Brightcontent).to receive(:main_menu_count) { 4 }
16
+ end
17
+
18
+ it 'gives the main menu items (with extra counting as an item)' do
19
+ expect(resources.main_menu).to eq [1, 2, 3]
20
+ end
21
+
22
+ it 'gives the extra menu items' do
23
+ expect(resources.extra_menu).to eq [4, 5]
24
+ end
25
+
26
+ it 'does have any exta menu items' do
27
+ expect(resources.extra_menu?).to be_true
28
+ end
29
+ end
30
+
31
+ context 'main menu count of 5' do
32
+ before do
33
+ allow(Brightcontent).to receive(:main_menu_count) { 5 }
34
+ end
35
+
36
+ it 'gives the main menu items' do
37
+ expect(resources.main_menu).to eq array
38
+ end
39
+
40
+ it 'gives the extra menu items' do
41
+ expect(resources.extra_menu).to eq []
42
+ end
43
+
44
+ it 'does not have any exta menu items' do
45
+ expect(resources.extra_menu?).to be_false
46
+ end
47
+ end
48
+
49
+ context 'main menu count of 6' do
50
+ before do
51
+ allow(Brightcontent).to receive(:main_menu_count) { 6 }
52
+ end
53
+
54
+ it 'gives the main menu items' do
55
+ expect(resources.main_menu).to eq array
56
+ end
57
+
58
+ it 'gives the extra menu items' do
59
+ expect(resources.extra_menu).to eq []
60
+ end
61
+
62
+ it 'does not have any exta menu items' do
63
+ expect(resources.extra_menu?).to be_false
64
+ end
65
+ end
66
+ end
67
+ end
@@ -12,11 +12,11 @@ module Brightcontent
12
12
 
13
13
  subject(:parser) { RoutesParser.new(routes_hash, engine_resources) }
14
14
 
15
- its(:resources) { should eq [resource("blogs")] }
15
+ its(:resources) { should eq [Resource.new("blogs")] }
16
16
 
17
17
  context "with extra resource" do
18
18
  before { routes_hash << {:action=>"index", :controller=>"brightcontent/articles", :path_spec => '/articles' } }
19
- its(:resources) { should eq [resource("blogs"), resource("articles")] }
19
+ its(:resources) { should eq [Resource.new("blogs"), Resource.new("articles")] }
20
20
  end
21
21
 
22
22
  context "with engine resources" do
@@ -25,7 +25,7 @@ module Brightcontent
25
25
  routes_hash << {:action=>"index", :controller=>"brightcontent/#{resource_name}"}
26
26
  end
27
27
  end
28
- its(:resources) { should eq [resource("blogs")] }
28
+ its(:resources) { should eq [Resource.new("blogs")] }
29
29
  end
30
30
 
31
31
  context "duplicate resources" do
@@ -33,12 +33,7 @@ module Brightcontent
33
33
  routes_hash << {action: "index", controller: "brightcontent/blogs" }
34
34
  end
35
35
 
36
- its(:resources) { should eq [resource("blogs")] }
36
+ its(:resources) { should eq [Resource.new("blogs")] }
37
37
  end
38
-
39
- def resource(path)
40
- RoutesParser::Resource.new(path)
41
- end
42
-
43
38
  end
44
39
  end
@@ -0,0 +1,40 @@
1
+ require 'brightcontent/view_lookup/abstract'
2
+
3
+ module Brightcontent::ViewLookup
4
+ describe Abstract do
5
+ class FakeFormField < Abstract
6
+ def field_type
7
+ :string
8
+ end
9
+ end
10
+
11
+ let(:view_context) { double(:view_context) }
12
+ let(:item) { double(:item, name: 'Item name') }
13
+ let(:fake_form_field) { FakeFormField.new(view_context, field: 'name', item: item) }
14
+
15
+ context 'with specific field partial' do
16
+ it 'renders the parial' do
17
+ expect(view_context).to receive(:render_if_exists)
18
+ .with("fake_form_field_name", {field: 'name', item: item}) { "Result" }
19
+ fake_form_field.call
20
+ end
21
+ end
22
+
23
+ context 'with specific field type partial' do
24
+ it 'renders the parial' do
25
+ expect(view_context).to receive(:render_if_exists).once
26
+ expect(view_context).to receive(:render_if_exists)
27
+ .with("brightcontent/base/fake_form_fields/string", {field: 'name', item: item}) { "Result" }
28
+ fake_form_field.call
29
+ end
30
+ end
31
+
32
+ context 'without partial' do
33
+ it 'renders the default value' do
34
+ expect(view_context).to receive(:render_if_exists).once
35
+ allow(fake_form_field).to receive(:field_type) { nil }
36
+ expect(fake_form_field.call).to eq 'Item name'
37
+ end
38
+ end
39
+ end
40
+ end