spree_zaez_banner 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Guardfile +90 -0
- data/LICENSE +26 -0
- data/README.md +66 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/app/banner_box_settings/banner_box_setting.js.coffee +65 -0
- data/app/assets/javascripts/spree/backend/app/banner_box_settings/banner_box_style.js.coffee +23 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_banner.js +1 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_banner.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_banner.css +6 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_banner.css +4 -0
- data/app/controllers/spree/admin/banner_box_settings_controller.rb +52 -0
- data/app/controllers/spree/admin/banner_boxes_controller.rb +54 -0
- data/app/helpers/spree/banner_boxes_helper.rb +39 -0
- data/app/models/spree/banner_box.rb +68 -0
- data/app/models/spree/banner_configuration.rb +10 -0
- data/app/overrides/spree/admin/shared/_main_menu/add_banner_tab_to_main_menu.html.erb.deface +6 -0
- data/app/views/spree/admin/banner_box_settings/edit.html.erb +104 -0
- data/app/views/spree/admin/banner_boxes/_form.html.erb +63 -0
- data/app/views/spree/admin/banner_boxes/edit.html.erb +10 -0
- data/app/views/spree/admin/banner_boxes/index.html.erb +80 -0
- data/app/views/spree/admin/banner_boxes/new.html.erb +17 -0
- data/app/views/spree/admin/shared/sub_menu/_banner.html.erb +4 -0
- data/app/views/spree/shared/_banner_box.html.erb +31 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +48 -0
- data/config/locales/pt-br.yml +48 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20120116204313_create_banners.rb +17 -0
- data/db/migrate/20120323174800_banner_namespace.rb +5 -0
- data/db/migrate/20131001104524_rename_presentation_to_alt_text.rb +5 -0
- data/db/migrate/20150721160059_add_display_period_to_spree_banner_boxes.rb +6 -0
- data/lib/generators/spree_zaez_banner/install/install_generator.rb +31 -0
- data/lib/spree_zaez_banner/engine.rb +24 -0
- data/lib/spree_zaez_banner/factories.rb +8 -0
- data/lib/spree_zaez_banner.rb +2 -0
- data/spec/features/admin/banner_box_settings_spec.rb +47 -0
- data/spec/features/admin/banner_boxes_spec.rb +126 -0
- data/spec/fixtures/spree.jpg +0 -0
- data/spec/models/spree/banner_box_spec.rb +58 -0
- data/spec/models/spree/banner_configuration_spec.rb +12 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/support/capybara_login.rb +13 -0
- data/spree_zaez_banner.gemspec +38 -0
- data/test +0 -0
- metadata +350 -0
data/bin/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_zaez_banner/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
en:
|
2
|
+
banners: Banners
|
3
|
+
images_only: "only available is JPG, JPEG, PNG o GIF"
|
4
|
+
banner_settings_updated: "Banner Settings successfully updated."
|
5
|
+
banner_boxes: Banners
|
6
|
+
banner_box: Banner
|
7
|
+
notice_messages:
|
8
|
+
banner_box_cloned: "Banner has been cloned"
|
9
|
+
banner_box_not_cloned: "Banner could not be cloned"
|
10
|
+
activerecord:
|
11
|
+
models:
|
12
|
+
banner_box:
|
13
|
+
one: Banner
|
14
|
+
other: Banners
|
15
|
+
attributes:
|
16
|
+
banner_box:
|
17
|
+
category: Category
|
18
|
+
updated_at: Updated At
|
19
|
+
created_at: Created At
|
20
|
+
enabled: Enabled?
|
21
|
+
begin_display: Begin Display
|
22
|
+
end_display: End Display
|
23
|
+
destroy: Destroy
|
24
|
+
confirm: Confirm
|
25
|
+
spree:
|
26
|
+
banners: Banners
|
27
|
+
banner_box_settings: Banner Settings
|
28
|
+
general_settings: General Settings
|
29
|
+
banner_styles: Paperclip Styles Banner
|
30
|
+
banner_path: Banner Path
|
31
|
+
banner_default_url: Banner Default URL
|
32
|
+
banner_url: Banner URL
|
33
|
+
banner_default_style: Banner Default Style
|
34
|
+
add_new_banner_style: Add New Banner Style
|
35
|
+
new_banner_style_name: Style Name
|
36
|
+
new_banner_style_value: Value
|
37
|
+
banner_settings_updated: Banner Settings successfully updated
|
38
|
+
listing_banner_boxes: Listing Banners
|
39
|
+
new_banner_box: New Banner Box
|
40
|
+
attachment: Attachment
|
41
|
+
enabled: Enabled
|
42
|
+
show_only_enabled: Show Only Enabled
|
43
|
+
url: URL
|
44
|
+
begin_display: Begin Display
|
45
|
+
end_display: End Display
|
46
|
+
previous: Previous
|
47
|
+
next: Next
|
48
|
+
banner_box_settings_warning: You will need to regenerate thumbnails if you update the paperclip styles. Use rake paperclip:refresh:thumbnails CLASS=Spree::BannerBox to do this.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
pt-BR:
|
2
|
+
banners: Banners
|
3
|
+
images_only: "apenas disponíveis os formatos JPG, JPEG, PNG o GIF"
|
4
|
+
banner_settings_updated: "Configurações do Banner atualizadas com sucesso."
|
5
|
+
banner_boxes: Banners
|
6
|
+
banner_box: Banner
|
7
|
+
notice_messages:
|
8
|
+
banner_box_cloned: "Banner foi clonado"
|
9
|
+
banner_box_not_cloned: "Banner não pode ser clonado"
|
10
|
+
activerecord:
|
11
|
+
models:
|
12
|
+
banner_box:
|
13
|
+
one: Banner
|
14
|
+
other: Banners
|
15
|
+
attributes:
|
16
|
+
banner_box:
|
17
|
+
category: Categoria
|
18
|
+
updated_at: Atualizado Em
|
19
|
+
created_at: Criado Em
|
20
|
+
enabled: Habilitado?
|
21
|
+
begin_display: Início da Exibição
|
22
|
+
end_display: Fim da Exibição
|
23
|
+
destroy: Excluir
|
24
|
+
confirm: Confirmar
|
25
|
+
spree:
|
26
|
+
banners: Banners
|
27
|
+
banner_box_settings: Configurações do Banner
|
28
|
+
general_settings: Configurações Principais
|
29
|
+
banner_styles: Estilo do Banner com Paperclip
|
30
|
+
banner_path: Caminho do Banner
|
31
|
+
banner_default_url: URL Padrão do Banner
|
32
|
+
banner_url: URL do Banner
|
33
|
+
banner_default_style: Estilo Padrão do Banner
|
34
|
+
add_new_banner_style: Adicionar Novo Estilo
|
35
|
+
new_banner_style_name: Nome do Estilo
|
36
|
+
new_banner_style_value: Valor
|
37
|
+
banner_settings_updated: Configurações do Banner atualizadas com sucesso
|
38
|
+
listing_banner_boxes: Listando Banners
|
39
|
+
new_banner_box: Novo Banner
|
40
|
+
attachment: Imagem
|
41
|
+
enabled: Habilitado
|
42
|
+
show_only_enabled: Exibir Apenas Habilitados
|
43
|
+
url: URL
|
44
|
+
begin_display: Início da Exibição
|
45
|
+
end_display: Fim da Exibição
|
46
|
+
previous: Anterior
|
47
|
+
next: Próximo
|
48
|
+
banner_box_settings_warning: Você deve gerar novamente as miniatura se você atualizar os estilos do Paperclip. Utilize rake paperclip:refresh:thumbnails CLASS=Spree::BannerBox para fazer isso.
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
|
3
|
+
namespace :admin do
|
4
|
+
resources :banner_boxes do
|
5
|
+
collection do
|
6
|
+
post :update_positions
|
7
|
+
end
|
8
|
+
member do
|
9
|
+
get :clone
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
resource :banner_box_settings, only: [:show, :edit, :update]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateBanners < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :banners do |t|
|
4
|
+
t.string :presentation, :url
|
5
|
+
t.string :category
|
6
|
+
t.integer :position
|
7
|
+
t.boolean :enabled, :default => false
|
8
|
+
|
9
|
+
t.string :attachment_content_type, :attachment_file_name
|
10
|
+
t.datetime :attachment_updated_at
|
11
|
+
t.integer :attachment_width, :attachment_height
|
12
|
+
t.integer :attachment_size
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeZaezBanner
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_zaez_banner\n"
|
9
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_zaez_banner\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_zaez_banner\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_zaez_banner\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_zaez_banner'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SpreeZaezBanner
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_zaez_banner'
|
6
|
+
|
7
|
+
# use rspec for tests
|
8
|
+
config.generators do |g|
|
9
|
+
g.test_framework :rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'spree_zaez_banner.preferences', :before => :load_config_initializers do |app|
|
13
|
+
Spree::BannerConfig = Spree::BannerConfiguration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.activate
|
17
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
18
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.to_prepare &method(:activate).to_proc
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Banner Box Settings', type: :feature do
|
4
|
+
before { create_admin_in_sign_in }
|
5
|
+
|
6
|
+
context 'visit Banner Box settings' do
|
7
|
+
it 'should be a link to Banner Box settings' do
|
8
|
+
within('.sidebar') { page.find_link('Banner Box Settings')['/admin/banner_box_settings/edit'] }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'show Banner Box settings' do
|
13
|
+
it 'should has the preferences of Banner Box', js: true do
|
14
|
+
visit spree.edit_admin_banner_box_settings_path
|
15
|
+
|
16
|
+
expect(page).to have_selector '#preferences_banner_path'
|
17
|
+
expect(page).to have_selector '#preferences_banner_default_url'
|
18
|
+
expect(page).to have_selector '#preferences_banner_url'
|
19
|
+
expect(page).to have_selector '#preferences_banner_default_style'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'edit Banner Box settings' do
|
24
|
+
before { visit spree.edit_admin_banner_box_settings_path }
|
25
|
+
|
26
|
+
it 'should update the preferences', js: true do
|
27
|
+
fill_in 'Banner Path', with: 'test'
|
28
|
+
click_button 'Update'
|
29
|
+
|
30
|
+
expect(Spree::BannerConfig.banner_path).to eq 'test'
|
31
|
+
expect(find_field('preferences_banner_path').value).to eq 'test'
|
32
|
+
|
33
|
+
# set default
|
34
|
+
Spree::BannerConfig.banner_path = ':rails_root/public/spree/banners/:id/:style/:basename.:extension'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should create a banner style', js: true do
|
38
|
+
click_link 'Add New Banner Style'
|
39
|
+
fill_in 'Style Name', with: 'test'
|
40
|
+
fill_in 'Value', with: '10x10'
|
41
|
+
click_icon :ok
|
42
|
+
|
43
|
+
expect(page).to have_text 'TEST'
|
44
|
+
expect(page).to have_selector '#banner_styles_test'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Banner Boxes', type: :feature do
|
4
|
+
|
5
|
+
before { create_admin_in_sign_in }
|
6
|
+
|
7
|
+
context 'visit Banner Box' do
|
8
|
+
it 'should be a link to Banner Box' do
|
9
|
+
within('.sidebar') { page.find_link('Banner Box')['/admin/banner_boxes'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should show a message if there are not any banners', js: true do
|
13
|
+
visit spree.admin_banner_boxes_path
|
14
|
+
|
15
|
+
expect(page).to have_text 'No Results'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should show the data of banner boxes', js: true do
|
19
|
+
create(:banner_box)
|
20
|
+
visit spree.admin_banner_boxes_path
|
21
|
+
|
22
|
+
expect(page).to have_text 'home'
|
23
|
+
expect(page).to have_text 'http://localhost:3000'
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'searching' do
|
27
|
+
before do
|
28
|
+
create(:banner_box)
|
29
|
+
create(:banner_box, category: 'product', url: 'google.com', enabled: false)
|
30
|
+
visit spree.admin_banner_boxes_path
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should search by category', js: true do
|
34
|
+
select2 'product', from: 'Category'
|
35
|
+
click_button 'Filter Results'
|
36
|
+
|
37
|
+
within_row(1) do
|
38
|
+
expect(page).to have_content('product')
|
39
|
+
end
|
40
|
+
within('table#listing_banner_boxes') { expect(page).not_to have_content('home') }
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should search by url', js: true do
|
44
|
+
fill_in 'URL', with: 'google.com'
|
45
|
+
click_button 'Filter Results'
|
46
|
+
|
47
|
+
within_row(1) do
|
48
|
+
expect(page).to have_content('product')
|
49
|
+
end
|
50
|
+
within('table#listing_banner_boxes') { expect(page).not_to have_content('home') }
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should search only enables', js: true do
|
54
|
+
check 'Show Only Enabled'
|
55
|
+
click_button 'Filter Results'
|
56
|
+
|
57
|
+
within_row(1) do
|
58
|
+
expect(page).to have_content('home')
|
59
|
+
end
|
60
|
+
within('table#listing_banner_boxes') { expect(page).not_to have_content('product') }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'create Banner Box' do
|
66
|
+
it 'should create a banner box', js: true do
|
67
|
+
visit spree.admin_banner_boxes_path
|
68
|
+
click_link 'New Banner Box'
|
69
|
+
|
70
|
+
fill_in 'Category', with: 'test'
|
71
|
+
fill_in 'URL', with: 'http://localhost'
|
72
|
+
fill_in 'Alternative Text', with: 'Test'
|
73
|
+
fill_in 'Begin Display', with: '2015/07/21'
|
74
|
+
fill_in 'End Display', with: '2015/07/22'
|
75
|
+
attach_file('Attachment', Rails.root + '../../spec/fixtures/spree.jpg')
|
76
|
+
click_button 'Create'
|
77
|
+
|
78
|
+
banner = Spree::BannerBox.last
|
79
|
+
expect(banner.category).to eq 'test'
|
80
|
+
expect(banner.url).to eq 'http://localhost'
|
81
|
+
expect(banner.alt_text).to eq 'Test'
|
82
|
+
expect(banner.begin_display).to eq Date.parse('2015/07/21')
|
83
|
+
expect(banner.end_display).to eq Date.parse('2015/07/22')
|
84
|
+
|
85
|
+
within_row(1) do
|
86
|
+
expect(page).to have_content('test')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'edit Banner Box' do
|
92
|
+
it 'should be possible edit a banner box', js: true do
|
93
|
+
create(:banner_box)
|
94
|
+
visit spree.admin_banner_boxes_path
|
95
|
+
click_icon :edit
|
96
|
+
|
97
|
+
fill_in 'End Display', with: '2015/07/22'
|
98
|
+
click_button 'Update'
|
99
|
+
|
100
|
+
expect(page).to have_text 'Banner box has been successfully updated!'
|
101
|
+
expect(Spree::BannerBox.last.end_display).to eq Date.parse('2015/07/22')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'clone Banner Box' do
|
106
|
+
it 'should be possible clone a banner box', js: true do
|
107
|
+
create(:banner_box)
|
108
|
+
visit spree.admin_banner_boxes_path
|
109
|
+
click_icon :clone
|
110
|
+
|
111
|
+
expect(page).to have_text 'Banner has been cloned'
|
112
|
+
expect(Spree::BannerBox.count).to eq 2
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'Delete Banner Box' do
|
117
|
+
it 'should be possible delete a banner box', js: true do
|
118
|
+
create(:banner_box)
|
119
|
+
visit spree.admin_banner_boxes_path
|
120
|
+
click_icon :delete
|
121
|
+
# page.driver.browser.switch_to.alert.accept
|
122
|
+
|
123
|
+
expect(page).to have_selector('table tbody tr', count: 0)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
Binary file
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::BannerBox do
|
4
|
+
let(:banner) { FactoryGirl.build(:banner_box) }
|
5
|
+
|
6
|
+
context 'validate banner' do
|
7
|
+
it 'should be invalid if category is null' do
|
8
|
+
banner.category = nil
|
9
|
+
expect(banner.invalid?).to be true
|
10
|
+
expect(banner.errors.full_messages).to include("Category can't be blank")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should be invalid if attachment is null' do
|
14
|
+
banner.attachment = nil
|
15
|
+
expect(banner.invalid?).to be true
|
16
|
+
expect(banner.errors.full_messages).to include("Attachment can't be blank")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should be able duplicate the banner' do
|
21
|
+
new_banner = banner.duplicate
|
22
|
+
expect(new_banner.category).to eq 'COPY OF home'
|
23
|
+
expect(new_banner.url).to eq 'http://localhost:3000'
|
24
|
+
expect(new_banner.attachment).to eq banner.attachment
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return the categories for select' do
|
28
|
+
create(:banner_box, category: 'cart')
|
29
|
+
create(:banner_box, category: 'product')
|
30
|
+
expect(subject.class.categories_for_select).to eq %w(cart product)
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'scoping enabled' do
|
34
|
+
it 'should return only enabled banners' do
|
35
|
+
create(:banner_box, category: 'product', enabled: false)
|
36
|
+
create(:banner_box, category: 'home')
|
37
|
+
expect(subject.class.enabled.count).to eq 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return the banners enabled without category defined' do
|
41
|
+
create(:banner_box, category: 'product')
|
42
|
+
create(:banner_box, category: 'home')
|
43
|
+
expect(subject.class.enabled.count).to eq 2
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return the banners with the category passed' do
|
47
|
+
create(:banner_box, category: 'product')
|
48
|
+
create(:banner_box, category: 'home')
|
49
|
+
expect(subject.class.enabled('product').count).to eq 1
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return the banners with display period between the current date' do
|
53
|
+
create(:banner_box, category: 'product', end_display: (Date.today - 2.days))
|
54
|
+
create(:banner_box, category: 'home')
|
55
|
+
expect(subject.class.enabled.count).to eq 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|