dandify 0.0.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -8
  3. data/Rakefile +2 -2
  4. data/app/assets/stylesheets/spree/backend/dandify.scss +55 -0
  5. data/app/controllers/spree/admin/stylesheets_controller.rb +17 -8
  6. data/app/controllers/spree/stylesheets_controller.rb +3 -3
  7. data/app/helpers/spree/admin/navigation_helper_decorator.rb +20 -4
  8. data/app/helpers/spree/admin/stylesheet_helper.rb +12 -2
  9. data/app/models/spree/stylesheet_version.rb +2 -1
  10. data/app/models/spree/unknown_user.rb +11 -0
  11. data/app/models/spree/user_decorator.rb +1 -1
  12. data/app/models/spree/user_identifier.rb +13 -0
  13. data/app/overrides/spree/admin/shared/{_configuration_menu → sub_menu/_configuration}/add_dandify_to_admin_configuration_sidebar.html.erb.deface +1 -1
  14. data/app/views/spree/admin/stylesheets/_form.html.erb +29 -7
  15. data/app/views/spree/admin/stylesheets/_versions.html.erb +16 -19
  16. data/app/views/spree/admin/stylesheets/edit.html.erb +4 -5
  17. data/app/views/spree/admin/stylesheets/new.html.erb +4 -5
  18. data/app/views/spree/admin/stylesheets/show.html.erb +22 -8
  19. data/config/locales/en.yml +39 -27
  20. data/config/routes.rb +1 -1
  21. data/db/migrate/20140617221725_add_paper_trail_versions.rb +5 -5
  22. data/lib/dandify.rb +0 -1
  23. data/lib/dandify/version.rb +1 -1
  24. data/lib/generators/dandify/install/install_generator.rb +10 -9
  25. data/spec/controllers/spree/admin/stylesheets_controller_spec.rb +109 -55
  26. data/spec/controllers/spree/stylesheets_controller_spec.rb +26 -22
  27. data/spec/features/buttons_spec.rb +69 -0
  28. data/spec/features/dandy_style_spec.rb +1 -0
  29. data/spec/features/managing_stylesheet_spec.rb +86 -0
  30. data/spec/features/sidebar_spec.rb +17 -9
  31. data/spec/helpers/admin/navigation_helper_spec.rb +13 -7
  32. data/spec/helpers/admin/stylesheet_helper_spec.rb +47 -0
  33. data/spec/models/spree/blank_stylesheet_spec.rb +5 -3
  34. data/spec/models/spree/stylesheet_spec.rb +73 -69
  35. data/spec/spec_helper.rb +13 -12
  36. metadata +47 -59
  37. data/app/assets/stylesheets/spree/backend/dandify.css +0 -42
  38. data/config/spring.rb +0 -1
  39. data/lib/tasks/dandify_tasks.rake +0 -4
  40. data/spec/features/managing_stylsheet_spec.rb +0 -80
  41. data/spec/features/viewing_admin_spec.rb +0 -49
@@ -1,37 +1,49 @@
1
1
  ---
2
2
  en:
3
- activerecord:
4
- attributes:
5
- spree/stylesheet:
6
- style_raw: Styles
7
3
  spree:
8
4
  dandify:
9
- unknown: Unknown
10
- sidebar: Store Stylesheet
11
- show:
12
- title: Custom Styles
5
+ admin:
6
+ action:
7
+ create: Created
8
+ update: Revised
9
+ destroy: Deleted
10
+ unknown: Unknown
11
+ no_resource_found: No stylesheet found
12
+ create_one: Let's get dandy
13
+ sidebar: Store Stylesheet
14
+ confirm:
15
+ restore: Are you sure you want to restore this version of the stylesheet?
16
+ destroy: Are you sure you want to delete your stylesheet?
13
17
  buttons:
14
- new: Create stylesheet
15
- edit: Edit stylesheet
16
- none: No custom style yet! Let's get dandy!
18
+ new: Create Stylesheet
19
+ edit: Edit
20
+ destroy: Delete
21
+ icons:
22
+ restore: Restore
23
+ destroy: Destroy
24
+ title:
25
+ show: Custom Styles
26
+ new: Creating Custom Styles
27
+ edit: Editing Custom Styles
28
+ flash:
29
+ success:
30
+ new: New stylesheet has been created.
31
+ edit: Stylesheet has been updated. A new revision has been created.
32
+ restore: Stylesheet has been restored. A new revision has been created.
33
+ destroyed: Stylesheet has been destroyed. A new revision has been created.
34
+ error:
35
+ restore: Unable to restore stylesheet.
17
36
  headers:
