brightcontent-core 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightcontent-core (2.0.1)
4
+ brightcontent-core (2.0.2)
5
5
  bcrypt-ruby
6
6
  bootstrap-wysihtml5-rails
7
+ has_scope
7
8
  inherited_resources
8
9
  jquery-rails
9
10
  rails (~> 3.2.9)
@@ -3,6 +3,7 @@ require_dependency "brightcontent/application_controller"
3
3
  module Brightcontent
4
4
  class BaseController < ApplicationController
5
5
  inherit_resources
6
+ helper_method :scopes_configuration
6
7
 
7
8
  include DefaultActions
8
9
  include Pagination
@@ -8,6 +8,15 @@ module Brightcontent
8
8
  render_if_exists("form_field_#{field}", form: form, item: form.object) || form.input(field.to_sym)
9
9
  end
10
10
 
11
+ def link_for_scope(scope)
12
+ case scope[:type]
13
+ when :boolean
14
+ polymorphic_url(resource_class, scope[:as] => true)
15
+ end
16
+ end
17
+
18
+ private
19
+
11
20
  def render_if_exists(*args)
12
21
  render *args
13
22
  rescue ActionView::MissingTemplate
@@ -0,0 +1,4 @@
1
+ Show only:
2
+ <% scopes_configuration.each do |scope| %>
3
+ <%= link_to scope[1][:as].to_s.humanize, link_for_scope(scope[1]) %>
4
+ <% end %>
@@ -3,6 +3,9 @@
3
3
  <%= link_to "Create new #{resource_instance_name.to_s.humanize}", polymorphic_url(resource_class, action: :new), class: "btn btn-primary btn-right" %>
4
4
  <h1><%= resource_collection_name.to_s.humanize %></h1>
5
5
 
6
+ <% if scopes_configuration %>
7
+ <%= render "scope_filters" %>
8
+ <% end %>
6
9
  <table class="table table-hover">
7
10
  <thead>
8
11
  <tr>
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "jquery-rails"
20
20
  s.add_dependency "bcrypt-ruby"
21
21
  s.add_dependency "inherited_resources"
22
+ s.add_dependency "has_scope"
22
23
  s.add_dependency "simple_form"
23
24
  s.add_dependency "will_paginate"
24
25
  s.add_dependency "bootstrap-wysihtml5-rails"
@@ -3,6 +3,7 @@ require "simple_form"
3
3
  require "jquery-rails"
4
4
  require "will_paginate"
5
5
  require "bootstrap-wysihtml5-rails"
6
+ require "has_scope"
6
7
 
7
8
  require "brightcontent/rails/routes"
8
9
  require "brightcontent/engine"
@@ -1,2 +1,3 @@
1
1
  class Brightcontent::BlogsController < Brightcontent::BaseController
2
+ has_scope :featured, :type => :boolean
2
3
  end
@@ -1,3 +1,5 @@
1
1
  class Blog < ActiveRecord::Base
2
- attr_accessible :body, :name
2
+ attr_accessible :body, :name, :featured
3
+
4
+ scope :featured, where(:featured => true)
3
5
  end
@@ -0,0 +1,5 @@
1
+ class AddFeaturedToBlog < ActiveRecord::Migration
2
+ def change
3
+ add_column :blogs, :featured, :boolean
4
+ end
5
+ end
@@ -11,13 +11,14 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20121206225720) do
14
+ ActiveRecord::Schema.define(:version => 20121223131824) do
15
15
 
16
16
  create_table "blogs", :force => true do |t|
17
17
  t.string "name"
18
18
  t.text "body"
19
19
  t.datetime "created_at", :null => false
20
20
  t.datetime "updated_at", :null => false
21
+ t.boolean "featured"
21
22
  end
22
23
 
23
24
  create_table "brightcontent_admin_users", :force => true do |t|
data/spec/factories.rb CHANGED
@@ -12,5 +12,6 @@ FactoryGirl.define do
12
12
  factory :blog do
