comfy_carousel 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -0
- data/LICENSE +20 -0
- data/README.md +35 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/slides.jquery.js +555 -0
- data/app/assets/javascripts/slides.min.jquery.js +20 -0
- data/app/controllers/admin/carousel/base_controller.rb +10 -0
- data/app/controllers/admin/carousel/carousels_controller.rb +50 -0
- data/app/controllers/admin/carousel/slides_controller.rb +12 -4
- data/app/helpers/carousel/application_helper.rb +12 -0
- data/app/models/carousel/carousel.rb +25 -0
- data/app/models/carousel/slide.rb +21 -17
- data/app/views/admin/carousel/_navigation.html.erb +1 -0
- data/app/views/admin/carousel/carousels/_form.html.erb +4 -0
- data/app/views/admin/carousel/carousels/edit.html.erb +5 -0
- data/app/views/admin/carousel/carousels/index.html.erb +20 -0
- data/app/views/admin/carousel/carousels/new.html.erb +5 -0
- data/app/views/admin/carousel/slides/_form.html.erb +12 -14
- data/app/views/admin/carousel/slides/edit.html.erb +4 -3
- data/app/views/admin/carousel/slides/index.html.erb +20 -21
- data/app/views/admin/carousel/slides/new.html.erb +4 -3
- data/comfy_carousel.gemspec +112 -0
- data/config/application.rb +3 -0
- data/config/environments/development.rb +1 -1
- data/config/environments/test.rb +1 -1
- data/config/initializers/comfy_carousel.rb +12 -0
- data/config/routes.rb +9 -1
- data/db/migrate/01_create_comfy_carousel.rb +17 -2
- data/db/schema.rb +40 -0
- data/lib/comfy_carousel.rb +25 -0
- data/lib/comfy_carousel/configuration.rb +22 -0
- data/lib/comfy_carousel/engine.rb +19 -0
- data/lib/comfy_carousel/form_builder.rb +50 -0
- data/lib/generators/comfy/carousel/README +11 -0
- data/lib/generators/comfy/carousel/carousel_generator.rb +35 -0
- data/lib/tasks/comfy_carousel.rake +4 -0
- data/test/fixtures/carousel/carousels.yml +3 -0
- data/test/fixtures/carousel/slides.yml +9 -0
- data/test/fixtures/files/image.jpg +0 -0
- data/test/functional/admin/carousel/carousels_controller_test.rb +92 -0
- data/test/functional/admin/carousel/slides_controller_test.rb +59 -30
- data/test/test_helper.rb +30 -5
- data/test/unit/carousel_test.rb +30 -0
- data/test/unit/configuration_test.rb +17 -0
- data/test/unit/slide_test.rb +29 -0
- metadata +49 -21
- data/app/assets/images/rails.png +0 -0
- data/app/assets/javascripts/application.js +0 -15
- data/app/assets/stylesheets/application.css +0 -13
- data/app/helpers/application_helper.rb +0 -2
- data/config/environments/production.rb +0 -67
- data/config/initializers/backtrace_silencers.rb +0 -7
- data/config/initializers/inflections.rb +0 -15
- data/config/initializers/mime_types.rb +0 -5
- data/config/initializers/secret_token.rb +0 -7
- data/config/initializers/session_store.rb +0 -8
- data/config/initializers/wrap_parameters.rb +0 -14
- data/db/seeds.rb +0 -7
- data/lib/assets/.gitkeep +0 -0
data/config/application.rb
CHANGED
@@ -11,6 +11,9 @@ end
|
|
11
11
|
|
12
12
|
module ComfyCarousel
|
13
13
|
class Application < Rails::Application
|
14
|
+
|
15
|
+
require 'comfy_carousel'
|
16
|
+
|
14
17
|
# Settings in config/environments/* take precedence over those specified here.
|
15
18
|
# Application configuration should go into files in config/initializers
|
16
19
|
# -- all .rb files in that directory are automatically loaded.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
ComfyCarousel::Application.configure do
|
1
|
+
defined?(ComfyCarousel::Application) && ComfyCarousel::Application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb
|
3
3
|
|
4
4
|
# In the development environment your application's code is reloaded on
|
data/config/environments/test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
ComfyCarousel::Application.configure do
|
1
|
+
defined?(ComfyCarousel::Application) && ComfyCarousel::Application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb
|
3
3
|
|
4
4
|
# The test environment is used exclusively to run your application's
|
@@ -0,0 +1,12 @@
|
|
1
|
+
ComfyCarousel.configure do |config|
|
2
|
+
|
3
|
+
# set the cms admin path if you have changed it for CMS
|
4
|
+
# config.admin_route_prefix = 'admin'
|
5
|
+
|
6
|
+
# Controller that should be used for admin area
|
7
|
+
# config.admin_controller = 'ApplicationController'
|
8
|
+
|
9
|
+
# Form builder
|
10
|
+
# config.form_builder = 'ComfyBlog::FormBuilder'
|
11
|
+
|
12
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
|
3
|
+
namespace :admin, :path => ComfyCarousel.config.admin_route_prefix do
|
4
|
+
namespace :carousel do
|
5
|
+
resources :carousels, :except => [:show] do
|
6
|
+
resources :slides, :except => [:show] do
|
7
|
+
put :reorder, :on => :collection
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end unless ComfyCarousel.config.admin_route_prefix.blank?
|
4
12
|
|
5
13
|
end
|
@@ -1,14 +1,29 @@
|
|
1
1
|
class CreateComfyCarousel < ActiveRecord::Migration
|
2
2
|
|
3
3
|
def self.up
|
4
|
-
create_table :
|
5
|
-
|
4
|
+
create_table :carousel_carousels do |t|
|
5
|
+
t.string :label, :null => false
|
6
|
+
t.string :identifier, :null => false
|
6
7
|
t.timestamps
|
7
8
|
end
|
9
|
+
add_index :carousel_carousels, :identifier
|
8
10
|
|
11
|
+
create_table :carousel_slides do |t|
|
12
|
+
t.integer :carousel_id, :null => false
|
13
|
+
t.string :label, :null => false
|
14
|
+
t.text :content
|
15
|
+
t.string :url
|
16
|
+
t.string :file_file_name
|
17
|
+
t.string :file_content_type
|
18
|
+
t.integer :file_file_size
|
19
|
+
t.integer :position, :null => false, :default => 0
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
add_index :carousel_slides, [:carousel_id, :position]
|
9
23
|
end
|
10
24
|
|
11
25
|
def self.down
|
26
|
+
drop_table :carousel_carousels
|
12
27
|
drop_table :carousel_slides
|
13
28
|
end
|
14
29
|
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 1) do
|
15
|
+
|
16
|
+
create_table "carousel_carousels", :force => true do |t|
|
17
|
+
t.string "label", :null => false
|
18
|
+
t.string "identifier", :null => false
|
19
|
+
t.datetime "created_at", :null => false
|
20
|
+
t.datetime "updated_at", :null => false
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index "carousel_carousels", ["identifier"], :name => "index_carousel_carousels_on_identifier"
|
24
|
+
|
25
|
+
create_table "carousel_slides", :force => true do |t|
|
26
|
+
t.integer "carousel_id", :null => false
|
27
|
+
t.string "label", :null => false
|
28
|
+
t.text "content"
|
29
|
+
t.string "url"
|
30
|
+
t.string "file_file_name"
|
31
|
+
t.string "file_content_type"
|
32
|
+
t.integer "file_file_size"
|
33
|
+
t.integer "position", :default => 0, :null => false
|
34
|
+
t.datetime "created_at", :null => false
|
35
|
+
t.datetime "updated_at", :null => false
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index "carousel_slides", ["carousel_id", "position"], :name => "index_carousel_slides_on_carousel_id_and_position"
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Loading engine only if this is not a standalone installation
|
2
|
+
unless defined? ComfyCarousel::Application
|
3
|
+
require File.expand_path('comfy_carousel/engine', File.dirname(__FILE__))
|
4
|
+
end
|
5
|
+
|
6
|
+
[ 'comfy_carousel/configuration',
|
7
|
+
'comfy_carousel/form_builder'
|
8
|
+
].each do |path|
|
9
|
+
require File.expand_path(path, File.dirname(__FILE__))
|
10
|
+
end
|
11
|
+
|
12
|
+
module ComfyCarousel
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
alias :config :configuration
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ComfyCarousel
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
# Default url to access admin area is http://yourhost/cms-admin/
|
5
|
+
# You can change 'cms-admin' to 'admin', for example.
|
6
|
+
attr_accessor :admin_route_prefix
|
7
|
+
|
8
|
+
# Controller that should be used for admin area
|
9
|
+
attr_accessor :admin_controller
|
10
|
+
|
11
|
+
# Form builder
|
12
|
+
attr_accessor :form_builder
|
13
|
+
|
14
|
+
# Configuration defaults
|
15
|
+
def initialize
|
16
|
+
@admin_route_prefix = 'admin'
|
17
|
+
@admin_controller = 'ApplicationController'
|
18
|
+
@form_builder = 'ComfyCarousel::FormBuilder'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'comfy_carousel'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module ComfyCarousel
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
initializer 'comfy_carousel.configuration' do |app|
|
7
|
+
if defined?(ComfortableMexicanSofa)
|
8
|
+
# Applying configuraion
|
9
|
+
ComfyCarousel.configure do |conf|
|
10
|
+
conf.admin_route_prefix = ComfortableMexicanSofa.config.admin_route_prefix
|
11
|
+
conf.admin_controller = 'CmsAdmin::BaseController'
|
12
|
+
conf.form_builder = 'ComfortableMexicanSofa::FormBuilder'
|
13
|
+
end
|
14
|
+
# Adding view hooks
|
15
|
+
ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/carousel/navigation')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class ComfyCarousel::FormBuilder < ActionView::Helpers::FormBuilder
|
2
|
+
|
3
|
+
helpers = field_helpers -
|
4
|
+
%w(hidden_field fields_for) +
|
5
|
+
%w(select)
|
6
|
+
|
7
|
+
helpers.each do |name|
|
8
|
+
class_eval %Q^
|
9
|
+
def #{name}(field, *args)
|
10
|
+
options = args.extract_options!
|
11
|
+
args << options
|
12
|
+
return super if options.delete(:disable_builder)
|
13
|
+
default_field('#{name}', field, options){ super }
|
14
|
+
end
|
15
|
+
^
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_field(type, field, options = {}, &block)
|
19
|
+
errors = if object.respond_to?(:errors) && object.errors[field].present?
|
20
|
+
"<div class='errors'>#{[object.errors[field]].flatten.first}</div>"
|
21
|
+
end
|
22
|
+
if desc = options.delete(:desc)
|
23
|
+
desc = "<div class='desc'>#{desc}</div>"
|
24
|
+
end
|
25
|
+
%(
|
26
|
+
<div class='form_element #{type}_element #{'errors' if errors}'>
|
27
|
+
<div class='label'>#{label_for(field, options)}</div>
|
28
|
+
<div class='value'>#{yield}</div>
|
29
|
+
#{desc}
|
30
|
+
#{errors}
|
31
|
+
</div>
|
32
|
+
).html_safe
|
33
|
+
end
|
34
|
+
|
35
|
+
def label_for(field, options)
|
36
|
+
label = options.delete(:label) || field.to_s.titleize.capitalize
|
37
|
+
"<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
def simple_field(label = nil, content = nil, options = {}, &block)
|
41
|
+
content ||= @template.capture(&block) if block_given?
|
42
|
+
%(
|
43
|
+
<div class='form_element #{options.delete(:class)}'>
|
44
|
+
<div class='label'>#{label}</div>
|
45
|
+
<div class='value'>#{content}</div>
|
46
|
+
</div>
|
47
|
+
).html_safe
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
____ __ ____ _
|
2
|
+
/ ___|___ _ __ ___ / _|_ _ / ___|__ _ _ __ ___ _ _ ___ ___| |
|
3
|
+
| | / _ \| '_ ` _ \| |_| | | | | / _` | '__/ _ \| | | / __|/ _ \ |
|
4
|
+
| |__| (_) | | | | | | _| |_| | |__| (_| | | | (_) | |_| \__ \ __/ |
|
5
|
+
\____\___/|_| |_| |_|_| \__, |\____\__,_|_| \___/ \__,_|___/\___|_|
|
6
|
+
|___/
|
7
|
+
|
8
|
+
Hey! Everything is almost done. Please don't forget to
|
9
|
+
|
10
|
+
* run migrations -> `rake db:migrate`
|
11
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Comfy
|
2
|
+
module Generators
|
3
|
+
class CarouselGenerator < Rails::Generators::Base
|
4
|
+
require 'rails/generators/active_record'
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
source_root File.expand_path('../../../../..', __FILE__)
|
9
|
+
|
10
|
+
def generate_migration
|
11
|
+
destination = File.expand_path('db/migrate/01_create_comfy_carousel.rb', self.destination_root)
|
12
|
+
migration_dir = File.dirname(destination)
|
13
|
+
destination = self.class.migration_exists?(migration_dir, 'create_comfy_carousel')
|
14
|
+
|
15
|
+
if destination
|
16
|
+
puts "\e[0m\e[31mFound existing create_comfy_carousel.rb migration. Remove it if you want to regenerate.\e[0m"
|
17
|
+
else
|
18
|
+
migration_template 'db/migrate/01_create_comfy_carousel.rb', 'db/migrate/create_comfy_carousel.rb'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_initialization
|
23
|
+
copy_file 'config/initializers/comfy_carousel.rb', 'config/initializers/comfy_carousel.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_readme
|
27
|
+
readme 'lib/generators/comfy/carousel/README'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.next_migration_number(dirname)
|
31
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
Binary file
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Admin::Carousel::CarouselsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert_template :index
|
9
|
+
assert assigns(:carousels)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_new
|
13
|
+
get :new
|
14
|
+
assert_response :success
|
15
|
+
assert_template :new
|
16
|
+
assert_select "form[action='/admin/carousel/carousels']"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_edit
|
20
|
+
carousel = carousel_carousels(:default)
|
21
|
+
get :edit, :id => carousel
|
22
|
+
assert_response :success
|
23
|
+
assert_template :edit
|
24
|
+
assert_select "form[action='/admin/carousel/carousels/#{carousel.id}']"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_edit_failure
|
28
|
+
get :edit, :id => 'invalid'
|
29
|
+
assert_response :redirect
|
30
|
+
assert_redirected_to :action => :index
|
31
|
+
assert_equal 'Carousel not found', flash[:error]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_creation
|
35
|
+
assert_difference 'Carousel::Carousel.count' do
|
36
|
+
post :create, :carousel => {
|
37
|
+
:label => 'Test',
|
38
|
+
:identifier => 'test'
|
39
|
+
}
|
40
|
+
assert_response :redirect
|
41
|
+
assert_redirected_to new_admin_carousel_carousel_slide_path(assigns(:carousel))
|
42
|
+
assert_equal 'Carousel created', flash[:notice]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_creation_failure
|
47
|
+
assert_no_difference 'Carousel::Carousel.count' do
|
48
|
+
post :create, :carousel => { }
|
49
|
+
assert_response :success
|
50
|
+
assert_template :new
|
51
|
+
assert_equal 'Failed to create Carousel', flash[:error]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_update
|
56
|
+
carousel = carousel_carousels(:default)
|
57
|
+
|
58
|
+
put :update, :id => carousel, :carousel => {
|
59
|
+
:label => 'Updated'
|
60
|
+
}
|
61
|
+
assert_response :redirect
|
62
|
+
assert_redirected_to :action => :edit, :id => carousel
|
63
|
+
assert_equal 'Carousel updated', flash[:notice]
|
64
|
+
|
65
|
+
carousel.reload
|
66
|
+
assert_equal 'Updated', carousel.label
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_update_failure
|
70
|
+
carousel = carousel_carousels(:default)
|
71
|
+
|
72
|
+
put :update, :id => carousel, :carousel => {
|
73
|
+
:identifier => ''
|
74
|
+
}
|
75
|
+
assert_response :success
|
76
|
+
assert_template :edit
|
77
|
+
assert_equal 'Failed to update Carousel', flash[:error]
|
78
|
+
|
79
|
+
carousel.reload
|
80
|
+
assert_not_equal '', carousel.identifier
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_destroy
|
84
|
+
assert_difference 'Carousel::Carousel.count', -1 do
|
85
|
+
delete :destroy, :id => carousel_carousels(:default)
|
86
|
+
assert_response :redirect
|
87
|
+
assert_redirected_to :action => :index
|
88
|
+
assert_equal 'Carousel removed', flash[:notice]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -1,53 +1,60 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class Admin::SlidesControllerTest < ActionController::TestCase
|
3
|
+
class Admin::Carousel::SlidesControllerTest < ActionController::TestCase
|
4
4
|
|
5
5
|
def test_get_index
|
6
|
-
get :index
|
6
|
+
get :index, :carousel_id => carousel_carousels(:default)
|
7
7
|
assert_response :success
|
8
8
|
assert_template :index
|
9
9
|
assert assigns(:slides)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_get_new
|
13
|
-
|
13
|
+
carousel = carousel_carousels(:default)
|
14
|
+
get :new, :carousel_id => carousel
|
14
15
|
assert_response :success
|
15
16
|
assert_template :new
|
16
17
|
assert assigns(:slide)
|
18
|
+
assert_select "form[action='/admin/carousel/carousels/#{carousel.id}/slides']"
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_get_edit
|
20
|
-
|
22
|
+
carousel = carousel_carousels(:default)
|
23
|
+
slide = carousel_slides(:default)
|
24
|
+
|
25
|
+
get :edit, :carousel_id => carousel, :id => slide
|
21
26
|
assert_response :success
|
22
27
|
assert_template :edit
|
23
28
|
assert assigns(:slide)
|
29
|
+
assert_select "form[action='/admin/carousel/carousels/#{carousel.id}/slides/#{slide.id}']"
|
24
30
|
end
|
25
31
|
|
26
32
|
def test_get_edit_failure
|
27
|
-
get :edit, :id => 'invalid'
|
33
|
+
get :edit, :carousel_id => carousel_carousels(:default), :id => 'invalid'
|
28
34
|
assert_response :redirect
|
29
35
|
assert_redirected_to :action => :index
|
30
36
|
assert_equal 'Slide not found', flash[:error]
|
31
37
|
end
|
32
38
|
|
33
39
|
def test_creation
|
34
|
-
assert_difference 'Slide.count' do
|
35
|
-
post :create, :slide => {
|
36
|
-
:
|
37
|
-
:url
|
38
|
-
:
|
39
|
-
:sort => 1
|
40
|
+
assert_difference 'Carousel::Slide.count' do
|
41
|
+
post :create, :carousel_id => carousel_carousels(:default), :slide => {
|
42
|
+
:label => 'Test',
|
43
|
+
:url => 'http://test.test',
|
44
|
+
:content => 'Test Slide'
|
40
45
|
}
|
41
46
|
assert_response :redirect
|
42
47
|
assert_redirected_to :action => :index
|
43
|
-
|
44
|
-
|
48
|
+
assert_equal 'Slide created', flash[:notice]
|
49
|
+
|
50
|
+
slide = Carousel::Slide.last
|
51
|
+
assert_equal 'Test', slide.label
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
48
55
|
def test_creation_failure
|
49
|
-
assert_no_difference 'Slide.count' do
|
50
|
-
post :create, :slide => { }
|
56
|
+
assert_no_difference 'Carousel::Slide.count' do
|
57
|
+
post :create, :carousel_id => carousel_carousels(:default), :slide => { }
|
51
58
|
assert_response :success
|
52
59
|
assert_template :new
|
53
60
|
assert_equal 'Failed to create Slide', flash[:error]
|
@@ -55,38 +62,60 @@ class Admin::SlidesControllerTest < ActionController::TestCase
|
|
55
62
|
end
|
56
63
|
|
57
64
|
def test_update
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
:
|
63
|
-
:sort => 1
|
65
|
+
carousel = carousel_carousels(:default)
|
66
|
+
slide = carousel_slides(:default)
|
67
|
+
|
68
|
+
put :update, :carousel_id => carousel, :id => slide, :slide => {
|
69
|
+
:label => 'Updated'
|
64
70
|
}
|
65
71
|
assert_response :redirect
|
66
|
-
assert_redirected_to :action => :edit
|
72
|
+
assert_redirected_to :action => :edit, :id => slide
|
73
|
+
assert_equal 'Slide updated', flash[:notice]
|
74
|
+
|
67
75
|
slide.reload
|
68
|
-
assert_equal '
|
76
|
+
assert_equal 'Updated', slide.label
|
69
77
|
end
|
70
78
|
|
71
79
|
def test_update_failure
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
carousel = carousel_carousels(:default)
|
81
|
+
slide = carousel_slides(:default)
|
82
|
+
|
83
|
+
put :update, :carousel_id => carousel, :id => slide, :slide => {
|
84
|
+
:label => ''
|
75
85
|
}
|
76
86
|
assert_response :success
|
77
87
|
assert_template :edit
|
78
88
|
assert_equal 'Failed to update Slide', flash[:error]
|
89
|
+
|
79
90
|
slide.reload
|
80
|
-
assert_not_equal '', slide.
|
91
|
+
assert_not_equal '', slide.label
|
81
92
|
end
|
82
93
|
|
83
94
|
def test_destroy
|
84
|
-
assert_difference 'Slide.count', -1 do
|
85
|
-
delete :destroy, :id =>
|
95
|
+
assert_difference 'Carousel::Slide.count', -1 do
|
96
|
+
delete :destroy, :carousel_id => carousel_carousels(:default), :id => carousel_slides(:default)
|
86
97
|
assert_response :redirect
|
87
98
|
assert_redirected_to :action => :index
|
88
99
|
assert_equal 'Slide deleted', flash[:notice]
|
89
100
|
end
|
90
101
|
end
|
102
|
+
|
103
|
+
def test_reorder
|
104
|
+
carousel = carousel_carousels(:default)
|
105
|
+
slide_one = carousel_slides(:default)
|
106
|
+
slide_two = carousel.slides.create!(
|
107
|
+
:label => 'test'
|
108
|
+
)
|
109
|
+
assert_equal 0, slide_one.position
|
110
|
+
assert_equal 1, slide_two.position
|
111
|
+
|
112
|
+
post :reorder, :carousel_id => carousel, :carousel_slide => [slide_two.id, slide_one.id]
|
113
|
+
assert_response :success
|
114
|
+
slide_one.reload
|
115
|
+
slide_two.reload
|
116
|
+
|
117
|
+
assert_equal 1, slide_one.position
|
118
|
+
assert_equal 0, slide_two.position
|
119
|
+
end
|
91
120
|
|
92
121
|
end
|