18
- created_at: Created
37
+ on: On
19
38
  author: Author
20
39
  action: Action
21
- new:
22
- title: Creating Custom Styles
23
- success: New stylesheet has been created.
24
- edit:
25
- title: Editing Custom Styles
26
- success: Stylesheet has been updated. A new revision has been created.
27
- restore:
28
- name: Restore
29
- success: Stylesheet has been restored. A new revision has been created.
30
- error: Unable to restore stylesheet.
31
- form:
32
- fieldset: Stylesheet
33
- label: Styles
40
+ revision: Revisions
41
+ labels: &dandify_labels
42
+ style_raw: Styles
34
43
  notes:
35
44
  sass: Stylesheets are compiled and minified using a CSS preprocessor. Valid SCSS can be used here.
36
- confirm:
37
- restore: Are you sure you want to restore this version of the stylesheet?
45
+
46
+ activerecord:
47
+ attributes:
48
+ spree/stylesheet:
49
+ <<: *dandify_labels
@@ -1,7 +1,7 @@
1
1
  Spree::Core::Engine.add_routes do
2
2
  namespace :admin do
3
3
  resource :stylesheets do
4
- post 'restore', to: 'stylesheets#restore'
4
+ post :restore
5
5
  end
6
6
  end
7
7
 
@@ -1,11 +1,11 @@
1
1
  class AddPaperTrailVersions < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :versions do |t|
4
- t.string :item_type, :null => false
5
- t.integer :item_id, :null => false
6
- t.string :event, :null => false
7
- t.string :whodunnit
8
- t.text :object
4
+ t.string :item_type, null: false
5
+ t.integer :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.text :object
9
9
  t.datetime :created_at
10
10
  end
11
11
  add_index :versions, [:item_type, :item_id]
@@ -1,5 +1,4 @@
1
1
  require 'spree_core'
2
- require 'sass'
3
2
  require 'paper_trail'
4
3
  require 'dandify/engine'
5
4
 
@@ -1,3 +1,3 @@
1
1
  module Dandify
2
- VERSION = '0.0.1'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -3,21 +3,22 @@ module Dandify
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  class_option :auto_run_migrations, type: :boolean, default: true
5
5
 
6
- def add_migrations
7
- run 'bundle exec rake railties:install:migrations FROM=dandify'
6
+ def add_javascripts
7
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/dandify\n"
8
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/dandify\n"
8
9
  end
9
10
 
10
11
  def add_stylesheets
11
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', "*= require spree/backend/dandify\n", before: /\*\//, verbose: true
12
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', "*= require spree/frontend/dandify\n ", before: /\*\//, verbose: true
13
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', "*= require spree/backend/dandify\n ", before: /\*\//, verbose: true
14
+ end
15
+
16
+ def add_migrations
17
+ run 'bundle exec rake railties:install:migrations FROM=dandify'
12
18
  end
13
19
 
14
20
  def run_migrations
15
- res = ask('Would you like to run the migrations now? [Y/n]').downcase
16
- if ['', 'y'].include?(res)
17
- run 'bundle exec rake db:migrate'
18
- else
19
- logger 'Skipping rake db:migrate, don\'t forget to run it!'
20
- end
21
+ run 'bundle exec rake db:migrate'
21
22
  end
22
23
  end
23
24
  end
@@ -1,71 +1,125 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::Admin::StylesheetsController do
4
- stub_authorization!
3
+ module Spree
4
+ module Admin
5
+ describe StylesheetsController, type: :controller do
6
+ stub_authorization!
5
7
 
6
- let(:show_path) { spree.admin_stylesheets_path }
7
- let(:good_style) { 'body {color:#ffff00;}' }
8
- let(:bad_style) { 'body {color:#ffff00;' }
8
+ let(:show_path) { spree.admin_stylesheets_path }
9
+ let(:good_style) { 'body {color:#ffff00;}' }
10
+ let(:bad_style) { 'body {color:#ffff00;' }
9
11
 
10
- before do
11
- user = create :admin_user
12
- controller.stub(try_spree_current_user: user)
13
- end
12
+ before do
13
+ user = create :admin_user
14
+ controller.stub(try_spree_current_user: user)
15
+ end
14
16
 
15
- context '#show' do
16
- it 'assigns new instance when none is found' do
17
- spree_get :show
18
- expect(assigns[:style]).to be_new_record
19
- end
17
+ describe 'GET #show' do
18
+ it 'assigns new instance when none is found' do
19
+ spree_get :show
20
20
 
