redde 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +2 -3
  4. data/lib/generators/redde/layout/layout_generator.rb +22 -1
  5. data/lib/generators/redde/layout/templates/base/_header.html.haml +1 -1
  6. data/lib/generators/redde/layout/templates/base/_launchbar.html.haml +2 -2
  7. data/lib/generators/redde/layout/templates/base/_sidebar.html.haml +3 -4
  8. data/lib/generators/redde/layout/templates/controllers/base_controller.rb +19 -2
  9. data/lib/generators/redde/layout/templates/controllers/managers/registrations_controller.rb +21 -0
  10. data/lib/generators/redde/layout/templates/controllers/managers_controller.rb +30 -0
  11. data/lib/generators/redde/photo/templates/photo.rb +1 -4
  12. data/lib/generators/redde/photo/templates/uploader.rb +0 -4
  13. data/lib/generators/redde/scaffold/templates/controllers/controller.rb +6 -14
  14. data/lib/redde/concerns/photoable.rb +17 -0
  15. data/lib/redde/concerns/with_photo.rb +17 -3
  16. data/lib/redde/version.rb +1 -1
  17. data/lib/redde.rb +1 -0
  18. data/redde.gemspec +9 -9
  19. data/spec/dummy/app/models/article.rb +1 -0
  20. data/spec/dummy/app/models/photo.rb +3 -0
  21. data/spec/dummy/app/views/admin/photos/_photo.haml +5 -0
  22. data/spec/dummy/app/views/admin/photos/_photos.haml +19 -0
  23. data/spec/dummy/app/views/admin/photos/create.js.erb +1 -0
  24. data/spec/dummy/app/views/admin/photos/destroy.js.erb +1 -0
  25. data/spec/dummy/db/migrate/20140607122532_create_photos.rb +16 -0
  26. data/spec/dummy/db/schema.rb +70 -1
  27. data/spec/generators/layout_generator_spec.rb +16 -18
  28. data/spec/generators/photo_generator_spec.rb +11 -12
  29. data/spec/generators/scaffold_generator_spec.rb +25 -26
  30. data/spec/models/sluggable_spec.rb +0 -1
  31. data/spec/models/with_photo_spec.rb +25 -0
  32. data/spec/spec_helper.rb +7 -14
  33. metadata +19 -6
  34. data/spec/dummy/db/development.sqlite3 +0 -0
  35. data/spec/dummy/db/test.sqlite3 +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e9c5fd3d5b0a6b212e42d958015be835b3ca326
4
- data.tar.gz: 211e8ec998cd34478082efba8e8418bc7dad1859
3
+ metadata.gz: e7db06e9218ae6343bcc14a2dd7f22680b620750
4
+ data.tar.gz: eef951c975ae0d16d8e0d83fd08499b06ead764e
5
5
  SHA512:
6
- metadata.gz: 28c5c14c47501b64b6bc181f2e85e8f35ca249acc37e0abaf7cc64236d52eb55ff2b71444c4880cd247b00ef347d15029bb65aaeb5393210ed235a88a6ad86f2
7
- data.tar.gz: aede49ea623edd9c5d1ea02425500cc238d9f15a6839a8b86335e3a86c53feb2e907e08752a155c33c894221b06edf13f5817bc476946728caac62b55cc05dd0
6
+ metadata.gz: 0cc6de724a9a269574ee2b76032544283f8ef49e159ddb82f71fc45d6cf0d497ef2d82d44d0f005f1a3f489926ee2f4f03397c4a4528ddc079e2f6fbc888b724
7
+ data.tar.gz: cbb28953633ae2aae37658fa38c510dbd5ada7026819642e2ee5ef84be3b8259198d36ecda581ab7c2068442e5b41f027cbb6a4aac780626b0d26baca0f65892
data/.gitignore CHANGED
@@ -22,4 +22,4 @@ tmp
22
22
  /spec/dummy/public/uploads
23
23
  /spec/dummy/log
24
24
  /spec/dummy/log/test.log
