adminpanel 2.1.1 → 2.1.2

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -7
  3. data/Rakefile +8 -7
  4. data/adminpanel.gemspec +6 -6
  5. data/app/controllers/adminpanel/application_controller.rb +1 -0
  6. data/app/controllers/concerns/adminpanel/facebook_actions.rb +1 -1
  7. data/app/controllers/concerns/adminpanel/sitemap_actions.rb +13 -0
  8. data/app/models/concerns/adminpanel/base.rb +1 -2
  9. data/app/models/concerns/adminpanel/facebook.rb +1 -1
  10. data/app/models/concerns/adminpanel/sitemap.rb +34 -0
  11. data/lib/adminpanel/version.rb +1 -1
  12. data/lib/generators/adminpanel/gallery/gallery_generator.rb +26 -28
  13. data/lib/generators/adminpanel/initialize/initialize_generator.rb +50 -52
  14. data/lib/generators/adminpanel/resource/resource_generator.rb +190 -193
  15. data/lib/tasks/adminpanel/adminpanel.rake +4 -4
  16. data/test/dummy/app/controllers/adminpanel/departments_controller.rb +13 -0
  17. data/test/dummy/app/models/adminpanel/department.rb +47 -0
  18. data/test/dummy/app/models/adminpanel/item.rb +38 -0
  19. data/test/dummy/app/models/adminpanel/mug.rb +1 -1
  20. data/test/dummy/app/models/adminpanel/salesman.rb +1 -0
  21. data/test/dummy/config/initializers/adminpanel_setup.rb +1 -0
  22. data/test/dummy/db/schema.rb +12 -0
  23. data/test/dummy/test/fixtures/adminpanel/mugs.yml +12 -0
  24. data/test/dummy/test/fixtures/adminpanel/products.yml +6 -0
  25. data/test/dummy/test/fixtures/adminpanel/salesmen.yml +12 -0
  26. data/test/features/shared/action_exclution_test.rb +20 -0
  27. data/test/features/shared/belongs_to_category_modal_test.rb +35 -0
  28. data/test/features/shared/belongs_to_non_category_modal_test.rb +41 -0
  29. data/test/features/shared/edit_test.rb +32 -0
  30. data/test/features/shared/has_many_through_category_modal_test.rb +35 -0
  31. data/test/features/shared/has_many_through_non_category_modal_test.rb +37 -0
  32. data/test/features/shared/index_test.rb +20 -0
  33. data/test/features/shared/new_test.rb +3 -3
  34. data/test/features/shared/show_test.rb +20 -0
  35. data/test/generators/gallery_generator_test.rb +39 -0
  36. data/test/generators/initialize_generator_test.rb +45 -0
  37. data/test/generators/resource_generator_test.rb +138 -0
  38. data/test/tasks/adminpanel_rake_test.rb +32 -0
  39. data/test/test_helper.rb +16 -23
  40. metadata +81 -70
  41. data/app/uploaders/adminpanel/image_uploader.rb +0 -58
  42. data/spec/features/galleries_pages_spec.rb +0 -110
  43. data/spec/features/section_pages_spec.rb +0 -36
  44. data/spec/features/shared_pages/edit_spec.rb +0 -48
  45. data/spec/features/shared_pages/index_spec.rb +0 -50
  46. data/spec/features/shared_pages/new_spec.rb +0 -128
  47. data/spec/features/shared_pages/show_spec.rb +0 -30
  48. data/spec/generators/gallery_generator_spec.rb +0 -48
  49. data/spec/generators/initialize_generator_spec.rb +0 -68
  50. data/spec/generators/resource_generator_spec.rb +0 -169
  51. data/spec/spec_helper.rb +0 -42
  52. data/spec/support/capybara_matchers.rb +0 -17
  53. data/spec/support/factories.rb +0 -52
  54. data/spec/support/helper_methods.rb +0 -30
  55. data/spec/support/shared_connection.rb +0 -10
  56. data/spec/tasks/adminpanel_rake_spec.rb +0 -59
@@ -10,7 +10,7 @@ namespace :adminpanel do
10
10
  :has_description => false,
11
11
  :description => "",
12
12
  :key => (args[:name].downcase.tr(' ','_')),
13
- :page => args[:section],
13
+ :page => args[:section].capitalize,
14
14
  :has_image => false
15
15
  )
16
16
 
@@ -57,7 +57,7 @@ namespace :adminpanel do
57
57
 
58
58
  task :dump => :environment do |t|
59
59
  puts "Dumping adminpanel_sections and adminpanel_categories into db/seeds.rb"
60
- File.open("db/seeds.rb", "w") do |f|
60
+ File.open("#{Rails.root.join('db', 'seeds.rb')}", "w+") do |f|
61
61
  f << "Adminpanel::Section.delete_all\n"