21
- it 'assigns existing' do
22
- style = create :stylesheet
23
- spree_get :show
24
- expect(assigns[:style]).to eq style
25
- end
26
- end
21
+ expect(assigns[:style]).to be_new_record
22
+ end
27
23
 
28
- context '#new' do
29
- it 'can create first a revision' do
30
- style = create :stylesheet
31
- spree_get :show
32
- expect(assigns[:style]).to eq style
33
- expect(response).to render_template(:show)
34
- end
24
+ it 'assigns existing' do
25
+ style = create :stylesheet
35
26
 
36
- it 'can not create first revision because error' do
37
- spree_post :create, stylesheet: { style_raw: bad_style }
38
- expect(response).to render_template(:new)
39
- end
40
- end
27
+ spree_get :show
41
28
 
42
- context '#edit' do
43
- it 'can create a revision' do
44
- create :stylesheet
45
- spree_get :show
46
- expect(response).to render_template(:show)
47
- end
29
+ expect(assigns[:style]).to eq style
30
+ end
31
+ end
48
32
 
49
- it 'can not create a revision because error' do
50
- spree_post :update, stylesheet: { style_raw: bad_style }
51
- expect(response).to render_template(:edit)
52
- end
53
- end
33
+ describe 'GET #new' do
34
+ it 'renders template' do
35
+ spree_get :new
54
36
 
55
- context '#restore', versioning: true do
56
- before { create :stylesheet }
37
+ expect(response).to render_template(:new)
38
+ end
39
+ end
57
40
 
58
- it 'fails to reify when there is only one revision' do
59
- spree_post :restore
60
- expect(flash[:error]).to eq Spree.t('dandify.restore.error')
61
- expect(response).to redirect_to show_path
62
- end
41
+ describe 'POST #create' do
42
+ it 'redirects to show with good data' do
43
+ spree_post :create,
44
+ stylesheet: { style_raw: '#main { display: inline; }' }
45
+
46
+ expect(response).to redirect_to(admin_stylesheets_path)
47
+ end
48
+
49
+ it 'renders new with bad data' do
50
+ spree_post :create, stylesheet: { style_raw: bad_style }
51
+
52
+ expect(response).to render_template(:new)
53
+ end
54
+ end
55
+
56
+ describe 'GET #edit' do
57
+ it 'can create a revision' do
58
+ stylesheet = create :stylesheet
59
+
60
+ spree_get :edit
61
+
62
+ expect(assigns[:style]).to eq stylesheet
63
+ end
64
+ end
65
+
66
+ describe 'PUT #update' do
67
+ before { create :stylesheet }
68
+
69
+ it 'redirects to show with good data' do
70
+ spree_post :update,
71
+ stylesheet: { style_raw: '#main { display: inline; }' }
72
+
73
+ expect(response).to redirect_to(admin_stylesheets_path)
74
+ end
75
+
76
+ it 'renders edit with bad data' do
77
+ spree_post :update, stylesheet: { style_raw: bad_style }
78
+
79
+ expect(response).to render_template(:edit)
80
+ end
81
+ end
82
+
83
+ describe 'POST #restore', versioning: true do
84
+ before { create :stylesheet }
85
+
86
+ it 'fails to reify when there is only one revision' do
87
+ spree_post :restore
88
+
89
+ expect(flash[:error]).to eq(
90
+ Spree.t('dandify.admin.flash.error.restore')
91
+ )
92
+
93
+ expect(response).to redirect_to show_path
94
+ end
95
+
96
+ it 'able to reify when there is more than one revision' do
97
+ style = Spree::Stylesheet.first
98
+
99
+ style.update_attributes style_raw: '#main { display: block; }'
100
+ style.update_attributes style_raw: '#main { display: none; }'
101
+
102
+ spree_post :restore, id: PaperTrail::Version.second.id
103
+
104
+ expect(flash[:success]).to eq(
105
+ Spree.t('dandify.admin.flash.success.restore')
106
+ )
107
+ expect(response).to redirect_to show_path
108
+ end
109
+ end
110
+
111
+ describe 'DELETE #destroy' do
112
+ it 'sends #destroy to returned model from #first_or_initialize' do
113
+ fake_stylesheet = instance_double(Spree::Stylesheet, destroy: true)
114
+ allow(Spree::Stylesheet).to receive(:first_or_initialize).
115
+ and_return fake_stylesheet
116
+
117
+ spree_delete :destroy
63
118
 
64
- it 'able to reify when there is more than one revision' do
65
- spree_post :update, stylesheet: { style_raw: good_style }
66
- spree_post :restore
67
- expect(flash[:success]).to eq Spree.t('dandify.restore.success')
68
- expect(response).to redirect_to show_path
119
+ expect(fake_stylesheet).to have_received(:destroy)
120
+ expect(response).to redirect_to admin_stylesheets_path
121
+ end
122
+ end
69
123
  end