25
- /spec/dummy/db/*sqlite3
25
+ /spec/dummy/db/*sqlite3
data/.travis.yml CHANGED
@@ -3,8 +3,7 @@ language: ruby
3
3
  notifications:
4
4
  email: false
5
5
  rvm:
6
- - 1.9.3
7
6
  - 2.0.0
8
- - 2.1.0
7
+ - 2.1
9
8
  before_script:
10
- - "cd spec/dummy; rake db:setup RAILS_ENV=test"
9
+ - 'cd spec/dummy; rake db:setup RAILS_ENV=test'
@@ -8,20 +8,41 @@ module Redde
8
8
 
9
9
  attr_reader :app_name
10
10
 
11
- def generate_layout
11
+ def make_views
12
12
  %w(admin login).each do |layout|
13
13
  template "layouts/#{layout}#{ext}", "app/views/layouts/#{layout}#{ext}"
14
14
  end
15
15
  directory 'base', 'app/views/admin/base'
16
+ end
17
+
18
+ def make_js
16
19
  %w(admin.js).each do |js|
17
20
  template "assets/javascripts/#{js}", "app/assets/javascripts/#{js}"
18
21
  end
19
22
  directory 'assets/javascripts/admin', 'app/assets/javascripts/admin'
23
+ end
24
+
25
+ def make_css
20
26
  directory 'assets/stylesheets/admin', 'app/assets/stylesheets/admin'
21
27
  directory 'assets/redactor', 'app/assets'
28
+ end
29
+
30
+ def make_helpers
22
31
  template 'helpers/admin_helper.rb', 'app/helpers/admin_helper.rb'
32
+ end
33
+
34
+ def make_images
23
35
  directory 'assets/images/admin', 'app/assets/images/admin'
36
+ end
37
+
38
+ def make_controllers
24
39
  template 'controllers/base_controller.rb', 'app/controllers/admin/base_controller.rb'
40
+ template 'controllers/managers_controller.rb', 'app/controllers/admin/managers_controller.rb'
41
+ directory 'controllers/managers', 'app/controllers/managers'
42
+ end
43
+
44
+ def fix_routes
45
+ route("devise_for :managers, controllers: { registrations: 'managers/registrations' }")
25
46
  end
26
47
 
27
48
  private
@@ -9,4 +9,4 @@
9
9
  = mail_to current_manager.email
10
10
  = link_to 'Выход', destroy_manager_session_path, method: :delete
11
11
  .header__center
12
- = link_to 'AppName', root_path ||= '/', target: :_blank
12
+ = link_to Rails.application.class.parent_name, root_path || '/', target: :_blank
@@ -1,11 +1,11 @@
1
1
  - case controller_name
2
2
  - when 'products' then @active = :shop
3
3
  - when 'articles' then @active = :materials
4
- - when 'users' then @active = :system
4
+ - when 'users', 'managers' then @active = :system
5
5
 
6
6
  .launchbar
7
7
  %nav.launchbar__menu
8
8
  = link_to 'Материалы', nil, class: ['launchbar__link', ('_active' if @active == :shop)]
9
9
  = link_to 'Обратная связь', nil, class: ['launchbar__link', ('_active' if @active == :materials)]
10
- = link_to 'Система', nil, class: ['launchbar__link', ('_active' if @active == :system)]
10
+ = link_to 'Система', [:admin, :managers], class: ['launchbar__link', ('_active' if @active == :system)]
11
11
  %span.launchbar__time= Russian.strftime(Time.now, '%d %b, %Y %H:%M ')
@@ -1,13 +1,12 @@
1
- -# add this condition to remove empty sidebar
2
- -# if @active
3
1
  %nav.sidebar
4
2
  - case @active
5
3
  - when :shop
6
- = link_to 'Товары', admin_products_path, class: 'sidebar__link'
4
+ = link_to 'Товары', [:admin, :products], class: 'sidebar__link'
7
5
  - when :materials
8
6
  = link_to 'Статьи', [:admin, :articles], class: 'sidebar__link'
9
7
  - when :system
10
- = link_to 'Пользователи', admin_users_path, class: 'sidebar__link'
8
+ = link_to 'Администраторы', [:admin, :managers], class: 'sidebar__link'
9
+ = link_to 'Пользователи', [:admin, :users], class: 'sidebar__link'
11
10
  - else
12
11
  = link_to 'Демо active', nil, class: ['sidebar__link', '_active']
13
12
  = link_to nil, class: ['sidebar__link'] do
@@ -1,5 +1,3 @@
1
- #coding: utf-8
2
-
3
1
  class Admin::BaseController < ActionController::Base
4
2
  layout 'admin'
5
3
  before_filter :authenticate_manager!
@@ -7,4 +5,23 @@ class Admin::BaseController < ActionController::Base
7
5
 
8
6
  def welcome
9
7
  end
8
+
9
+ private
10
+
11
+ def redirect_or_edit(obj, saved)
12
+ if saved
13
+ redirect_to url_for_obj(obj), notice: notice_for(obj)
14
+ else
15
+ render 'edit'
16
+ end
17
+ end
18
+
19
+ def notice_for(obj)
20
+ "#{obj.class.model_name.human} сохранен."
21
+ end
22
+
23
+ def url_for_obj(obj)
24
+ return [:edit, :admin, obj] if params[:commit] == 'Применить'
25
+ [:admin, obj.class.model_name.plural.to_sym]
26
+ end
10
27
  end
@@ -0,0 +1,21 @@
1
+ class Managers::RegistrationsController < Devise::RegistrationsController
2
+ def new
3
+ redirect_to root_path, alert: 'Регистрация закрыта'
4
+ end
5
+
6
+ def create
7
+ redirect_to root_path, alert: 'Регистрация закрыта'
8
+ end
9
+
10
+ def edit
11
+ redirect_to root_path, alert: 'Регистрация закрыта'
12
+ end
13
+
14
+ def update
15
+ redirect_to root_path, alert: 'Регистрация закрыта'
16
+ end
17
+
18
+ def destroy
19
+ redirect_to root_path, alert: 'Регистрация закрыта'
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ class Admin::ManagersController < Admin::BaseController
2
+ def index
3
+ @managers = Manager.all
4
+ end
5
+
6
+ def new
7
+ @manager = Manager.new
8
+ render 'edit'
9
+ end
10
+
11
+ def create
12
+ @manager = Manager.new(manager_params)
13
+ redirect_or_edit(@manager, @manager.save)
14
+ end
15
+
16
+ def edit
17
+ @manager = Manager.find(params[:id])
18
+ end
19
+
20
+ def update
21
+ @manager = Manager.find(params[:id])
22
+ redirect_or_edit(@manager, @manager.update(manager_params))
23
+ end
24
+
25
+ def destroy
26
+ @manager = Manager.find(params[:id])
27
+ @manager.destroy if current_manager.id != @manager.id
28
+ redirect_to [:admin, :managers], alert: 'Администратор удален'
29
+ end
30
+ end
@@ -1,7 +1,4 @@
1
1
  class Photo < ActiveRecord::Base
2
- belongs_to :imageable, polymorphic: true
3
-
4
- default_scope { order(:position) }
5
-
2
+ include Redde::Photoable
6
3
  mount_uploader :src, PhotoUploader
7
4
  end
@@ -1,7 +1,4 @@
1
- # encoding: utf-8
2
-
3
1
  class PhotoUploader < CarrierWave::Uploader::Base
4
-
5
2
  # Include RMagick or MiniMagick support:
6
3
  include CarrierWave::RMagick
7
4
  # include CarrierWave::MiniMagick
@@ -28,7 +25,6 @@ class PhotoUploader < CarrierWave::Uploader::Base
28
25
  ActionController::Base.helpers.asset_path "missing/#{model.class.to_s.tableize}/#{version_name}.png"
29
26
  end
30
27
 
31
-
32
28
  # Process files as they are uploaded:
33
29
  # process :scale => [200, 300]
34
30
  #
@@ -23,20 +23,12 @@ class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseCont
23
23
 
24
24
  def create
25
25
  @<%= resource_name %> = <%= model_name.demodulize -%>.new(<%= resource_name %>_params)
26
- if @<%= resource_name %>.save
27
- redirect_to params[:commit] == 'Применить' ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], notice: "#{<%= model_name.demodulize -%>.model_name.human} добавлен."
28
- else
29
- render 'edit'
30
- end
26
+ redirect_or_edit(@<%= resource_name %>, @<%= resource_name %>.save)
31
27
  end
32
28
 
33
29
  def update
34
30
  @<%= resource_name %> = <%= model_name.demodulize -%>.find(params[:id])
35
- if @<%= resource_name %>.update_attributes(<%= resource_name %>_params)
36
- redirect_to params[:commit] == 'Применить' ? [:edit, :admin, @<%= resource_name %>] : [:admin, :<%= plural_resource_name %>], notice: "#{<%= model_name.demodulize -%>.model_name.human} отредактирован."
37
- else
38
- render 'edit'
39
- end
31
+ redirect_or_edit(@<%= resource_name %>, @<%= resource_name %>.update(<%= resource_name %>_params))
40
32
  end
41
33
 
42
34
  def destroy
@@ -46,8 +38,8 @@ class Admin::<%= model_name.demodulize.pluralize -%>Controller < Admin::BaseCont
46
38
  end
47
39
 
48
40
  private
49
- def <%= resource_name %>_params
50
- params.require(:<%= resource_name %>).permit(<%= column_names.select {|c| !(['id', 'updated_at', 'created_at'].include? c) }.map {|c| ":#{c}"}.join(', ') %>)
51
- end
52
41
 
53
- end
42
+ def <%= resource_name %>_params
43
+ params.require(:<%= resource_name %>).permit(<%= column_names.select {|c| !(['id', 'updated_at', 'created_at'].include? c) }.map { |c| ":#{c}" }.join(', ') %>)
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ module Redde::Photoable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ belongs_to :imageable, polymorphic: true
6
+ default_scope { order(:position) }
7
+ before_save :set_token, unless: :persisted_link?
8
+ end
9
+
10
+ def set_token
11
+ token = SecureRandom.uuid unless token.present?
12
+ end
13
+
14
+ def persisted_link?
15
+ imageable_type.present? && imageable_id.present?
16
+ end
17
+ end
@@ -1,13 +1,27 @@
1
- module WithPhoto
1
+ module Redde::WithPhoto
2
2
  extend ActiveSupport::Concern
3
3
 
4
+ QUERY = 'imageable_id = :id AND imageable_type = :type OR token in (:tokens)'
5
+
4
6
  included do
5
- attr_accessor :tokens
7
+ attr_accessor :photo_tokens
6
8
  has_many :photos, dependent: :destroy, as: :imageable
7
9
  after_create :assign_photos
8
10
  end
9
11
 
12
+ def all_photos
13
+ Photo.where(QUERY, id: self.id, type: self.class.name, tokens: tokens)
14
+ end
15
+
10
16
  def assign_photos
11
- Photo.where(token: tokens || []).update_all(imageable_id: self.id, imageable_type: self.class.name)
17
+ Photo.where(token: tokens).update_all(imageable_attributes)
18
+ end
19
+
20
+ def imageable_attributes
21
+ { imageable_id: self.id, imageable_type: self.class.name, token: nil }
22
+ end
23
+
24
+ def tokens
25
+ photo_tokens || []
12
26
  end
13
27
  end
data/lib/redde/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
data/lib/redde.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'redde/version'
2
2
  require 'redde/concerns/sluggable'
3
3
  require 'redde/concerns/with_photo'
4
+ require 'redde/concerns/photoable'
4
5
 
5
6
  module Redde
6
7
  require 'generators/redde/layout/layout_generator'
data/redde.gemspec CHANGED
@@ -3,27 +3,27 @@
3
3
  require File.expand_path('../lib/redde/version', __FILE__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.authors = ["Oleg Bovykin", "Konstantin Gorozhankin"]
7
- gem.email = ["oleg.bovykin@gmail.com", "konstantin.gorozhankin@gmail.com", "info@redde.ru"]
6
+ gem.authors = ['Oleg Bovykin', 'Konstantin Gorozhankin']
7
+ gem.email = ['oleg.bovykin@gmail.com', 'konstantin.gorozhankin@gmail.com', 'info@redde.ru']
8
8
  gem.description = %q{Admin scaffold generator for redde projects}
9
9
  gem.summary = %q{Admin scaffold generator for redde projects}
10
- gem.homepage = "http://github.com/redde/redde"
10
+ gem.homepage = 'http://github.com/redde/redde'
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
13
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
- gem.name = "redde"
16
- gem.require_paths = ["lib"]
15
+ gem.name = 'redde'
16
+ gem.require_paths = ['lib']
17
17
  gem.version = Redde::VERSION
18
- gem.license = "MIT"
18
+ gem.license = 'MIT'
19
19
 
20
- gem.add_runtime_dependency "jquery-rails"
21
- gem.add_runtime_dependency "jquery-ui-rails"
20
+ gem.add_runtime_dependency 'jquery-rails'
21
+ gem.add_runtime_dependency 'jquery-ui-rails'
22
22
 
23
23
  gem.add_development_dependency 'rails', '>= 3.1'
24
24
  gem.add_development_dependency 'rspec-rails', '>= 2.7'
25
25
  gem.add_development_dependency 'factory_girl_rails', '>= 2.7'
26
26
  gem.add_development_dependency 'guard-rspec'
27
- gem.add_development_dependency "sqlite3"
27
+ gem.add_development_dependency 'sqlite3'
28
28
  gem.add_development_dependency 'generator_spec'
29
29
  end
@@ -1,3 +1,4 @@
1
1
  class Article < ActiveRecord::Base
2
+ include Redde::WithPhoto
2
3
  validates :title, presence: true
3
4
  end
@@ -0,0 +1,3 @@
1
+ class Photo < ActiveRecord::Base
2
+ include Redde::Photoable
3
+ end
@@ -0,0 +1,5 @@
1
+ %li{ class: 'handle', id: "photo_#{photo.id}" }
2
+ = link_to photo.src.url do
3
+ = image_tag photo.src.admin
4
+ %em= photo.src.to_s.gsub(/.*\/(.*)\z/, '\1')
5
+ = link_to 'удалить', [:admin, photo.imageable, photo], method: :delete, data: { confirm: 'Точно удалить?'}, remote: true, title: 'Удалить', class: 'del'
@@ -0,0 +1,19 @@
1
+ - unless parent.new_record?
2
+ = content_for(:page_sidebar) do
3
+ %h5
4
+ Фотографии
5
+ - if editable ||= false
6
+ = link_to 'ред.', [:admin, parent]
7
+ .product-photos
8
+ %ul.photos#photo-list
9
+ = render parent.photos
10
+ #preview
11
+ #drag-n-drop{ style: 'display: none; margin-top: 5px;' }
12
+ #drop-zone.b-dropzone{ style: 'height: 100px;', data: { 'upload-url' => url_for([:admin, parent, :photos]) } }
13
+ .b-dropzone__bg
14
+ .b-dropzone__txt Перетащите файлы сюда
15
+ #buttons-panel{ style: 'margin-bottom: 10px;' }
16
+ .b-button.js-fileapi-wrapper
17
+ .b-button__text Загрузить файлы
18
+ %input.b-button__input.js-fileapi{ name: 'files', type: 'file', multiple: true, data: { "upload-url" => url_for([:admin, parent, :photos]) } }
19
+ = photo_sortable url_for([:sort, :admin, parent, :photos])
@@ -0,0 +1 @@
1
+ $('ul.photos').append('<%= escape_javascript(render "admin/photos/photo", { photo: @photo, parent: @parent }) %>');
@@ -0,0 +1 @@
1
+ $("li#photo_<%= @photo.id%>").remove();
@@ -0,0 +1,16 @@
1
+ class CreatePhotos < ActiveRecord::Migration
2
+ def change
3
+ create_table :photos do |t|
4
+ t.integer :imageable_id
5
+ t.string :imageable_type
6
+ t.integer :position
7
+ t.string :src
8
+ t.string :token
9
+
10
+ t.timestamps
11
+ end
12
+ add_index :photos, :imageable_id
13
+ add_index :photos, :imageable_type
14
+ add_index :photos, :token
15
+ end
16
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140128152208) do
14
+ ActiveRecord::Schema.define(version: 20140607122532) do
15
15
 
16
16
  create_table "article_categories", force: true do |t|
17
17
  t.string "title"
@@ -26,4 +26,73 @@ ActiveRecord::Schema.define(version: 20140128152208) do
26
26
  t.datetime "created_at"
27
27
  t.datetime "updated_at"
28
28
  end
29
+
30
+ create_table "photos", force: true do |t|
31
+ t.integer "imageable_id"
32
+ t.string "imageable_type"
33
+ t.integer "position"
34
+ t.string "src"
35
+ t.string "token"
36
+ t.datetime "created_at"
37
+ t.datetime "updated_at"
38
+ end
39
+
40
+ add_index "photos", ["imageable_id"], name: "index_photos_on_imageable_id"
41
+ add_index "photos", ["imageable_type"], name: "index_photos_on_imageable_type"
42
+ add_index "photos", ["token"], name: "index_photos_on_token"
43
+
44
+ create_table "redditor_images", force: true do |t|
45
+ t.integer "imageable_id"
46
+ t.string "imageable_type"
47
+ t.integer "position"
48
+ t.string "src"
49
+ t.string "description"
50
+ t.datetime "created_at", null: false
51
+ t.datetime "updated_at", null: false
52
+ end
53
+
54
+ add_index "redditor_images", ["imageable_id"], name: "index_redditor_images_on_imageable_id"
55
+ add_index "redditor_images", ["imageable_type"], name: "index_redditor_images_on_imageable_type"
56
+
57
+ create_table "redditor_pages", force: true do |t|
58
+ t.integer "pageable_id"
59
+ t.string "pageable_type"
60
+ t.datetime "created_at", null: false
61
+ t.datetime "updated_at", null: false
62
+ end
63
+
64
+ add_index "redditor_pages", ["pageable_id"], name: "index_redditor_pages_on_pageable_id"
65
+ add_index "redditor_pages", ["pageable_type"], name: "index_redditor_pages_on_pageable_type"
66
+
67
+ create_table "redditor_slider_blocks", force: true do |t|
68
+ t.integer "page_id"
69
+ t.integer "position"
70
+ t.datetime "created_at", null: false
71
+ t.datetime "updated_at", null: false
72
+ end
73
+
74
+ add_index "redditor_slider_blocks", ["page_id"], name: "index_redditor_slider_blocks_on_page_id"
75
+
76
+ create_table "redditor_text_blocks", force: true do |t|
77
+ t.integer "page_id"
78
+ t.text "body"
79
+ t.integer "position"
80
+ t.datetime "created_at", null: false
81
+ t.datetime "updated_at", null: false
82
+ end
83
+
84
+ add_index "redditor_text_blocks", ["page_id"], name: "index_redditor_text_blocks_on_page_id"
85
+
86
+ create_table "redditor_video_blocks", force: true do |t|
87
+ t.integer "page_id"
88
+ t.integer "position"
89
+ t.integer "width"
90
+ t.integer "height"
91
+ t.string "youtube"
92
+ t.datetime "created_at", null: false
93
+ t.datetime "updated_at", null: false
94
+ end
95
+
96
+ add_index "redditor_video_blocks", ["page_id"], name: "index_redditor_video_blocks_on_page_id"
97
+
29
98
  end
@@ -2,11 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Redde::Generators::LayoutGenerator do
4
4
  include GeneratorSpec::TestCase
5
- destination File.expand_path("../../../tmp", __FILE__)
5
+ destination File.expand_path('../../../tmp', __FILE__)
6
6
  arguments %w(something)
7
7
 
8
8
  before(:all) do
9
9
  prepare_destination
10
+ `mkdir tmp/config; touch tmp/config/routes.rb; echo "Rails.application.routes.draw do\nend" > tmp/config/routes.rb`
10
11
  run_generator
11
12
  end
12
13
 
@@ -14,28 +15,25 @@ describe Redde::Generators::LayoutGenerator do
14
15
  FileUtils.rm_rf 'tmp'
15
16
  end
16
17
 
17
- describe "layout" do
18
-
19
- it "Generates admin and login layouts with js and css" do
18
+ describe 'layout' do
19
+ it 'Generates admin and login layouts with js and css' do
20
20
  # check layouts
21
- assert_file "app/views/layouts/admin.html.haml"
22
- assert_file "app/views/layouts/login.html.haml"
21
+ assert_file 'app/views/layouts/admin.html.haml'
22
+ assert_file 'app/views/layouts/login.html.haml'
23
23
 
24
24
  # check shared
25
- assert_file "app/views/admin/base/_launchbar.html.haml"
26
- assert_file "app/views/admin/base/_sidebar.html.haml"
27
- assert_file "app/views/admin/base/_header.html.haml"
25
+ assert_file 'app/views/admin/base/_launchbar.html.haml'
26
+ assert_file 'app/views/admin/base/_sidebar.html.haml'
27
+ assert_file 'app/views/admin/base/_header.html.haml'
28
28
 
29
29
  # check js and css
30
- assert_file "app/assets/javascripts/admin.js"
31
- assert_file "app/assets/stylesheets/admin/index.scss"
30
+ assert_file 'app/assets/javascripts/admin.js'
31
+ assert_file 'app/assets/stylesheets/admin/index.scss'
32
32
 
33
- #check images
34
- assert_directory "app/assets/images/admin"
35
- assert_directory "app/assets/javascripts/admin"
36
- assert_directory "app/assets/stylesheets/admin"
33
+ # check images
34
+ assert_directory 'app/assets/images/admin'
35
+ assert_directory 'app/assets/javascripts/admin'
36
+ assert_directory 'app/assets/stylesheets/admin'
37
37
  end
38
-
39
38
  end
40
-
41
- end
39
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Redde::Generators::PhotoGenerator do
4
4
  include GeneratorSpec::TestCase
5
- destination File.expand_path("../../../tmp", __FILE__)
5
+ destination File.expand_path('../../../tmp', __FILE__)
6
6
 
7
7
  before(:all) do
8
8
  prepare_destination
@@ -13,21 +13,20 @@ describe Redde::Generators::PhotoGenerator do
13
13
  FileUtils.rm_rf 'tmp'
14
14
  end
15
15
 
16
- it "Generates controller" do
17
- assert_file "app/controllers/admin/photos_controller.rb"
16
+ it 'Generates controller' do
17
+ assert_file 'app/controllers/admin/photos_controller.rb'
18
18
  end
19
19
 
20
- it "Generates views" do
21
- assert_directory "app/views/admin/photos"
20
+ it 'Generates views' do
21
+ assert_directory 'app/views/admin/photos'
22
22
  end
23
23
 
24
- it "Generates model" do
25
- assert_file "app/models/photo.rb"
24
+ it 'Generates model' do
25
+ assert_file 'app/models/photo.rb'
26
26
  end
27
27
 
28
- it "Generates migration" do
29
- files = Dir["tmp/db/migrate/*.rb"]
30
- expect(files.map(&:to_s).join(" ").index("create_photos")).to eq 30
28
+ it 'Generates migration' do
29
+ files = Dir['tmp/db/migrate/*.rb']
30
+ expect(files.map(&:to_s).join(' ').index('create_photos')).to eq 30
31
31
  end
32
-
33
- end
32
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Redde::Generators::ScaffoldGenerator do
4
4
  include GeneratorSpec::TestCase
5
- destination File.expand_path("../../../tmp", __FILE__)
5
+ destination File.expand_path('../../../tmp', __FILE__)
6
6
  arguments ['Articles']
7
7
 
8
8
  before(:all) do
@@ -14,46 +14,45 @@ describe Redde::Generators::ScaffoldGenerator do
14
14
  FileUtils.rm_rf 'tmp'
15
15
  end
16
16
 
17
- let(:args) { ["ArticleCategory"] }
17
+ let(:args) { ['ArticleCategory'] }
18
18
  let(:generator) { Redde::Generators::ScaffoldGenerator.new(args) }
19
19
 
20
- context "METHODS" do
21
- it "gets controller_routing_path" do
22
- expect(generator.send(:controller_routing_path)).to eq "article_category"
20
+ context 'METHODS' do
21
+ it 'gets controller_routing_path' do
22
+ expect(generator.send(:controller_routing_path)).to eq 'article_category'
23
23
  end
24
24
 
25
- it "gets singular_controller_routing_path" do
26
- expect(generator.send(:singular_controller_routing_path)).to eq "article_category"
25
+ it 'gets singular_controller_routing_path' do
26
+ res = generator.send(:singular_controller_routing_path)
27
+ expect(res).to eq 'article_category'
27
28
  end
28
29
 
29
- it "gets model_name" do
30
- expect(generator.send(:model_name)).to eq "::ArticleCategory"
30
+ it 'gets model_name' do
31
+ expect(generator.send(:model_name)).to eq '::ArticleCategory'
31
32
  end
32
33
 
33
- it "gets plural_model_name" do
34
- expect(generator.send(:plural_model_name)).to eq "::ArticleCategories"
34
+ it 'gets plural_model_name' do
35
+ expect(generator.send(:plural_model_name)).to eq '::ArticleCategories'
35
36
  end
36
37
 
37
- it "gets resource_name" do
38
- expect(generator.send(:resource_name)).to eq "article_category"
38
+ it 'gets resource_name' do
39
+ expect(generator.send(:resource_name)).to eq 'article_category'
39
40
  end
40
41
 
41
- it "gets plural_resource_name" do
42
- expect(generator.send(:plural_resource_name)).to eq "article_categories"
42
+ it 'gets plural_resource_name' do
43
+ expect(generator.send(:plural_resource_name)).to eq 'article_categories'
43
44
  end
44
45
 
45
- it "gets index header" do
46
- expect(generator.send(:index_header)).to eq "Article categories"
46
+ it 'gets index header' do
47
+ expect(generator.send(:index_header)).to eq 'Article categories'
47
48
  end
48
- end # end context "METHODS"
49
+ end # end context 'METHODS'
49
50
 
50
- context "INTEGRATION" do
51
-
52
- it "Generates admin views" do
53
- assert_file "app/views/admin/articles/index.html.haml"
54
- assert_file "app/views/admin/articles/edit.html.haml"
51
+ context 'INTEGRATION' do
52
+ it 'Generates admin views' do
53
+ assert_file 'app/views/admin/articles/index.html.haml'
54
+ assert_file 'app/views/admin/articles/edit.html.haml'
55
55
  end
56
56
 
57
- end # end describe "VIEWS"
58
-
59
- end
57
+ end # end describe 'VIEWS'
58
+ end
@@ -17,7 +17,6 @@ class DummyClass
17
17
  end
18
18
  end
19
19
 
20
-
21
20
  class DummyClassWithTitle < DummyClass
22
21
  include Redde::Sluggable
23
22
  TITLE_SYMBOL = :name
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Redde::WithPhoto do
4
+ let(:photo1) { Photo.create(src: '/uploads/1.txt', token: rand(1000)) }
5
+ let(:photo2) { Photo.create(src: '/uploads/2.txt', token: rand(1000)) }
6
+ let(:tokens) { [photo1.token, photo2.token] }
7
+ let(:only_token) { { imageable_type: nil, imageable_id: nil, token: 123 } }
8
+ let(:article) { Article.new(title: 'Test Title', photo_tokens: tokens) }
9
+
10
+ it 'assigns photos to article' do
11
+ Photo.delete_all
12
+ article.save
13
+ expect(article.photos.count).to eq 2
14
+ end
15
+
16
+ it 'it gets all photos for article' do
17
+ Photo.delete_all
18
+ article.save
19
+ article.reload
20
+ article.photos.first.update(only_token)
21
+ article.photo_tokens = [123]
22
+ expect(article.all_photos.count).to eq 2
23
+ expect(article.photos.count).to eq 1
24
+ end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,29 +1,22 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
- require File.expand_path("../dummy/config/environment", __FILE__)
3
-
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../dummy/config/environment', __FILE__)
4
3
  require 'bundler/setup'
5
4
  require 'rails/all'
6
5
  require 'active_record'
7
-
8
6
  require 'rspec/rails'
9
7
  require 'rspec/autorun'
10
-
11
8
  require 'factory_girl'
12
-
13
-
14
9
  require 'generator_spec/test_case'
15
10
  require 'redde'
16
- Dir[Pathname.new(File.expand_path('../', __FILE__)).join('support/**/*.rb')].each {|f| require f}
17
11
 