13
13
  name "Blogname"
14
14
  body "Inhoud"
15
+ featured false
15
16
  end
16
17
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Scope" do
4
+
5
+ background do
6
+ 2.times { create(:blog, name: "Featured", featured: true) }
7
+ 2.times { create(:blog, name: "Notfeatured", featured: false) }
8
+ sign_in
9
+ visit_blogs_page
10
+ end
11
+
12
+ scenario "Default shows all items" do
13
+ page.should have_content "Featured"
14
+ page.should have_content "Notfeatured"
15
+ end
16
+
17
+ scenario "filter featured only" do
18
+ click_link "Featured"
19
+ page.should have_content "Featured"
20
+ page.should_not have_content "Notfeatured"
21
+ end
22
+
23
+ def visit_blogs_page
24
+ click_link "Blogs"
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcontent-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: has_scope
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: simple_form
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +253,7 @@ files:
237
253
  - app/views/brightcontent/base/_form.html.erb
238
254
  - app/views/brightcontent/base/_list.html.erb
239
255
  - app/views/brightcontent/base/_list_actions.html.erb
256
+ - app/views/brightcontent/base/_scope_filters.html.erb
240
257
  - app/views/brightcontent/base/edit.html.erb
241
258
  - app/views/brightcontent/base/index.html.erb
242
259
  - app/views/brightcontent/base/new.html.erb
@@ -293,6 +310,7 @@ files:
293
310
  - spec/dummy/config/locales/en.yml
294
311
  - spec/dummy/config/routes.rb
295
312
  - spec/dummy/db/migrate/20121206225720_create_blogs.rb
313
+ - spec/dummy/db/migrate/20121223131824_add_featured_to_blog.rb
296
314
  - spec/dummy/db/schema.rb
297
315
  - spec/dummy/lib/assets/.gitkeep
298
316
  - spec/dummy/public/404.html
@@ -305,6 +323,7 @@ files:
305
323
  - spec/features/menu_spec.rb
306
324
  - spec/features/resources_form_spec.rb
307
325
  - spec/features/resources_index_spec.rb
326
+ - spec/features/scope_spec.rb
308
327
  - spec/lib/brightcontent/routes_parser_spec.rb
309
328
  - spec/spec_helper.rb
310
329
  - spec/support/acceptance_helper.rb
@@ -322,7 +341,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
322
341
  version: '0'
323
342
  segments:
324
343
  - 0
325
- hash: 701533251447277720
344
+ hash: -4292959386572265707
326
345
  required_rubygems_version: !ruby/object:Gem::Requirement
327
346
  none: false
328
347
  requirements:
@@ -331,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
331
350
  version: '0'
332
351
  segments:
333
352
  - 0
334
- hash: 701533251447277720
353
+ hash: -4292959386572265707
335
354
  requirements: []
336
355
  rubyforge_project:
337
356
  rubygems_version: 1.8.24
@@ -372,6 +391,7 @@ test_files:
372
391
  - spec/dummy/config/locales/en.yml
373
392
  - spec/dummy/config/routes.rb
374
393
  - spec/dummy/db/migrate/20121206225720_create_blogs.rb
394
+ - spec/dummy/db/migrate/20121223131824_add_featured_to_blog.rb
375
395
  - spec/dummy/db/schema.rb
376
396
  - spec/dummy/lib/assets/.gitkeep
377
397
  - spec/dummy/public/404.html
@@ -384,6 +404,7 @@ test_files:
384
404
  - spec/features/menu_spec.rb
385
405
  - spec/features/resources_form_spec.rb
386
406
  - spec/features/resources_index_spec.rb
407
+ - spec/features/scope_spec.rb
387
408
  - spec/lib/brightcontent/routes_parser_spec.rb
388
409
  - spec/spec_helper.rb
389
410
  - spec/support/acceptance_helper.rb