70
124
  end
71
125
  end
@@ -1,36 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::StylesheetsController, '#show' do
4
- context 'with a bad format' do
5
- it 'responds with blank sheet' do
6
- spree_get :show, format: :xml
3
+ module Spree
4
+ describe StylesheetsController, '#show', type: :controller do
5
+ stub_authorization!
7
6
 
8
- expect(response.header['Content-Type']).to include 'text/css'
9
- end
7
+ context 'with a bad format' do
8
+ it 'responds with blank sheet' do
9
+ spree_get :show, format: :xml
10
+
11
+ expect(response.header['Content-Type']).to include 'text/css'
12
+ end
10
13
 
11
- it 'responds with found sheet' do
12
- css = create(:stylesheet).style_compressed
13
- spree_get :show, format: :atom
14
+ it 'responds with found sheet' do
15
+ css = create(:stylesheet).style_compressed
16
+ spree_get :show, format: :atom
14
17
 
15
- expect(response.header['Content-Type']).to include 'text/css'
16
- expect(assigns[:style].style_compressed).to eq css
18
+ expect(response.header['Content-Type']).to include 'text/css'
19
+ expect(assigns[:style].style_compressed).to eq css
20
+ end
17
21
  end
18
- end
19
22
 
20
- context 'when there is no stylesheet' do
21
- it 'displays a blank stylesheet' do
22
- spree_get :show, format: :css
23
+ context 'when there is no stylesheet' do
24
+ it 'displays a blank stylesheet' do
25
+ spree_get :show, format: :css
23
26
 
24
- expect(assigns[:style]).to be_a Spree::BlankStylesheet
27
+ expect(assigns[:style]).to be_a Spree::BlankStylesheet
28
+ end
25
29
  end
26
- end
27
30
 
28
- context 'when there is a stylesheet' do
29
- it 'assigns the stored sheet' do
30
- create :stylesheet
31
- spree_get :show, format: :css
31
+ context 'when there is a stylesheet' do
32
+ it 'assigns the stored sheet' do
33
+ create :stylesheet
34
+ spree_get :show, format: :css
32
35
 
33
- expect(assigns[:style]).to be_a Spree::Stylesheet
36
+ expect(assigns[:style]).to be_a Spree::Stylesheet
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Managing stylesheet' do
4
+ stub_authorization!
5
+
6
+ let(:show_path) { spree.admin_stylesheets_path }
7
+ let(:new_path) { spree.new_admin_stylesheets_path }
8
+ let(:edit_path) { spree.edit_admin_stylesheets_path }
9
+
10
+ context 'create stylesheet link' do
11
+ it 'is available when there are no stylesheets' do
12
+ visit show_path
13
+
14
+ expect(page).to have_link(
15
+ Spree.t('dandify.admin.buttons.new'), href: new_path
16
+ )
17
+ end
18
+
19
+ it 'is not available when there are stylesheets' do
20
+ create(:stylesheet)
21
+
22
+ visit show_path
23
+
24
+ expect(page).to_not have_link(
25
+ Spree.t('dandify.admin.buttons.new'), href: new_path
26
+ )
27
+ end
28
+ end
29
+
30
+ context 'edit stylesheet link' do
31
+ it 'is not available when there are stylesheets' do
32
+ visit show_path
33
+
34
+ expect(page).to_not have_link(
35
+ Spree.t('dandify.admin.buttons.edit'), href: edit_path
36
+ )
37
+ end
38
+
39
+ it 'is available when there are stylesheets' do
40
+ create(:stylesheet)
41
+
42
+ visit show_path
43
+
44
+ expect(page).to have_link(
45
+ Spree.t('dandify.admin.buttons.edit'), href: edit_path
46
+ )
47
+ end
48
+ end
49
+
50
+ context 'cancel button' do
51
+ it 'is available on `new` page' do
52
+ visit new_path
53
+
54
+ expect(page).to have_link(Spree.t('actions.cancel'), href: show_path)
55
+ end
56
+
57
+ it 'is available on `edit` page' do
58
+ visit edit_path
59
+
60
+ expect(page).to have_link(Spree.t('actions.cancel'), href: show_path)
61
+ end
62
+
63
+ it 'is not available on listing page' do
64
+ visit show_path
65
+
66
+ expect(page).not_to have_link(Spree.t('actions.cancel'), href: show_path)
67
+ end
68
+ end
69
+ end