18
12
  # Requires supporting ruby files with custom matchers and macros, etc,
19
13
  # in spec/support/ and its subdirectories.
20
- Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
14
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
21
15
 
22
16
  # Checks for pending migrations before tests are run.
23
17
  # If you are not using ActiveRecord, you can remove this line.
24
18
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
25
19
 
26
-
27
20
  RSpec.configure do |config|
28
21
  # ## Mock Framework
29
22
  #
@@ -34,9 +27,9 @@ RSpec.configure do |config|
34
27
  # config.mock_with :rr
35
28
 
36
29
  # config.after(:all) do
37
- # if Rails.env.test?
38
- # FileUtils.rm_rf(Dir["#{Rails.root}/public/uploads"])
39
- # end
30
+ # if Rails.env.test?
31
+ # FileUtils.rm_rf(Dir['#{Rails.root}/public/uploads'])
32
+ # end
40
33
  # end
41
34
 
42
35
  config.include FactoryGirl::Syntax::Methods
@@ -55,5 +48,5 @@ RSpec.configure do |config|
55
48
  # order dependency and want to debug it, you can fix the order by providing
56
49
  # the seed, which is printed after each run.
57
50
  # --seed 1234
58
- config.order = "random"
51
+ config.order = 'random'
59
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Bovykin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-07 00:00:00.000000000 Z
12
+ date: 2014-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
@@ -228,6 +228,8 @@ files:
228
228
  - lib/generators/redde/layout/templates/base/_validate.haml