62
62
  f << "Adminpanel::Category.delete_all\n"
63
63
  Adminpanel::Section.all.each do |section|
@@ -71,7 +71,7 @@ namespace :adminpanel do
71
71
 
72
72
  task :dump_sections => :environment do |t|
73
73
  puts "Dumping adminpanel_sections table into db/seeds.rb"
74
- File.open("db/seeds.rb", "w") do |f|
74
+ File.open("#{Rails.root.join('db', 'seeds.rb')}", "w") do |f|
75
75
  f << "Adminpanel::Section.delete_all\n"
76
76
  Adminpanel::Section.all.each do |section|
77
77
  f << "#{creation_command_section(section)}"
@@ -81,7 +81,7 @@ namespace :adminpanel do
81
81
 
82
82
  task :dump_categories => :environment do |t|
83
83
  puts "Dumping adminpanel_categories table into db/seeds.rb"
84
- File.open("db/seeds.rb", "w") do |f|
84
+ File.open("#{Rails.root.join('db', 'seeds.rb')}", "w") do |f|
85
85
  f << "Adminpanel::Section.delete_all\n"
86
86
  Adminpanel::Section.all.each do |section|
87
87
  f << "#{creation_command_categories(section)}"
@@ -0,0 +1,13 @@
1
+ module Adminpanel
2
+ class DepartmentsController < Adminpanel::ApplicationController
3
+
4
+ private
5
+ def department_params
6
+ params.require(:department).permit(
7
+ :category_id,
8
+ :product_ids,
9
+ :name
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ module Adminpanel
2
+ class Department < ActiveRecord::Base
3
+ include Adminpanel::Base
4
+
5
+ belongs_to :category
6
+
7
+ has_many :items
8
+ has_many :product, :through => :items, :dependent => :destroy
9
+
10
+ def self.form_attributes
11
+ [
12
+ {
13
+ 'category_id' => {
14
+ 'type' => 'belongs_to',
15
+ 'label' => 'category',
16
+ 'placeholder' => 'category',
17
+ 'model' => 'Adminpanel::Category',
18
+ }
19
+ },
20
+ {
21
+ 'product_ids' => {
22
+ 'type' => 'has_many',
23
+ 'label' => 'product',
24
+ 'placeholder' => 'product',
25
+ 'model' => 'Adminpanel::Product',
26
+ }
27
+ },
28
+ {
29
+ 'name' => {
30
+ 'type' => 'text_field',
31
+ 'label' => 'name',
32
+ 'placeholder' => 'name',
33
+ }
34
+ },
35
+
36
+ ]
37
+ end
38
+
39
+ def self.display_name
40
+ 'Departamento' #singular
41
+ end
42
+
43
+ # def self.icon
44
+ # "truck" # fa-{icon}
45
+ # end
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ module Adminpanel
2
+ class Item < ActiveRecord::Base
3
+ include Adminpanel::Base
4
+
5
+ belongs_to :product
6
+ belongs_to :category
7
+
8
+ def self.form_attributes
9
+ [
10
+ {
11
+ 'product_id' => {
12
+ 'type' => 'belongs_to',
13
+ 'label' => 'product',
14
+ 'placeholder' => 'product',
15
+ 'model' => 'Adminpanel::Product',
16
+ }
17
+ },
18
+ {
19
+ 'category_id' => {
20
+ 'type' => 'belongs_to',
21
+ 'label' => 'category',
22
+ 'placeholder' => 'category',
23
+ 'model' => 'Adminpanel::Category',
24
+ }
25
+ },
26
+
27
+ ]
28
+ end
29
+
30
+ def self.display_name
31
+ 'Item' #singular
32
+ end
33
+
34
+ # def self.icon
35
+ # "truck" # fa-{icon}
36
+ # end
37
+ end
38
+ end
@@ -2,7 +2,7 @@ module Adminpanel
2
2
  class Mug < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
4
  validates_presence_of :name
5
-
5
+
6
6
  def self.form_attributes
7
7
  [
8
8
  {
@@ -1,6 +1,7 @@
1
1
  module Adminpanel
2
2
  class Salesman < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
+ include Adminpanel::Facebook
4
5
 
5
6
  belongs_to :product
6
7
 
@@ -12,6 +12,7 @@ Adminpanel.setup do |config|
12
12
 
13
13
  # # This are the modules that are going to be displayed and order that are going to be displayed
14
14
  config.displayable_resources = [
15
+ :departments,
15
16
  :analytics,
16
17
  :galleries,
17
18
  :sections,
@@ -64,6 +64,18 @@ ActiveRecord::Schema.define do
64
64
  t.datetime :created_at, :null => false
65
65
  t.datetime :updated_at, :null => false
66
66
  end
67
+ create_table :adminpanel_items do |t|
68
+ t.integer :product_id
69
+ t.integer :deparment_id
70
+ t.datetime :created_at, :null => false
71
+ t.datetime :updated_at, :null => false
72
+ end
73
+ create_table :adminpanel_departments do |t|
74
+ t.integer :category_id
75
+ t.integer :name
76
+ t.datetime :created_at, :null => false
77
+ t.datetime :updated_at, :null => false
78
+ end
67
79
  create_table :adminpanel_groups do |t|
68
80
  t.string :name
69
81
  t.datetime :created_at, :null => false
@@ -0,0 +1,12 @@
1
+ first:
2
+ name: 'Mug 1'
3
+ created_at: <%= Date.today %>
4
+ updated_at: <%= Date.today %>
5
+ second:
6
+ name: 'Mug 2'
7
+ created_at: <%= Date.today %>
8
+ updated_at: <%= Date.today %>
9
+ third:
10
+ name: 'Mug 3'
11
+ created_at: <%= Date.today %>
12
+ updated_at: <%= Date.today %>
@@ -0,0 +1,6 @@
1
+ first:
2
+ name: Product saved
3
+ price: 123.45
4
+ description: lorem ipsum dolor sit amec
5
+ created_at: <%= Date.today %>
6
+ updated_at: <%= Date.today %>
@@ -0,0 +1,12 @@
1
+ one:
2
+ name: 'John Doe'
3
+ created_at: <%= Date.today %>
4
+ updated_at: <%= Date.today %>
5
+ two:
6
+ name: 'Bar Baz'
7
+ created_at: <%= Date.today %>
8
+ updated_at: <%= Date.today %>
9
+ three:
10
+ name: 'Katy Lopez'
11
+ created_at: <%= Date.today %>
12
+ updated_at: <%= Date.today %>
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class ActionExclutionTest < ViewCase
4
+ fixtures :all
5
+
6
+ setup :sign_in
7
+ def test_mugs_index_excluding_every_action_but_index
8
+ visit adminpanel.mugs_path
9
+ assert_no_link 'Crear Taza'
10
+ assert_no_selector 'i.fa.fa-pencil'
11
+ assert_no_selector 'i.fa.fa-search-plus'
12
+ assert_no_selector 'i.fa.fa-facebook'
13
+ end
14
+
15
+ protected
16
+ def sign_in
17
+ visit adminpanel.signin_path
18
+ login
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'adminpanel/product'
3
+ require 'adminpanel/category'
4
+
5
+ class BelongsToCategoryModalTest < ViewCase
6
+
7
+ setup :visit_adminpanel_new_department_path
8
+ teardown :teardown
9
+
10
+ def test_add_remote_category_link_exist
11
+ assert_link('Agregar Categoria')
12
+ end
13
+
14
+ def test_adding_a_remote_category_with_invalid_information
15
+ trigger_modal 'Agregar Categoria'
16
+ assert_equal 'Agregar Categoria', find('#modal-title').text
17
+ submit_modal 'Agregar Categoria'
18
+ assert_content( I18n.t('errors', model: 'Categoria', count: 1) )
19
+ end
20
+
21
+ def test_adding_a_remote_category_with_valid_information
22
+ trigger_modal 'Agregar Categoria'
23
+ fill_in 'category_name', with: 'remote product'
24
+ submit_modal 'Agregar Categoria'
25
+ assert_xpath("//option[contains(text(), 'remote product' )]")
26
+ end
27
+
28
+ private
29
+
30
+ def visit_adminpanel_new_department_path
31
+ visit adminpanel.signin_path
32
+ login
33
+ visit adminpanel.new_department_path
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+ require 'adminpanel/product'
3
+ require 'adminpanel/category'
4
+
5
+ class BelongsToNonCategoryModalTest < ViewCase
6
+
7
+ setup :visit_adminpanel_new_salesman_path
8
+ teardown :teardown
9
+
10
+ def test_add_remote_product_link_exist
11
+ assert_link('Agregar Producto')
12
+ end
13
+
14
+ def test_adding_a_remote_product_with_invalid_information
15
+ trigger_modal 'Agregar Producto'
16
+ assert_equal 'Agregar Producto', find('#modal-title').text
17
+ submit_modal 'Agregar Producto'
18
+ assert_content( I18n.t('errors', model: 'Producto', count: 3) )
19
+ end
20
+
21
+ def test_adding_a_remote_product_with_valid_information
22
+ trigger_modal 'Agregar Producto'
23
+ fill_in 'product_name', with: 'remote product'
24
+ fill_in 'product_description', with: 'remote description lorem'
25
+ fill_in 'product_price', with: '12.3'
26
+ submit_modal 'Agregar Producto'
27
+ # remote_product = Adminpanel::Product.last
28
+ # assert_equal 'remote_product', remote_product.name
29
+ # assert_equal 'remote descrpition lorem', remote_product.description
30
+ # assert_equal '12.3', remote_product.price
31
+ assert_xpath("//option[contains(text(), 'remote product' )]")
32
+ end
33
+
34
+ private
35
+
36
+ def visit_adminpanel_new_salesman_path
37
+ visit adminpanel.signin_path
38
+ login
39
+ visit adminpanel.new_salesman_path
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class EditTest < ViewCase
4
+ fixtures :all
5
+
6
+ setup :visit_adminpanel_new_product_path
7
+ teardown :teardown
8
+
9
+ def test_shared_new_page_messages
10
+ assert_button('Guardar Producto')
11
+ end
12
+
13
+ def test_submitting_with_same_information
14
+ click_button('Guardar Producto')
15
+ assert_content( I18n.t('action.save_success') )
16
+ end
17
+
18
+ def test_submitting_with_invalid_information
19
+ fill_in 'product_name', :with => ''
20
+ fill_in 'product_price', :with => ''
21
+ click_button('Guardar Producto')
22
+ assert_content('Producto no pudo guardarse debido a 2 errores')
23
+ saved_product = Adminpanel::Product.last
24
+ end
25
+
26
+ protected
27
+ def visit_adminpanel_new_product_path
28
+ visit adminpanel.signin_path
29
+ login
30
+ visit adminpanel.edit_product_path(adminpanel_products(:first))
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'adminpanel/product'
3
+ require 'adminpanel/category'
4
+
5
+ class HasManyThroughCategoryModalTest < ViewCase
6
+
7
+ setup :visit_adminpanel_new_product_path
8
+ teardown :teardown
9
+
10
+ def test_add_remote_product_link_exist
11
+ assert_link('Agregar Categoria')
12
+ end
13
+
14
+ def test_adding_a_remote_product_with_invalid_information
15
+ trigger_modal 'Agregar Categoria'
16
+ assert_equal 'Agregar Categoria', find('#modal-title').text
17
+ submit_modal 'Agregar Categoria'
18
+ assert_content( I18n.t('errors', model: 'Categoria', count: 1) )
19
+ end
20
+
21
+ def test_adding_a_remote_product_with_valid_information
22
+ trigger_modal 'Agregar Categoria'
23
+ fill_in 'category_name', with: 'remote option of category'
24
+ submit_modal 'Agregar Categoria'
25
+ assert_content('remote option of category')
26
+ end
27
+
28
+ private
29
+
30
+ def visit_adminpanel_new_product_path
31
+ visit adminpanel.signin_path
32
+ login
33
+ visit adminpanel.new_product_path
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+ require 'adminpanel/product'
3
+ require 'adminpanel/category'
4
+ class HasManyThroughNonCategoryModalTest < ViewCase
5
+
6
+ setup :visit_adminpanel_new_department_path
7
+ teardown :teardown
8
+
9
+ def test_add_remote_product_link_exist
10
+ assert_link('Agregar Producto')
11
+ end
12
+
13
+ def test_adding_a_remote_product_with_invalid_information
14
+ trigger_modal 'Agregar Producto'
15
+ assert_equal 'Agregar Producto', find('#modal-title').text
16
+ submit_modal 'Agregar Producto'
17
+ assert_content( I18n.t('errors', model: 'Producto', count: 3) )
18
+ end
19
+
20
+ def test_adding_a_remote_product_with_valid_information
21
+ trigger_modal 'Agregar Producto'
22
+ fill_in 'product_name', with: 'remote checkbox of product'
23
+ fill_in 'product_description', with: 'remote description lorem'
24
+ fill_in 'product_price', with: '12.3'
25
+ submit_modal 'Agregar Producto'
26
+ assert_content('remote checkbox of product')
27
+
28
+ end
29
+
30
+ private
31
+
32
+ def visit_adminpanel_new_department_path
33
+ visit adminpanel.signin_path
34
+ login
35
+ visit adminpanel.new_department_path
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class IndexTest < ViewCase
4
+ fixtures :all
5
+
6
+ setup :sign_in
7
+ def test_index_buttons_of_resources
8
+ visit adminpanel.salesmen_path
9
+ assert_link 'Crear Agente'
10
+ assert_selector 'i.fa.fa-pencil'
11
+ assert_selector 'i.fa.fa-search-plus'
12
+ assert_selector 'i.fa.fa-facebook'
13
+ end
14
+
15
+ protected
16
+ def sign_in
17
+ visit adminpanel.signin_path
18
+ login
19
+ end
20
+ end