229
229
  - lib/generators/redde/layout/templates/base/welcome.haml
230
230
  - lib/generators/redde/layout/templates/controllers/base_controller.rb
231
+ - lib/generators/redde/layout/templates/controllers/managers/registrations_controller.rb
232
+ - lib/generators/redde/layout/templates/controllers/managers_controller.rb
231
233
  - lib/generators/redde/layout/templates/helpers/admin_helper.rb
232
234
  - lib/generators/redde/layout/templates/layouts/admin.html.haml
233
235
  - lib/generators/redde/layout/templates/layouts/login.html.haml
@@ -246,6 +248,7 @@ files:
246
248
  - lib/generators/redde/scaffold/templates/index.html.haml
247
249
  - lib/redde.rb
248
250
  - lib/redde/concerns/layout.rb
251
+ - lib/redde/concerns/photoable.rb
249
252
  - lib/redde/concerns/sluggable.rb
250
253
  - lib/redde/concerns/with_photo.rb
251
254
  - lib/redde/url_generator.rb
@@ -262,6 +265,11 @@ files:
262
265
  - spec/dummy/app/models/.keep
263
266
  - spec/dummy/app/models/article.rb
264
267
  - spec/dummy/app/models/article_category.rb
268
+ - spec/dummy/app/models/photo.rb
269
+ - spec/dummy/app/views/admin/photos/_photo.haml
270
+ - spec/dummy/app/views/admin/photos/_photos.haml
271
+ - spec/dummy/app/views/admin/photos/create.js.erb
272
+ - spec/dummy/app/views/admin/photos/destroy.js.erb
265
273
  - spec/dummy/app/views/articles/show.html.haml
266
274
  - spec/dummy/app/views/layouts/application.html.erb
267
275
  - spec/dummy/bin/bundle
@@ -284,11 +292,10 @@ files:
284
292
  - spec/dummy/config/initializers/wrap_parameters.rb
285
293
  - spec/dummy/config/locales/en.yml
286
294
  - spec/dummy/config/routes.rb
287
- - spec/dummy/db/development.sqlite3
288
295
  - spec/dummy/db/migrate/20130908123351_create_articles.rb
289
296
  - spec/dummy/db/migrate/20140128152208_create_article_categories.rb
297
+ - spec/dummy/db/migrate/20140607122532_create_photos.rb
290
298
  - spec/dummy/db/schema.rb
291
- - spec/dummy/db/test.sqlite3
292
299
  - spec/dummy/lib/assets/.keep
293
300
  - spec/dummy/log/.keep
294
301
  - spec/dummy/public/404.html
@@ -300,6 +307,7 @@ files:
300
307
  - spec/generators/scaffold_generator_spec.rb
301
308
  - spec/models/sluggable_spec.rb
302
309
  - spec/models/url_generator_spec.rb
310
+ - spec/models/with_photo_spec.rb
303
311
  - spec/spec_helper.rb
304
312
  homepage: http://github.com/redde/redde
305
313
  licenses:
@@ -337,6 +345,11 @@ test_files:
337
345
  - spec/dummy/app/models/.keep
338
346
  - spec/dummy/app/models/article.rb
339
347
  - spec/dummy/app/models/article_category.rb
348
+ - spec/dummy/app/models/photo.rb
349
+ - spec/dummy/app/views/admin/photos/_photo.haml
350
+ - spec/dummy/app/views/admin/photos/_photos.haml
351
+ - spec/dummy/app/views/admin/photos/create.js.erb
352
+ - spec/dummy/app/views/admin/photos/destroy.js.erb
340
353
  - spec/dummy/app/views/articles/show.html.haml
341
354
  - spec/dummy/app/views/layouts/application.html.erb
342
355
  - spec/dummy/bin/bundle
@@ -359,11 +372,10 @@ test_files:
359
372
  - spec/dummy/config/initializers/wrap_parameters.rb
360
373
  - spec/dummy/config/locales/en.yml
361
374
  - spec/dummy/config/routes.rb
362
- - spec/dummy/db/development.sqlite3
363
375
  - spec/dummy/db/migrate/20130908123351_create_articles.rb
364
376
  - spec/dummy/db/migrate/20140128152208_create_article_categories.rb
377
+ - spec/dummy/db/migrate/20140607122532_create_photos.rb
365
378
  - spec/dummy/db/schema.rb
366
- - spec/dummy/db/test.sqlite3
367
379
  - spec/dummy/lib/assets/.keep
368
380
  - spec/dummy/log/.keep
369
381
  - spec/dummy/public/404.html
@@ -375,4 +387,5 @@ test_files:
375
387
  - spec/generators/scaffold_generator_spec.rb
376
388
  - spec/models/sluggable_spec.rb
377
389
  - spec/models/url_generator_spec.rb
390
+ - spec/models/with_photo_spec.rb
378
391
  - spec/spec_helper.rb
Binary file
Binary file