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
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  feature 'Dandy stylesheet' do
4
4
  scenario 'store contains dandystylesheet' do
5
5
  visit spree.root_path
6
+
6
7
  expect(page).to(
7
8
  have_xpath('//link[contains(@href, "/dandystyles.css")]', visible: false)
8
9
  )
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Managing stylesheets' 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
+ let(:restore_path) { spree.restore_admin_stylesheets_path }
10
+ let(:style) { 'body {display: none;}' }
11
+ let(:css_path) { 'table#listing_versions tbody tr' }
12
+
13
+ context 'without existing style' do
14
+ scenario 'user views page with no stylesheet' do
15
+ visit show_path
16
+
17
+ expect(page).to have_text Spree.t('dandify.admin.no_resource_found')
18
+ expect(page).to have_text Spree.t('dandify.admin.create_one')
19
+ end
20
+
21
+ scenario 'user can create styles' do
22
+ visit new_path
23
+
24
+ fill_in Spree.t('dandify.admin.labels.style_raw'), with: style
25
+ click_button Spree.t(:create)
26
+
27
+ expect(page).to have_text Spree.t('dandify.admin.title.show')
28
+ end
29
+ end
30
+
31
+ context 'with existing style', versioning: true do
32
+ before { create :stylesheet }
33
+
34
+ scenario 'user does not see audit trail with no revisions' do
35
+ visit show_path
36
+
37
+ expect(page).not_to have_css(css_path, count: 1)
38
+ end
39
+
40
+ scenario 'after first edit user can see previous revisions' do
41
+ visit edit_path
42
+
43
+ fill_in Spree.t('dandify.admin.labels.style_raw'), with: '.moon { display: none}'
44
+ click_button Spree.t(:update)
45
+
46
+ expect(page).to have_css(css_path, count: 2)
47
+ end
48
+
49
+ scenario 'user can edit exiting styles' do
50
+ visit edit_path
51
+
52
+ fill_in Spree.t('dandify.admin.labels.style_raw'), with: style
53
+ click_button Spree.t(:update)
54
+
55
+ expect(page).to have_text(Spree.t('dandify.admin.title.show'))
56
+ end
57
+
58
+ scenario 'user creates new audit trail on edit', versioning: true, js: true do
59
+ visit edit_path
60
+ fill_in Spree.t('dandify.admin.labels.style_raw'), with: style
61
+
62
+ click_button Spree.t(:update)
63
+
64
+ expect(page).to have_css(css_path, count: 2)
65
+ end
66
+ end
67
+
68
+ context 'restoring stylesheet' do
69
+ before { create :stylesheet }
70
+
71
+ scenario 'not possible when there is only one version', versioning: true do
72
+ visit show_path
73
+
74
+ expect(page).not_to have_css(css_path)
75
+ end
76
+
77
+ scenario 'user can restore to previous version', versioning: true, js: true do
78
+ visit edit_path
79
+ fill_in Spree.t('dandify.admin.labels.style_raw'), with: style
80
+
81
+ click_button Spree.t(:update)
82
+
83
+ expect(page).to have_css(css_path, count: 2)
84
+ end
85
+ end
86
+ end
@@ -1,24 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'In the admin' do
3
+ feature 'In the admin sidebar' do
4
4
  stub_authorization!
5
5
 
6
6
  let(:configuration_path) { spree.edit_admin_general_settings_path }
7
- let(:show_path) { spree.admin_stylesheets_path }
8
- let(:new_path) { spree.new_admin_stylesheets_path }
9
- let(:edit_path) { spree.edit_admin_stylesheets_path }
7
+ let(:show_path) { spree.admin_stylesheets_path }
8
+ let(:new_path) { spree.new_admin_stylesheets_path }
9
+ let(:edit_path) { spree.edit_admin_stylesheets_path }
10
10
 
11
11
  context 'on the configuration page' do
12
- it 'the user views Dandify link in sidebar' do
13
- visit configuration_path
14
- expect(page).to have_link(Spree.t('dandify.sidebar'), href: show_path)
15
- end
12
+ before { visit configuration_path }
16
13
 
17
14
  it 'the user views non-highlighted Dandify link in sidebar' do
18
- visit configuration_path
19
15
  expect(page).to_not(
20
16
  have_selector(:css, "li.active a[href='#{show_path}']")
21
17
  )
18
+ expect(page).to have_link(
19
+ Spree.t('dandify.admin.sidebar'), href: show_path
20
+ )
22
21
  end
23
22
  end
24
23
 
@@ -26,16 +25,25 @@ describe 'In the admin' do
26
25
  it 'on Dandify show page' do
27
26
  visit show_path
28
27
  expect(page).to have_selector(:css, "li.active a[href='#{show_path}']")
28
+ expect(page).to have_link(
29
+ Spree.t('dandify.admin.sidebar'), href: show_path
30
+ )
29
31
  end
30
32
 
31
33
  it 'on Dandify edit page' do
32
34
  visit edit_path
33
35
  expect(page).to have_selector(:css, "li.active a[href='#{show_path}']")
36
+ expect(page).to have_link(
37
+ Spree.t('dandify.admin.sidebar'), href: show_path
38
+ )
34
39
  end
35
40
 
36
41
  it 'on Dandify new page' do
37
42
  visit new_path
38
43
  expect(page).to have_selector(:css, "li.active a[href='#{show_path}']")
44
+ expect(page).to have_link(
45
+ Spree.t('dandify.admin.sidebar'), href: show_path
46
+ )
39
47
  end
40
48
  end
41
49
  end
@@ -1,13 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::Admin::NavigationHelper do
4
- describe '#link_to_restore_url' do
5
- let(:restore_path) { spree.edit_admin_stylesheets_path }
3
+ module Spree
4
+ module Admin
5
+ describe NavigationHelper do
6
+ describe '#link_to_restore_url' do
7
+ let(:restore_path) { spree.edit_admin_stylesheets_path }
6
8
 
7
- context 'link to restore URL' do
8
- it 'should build circular restore button' do
9
- restore_button = helper.link_to_restore_url(restore_path)
10
- restore_button.should include(Spree.t('dandify.confirm.restore'))
9
+ context 'link to restore URL' do
10
+ it 'should build circular restore button' do
11
+ restore_button = helper.link_to_restore_url(restore_path)
12
+
13
+ expect(restore_button).
14
+ to include(Spree.t('dandify.admin.confirm.restore'))
15
+ end
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StylesheetHelper do
6
+ describe '#dandify_version_email' do
7
+ context 'with nil or unknown values' do
8
+ let(:fake_unknown_user) { instance_double(UnknownUser, email: 'foo') }
9
+
10
+ before do
11
+ allow(UnknownUser).to receive(:new) { fake_unknown_user }
12
+ end
13
+
14
+ context 'when user_id is nil' do
15
+ it 'instantiates a new UknownUser and calls #email' do
16
+ helper.dandify_version_email(nil)
17
+
18
+ expect(UnknownUser).to have_received(:new)
19
+ expect(fake_unknown_user).to have_received(:email)
20
+ end
21
+ end
22
+
23
+ context 'when user_id equals Spree.t("dandify.admin.unknown")' do
24
+ it 'instantiates a new UknownUser and calls #email' do
25
+ helper.dandify_version_email(Spree.t('dandify.admin.unknown'))
26
+
27
+ expect(UnknownUser).to have_received(:new)
28
+ expect(fake_unknown_user).to have_received(:email)
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'with everything else' do
34
+ it 'sends user_id to User#find and calls email' do
35
+ fake_user = instance_double(User, email: 'foo')
36
+ allow(User).to receive(:find) { fake_user }
37
+
38
+ helper.dandify_version_email('1')
39
+
40
+ expect(User).to have_received(:find).with '1'
41
+ expect(fake_user).to have_received(:email)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::BlankStylesheet, '#style_compressed' do
4
- it 'returns a blank string' do
5
- expect(Spree::BlankStylesheet.new.style_compressed).to eq ''
3
+ module Spree
4
+ describe BlankStylesheet, '#style_compressed' do
5
+ it 'returns a blank string' do
6
+ expect(subject.style_compressed).to eq ''
7
+ end
6
8
  end
7
9
  end
@@ -1,102 +1,106 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::Stylesheet do
4
- context 'versions', versioning: true do
5
- it { should be_versioned }
3
+ module Spree
4
+ describe Stylesheet do
5
+ context 'versions', versioning: true do
6
+ it { should be_versioned }
6
7
 
7
- it 'restores previous versions' do
8
- style = create :stylesheet
9
- style.update style_raw: 'h1{display:none; color: blue;}'
8
+ it 'restores previous versions' do
9
+ style = create :stylesheet
10
+ style.update style_raw: 'h1{display:none; color: blue;}'
10
11
 
11
- expect(style.versions.size).to eq(2)
12
+ expect(style.versions.size).to eq(2)
13
+ end
12
14
  end
13
- end
14
15
 
15
- context 'validations' do
16
- let(:valid_css) { '#main {background-color: #0000ff}' }
17
- let(:invalid_css) { 'main {background-color #0000ff}' }
16
+ context 'validations' do
17
+ let(:valid_css) { '#main {background-color: #0000ff}' }
18
+ let(:invalid_css) { 'main {background-color #0000ff}' }
18
19
 
19
- it { should validate_presence_of(:style_raw) }
20
+ it { should validate_presence_of(:style_raw) }
20
21
 
21
- it 'pass with proper vanilla syntax' do
22
- expect(style_with valid_css).to be_valid
23
- end
22
+ it 'pass with proper vanilla syntax' do
23
+ expect(style_with valid_css).to be_valid
24
+ end
24
25
 
25
- it 'fail with bad vanilla syntax' do
26
- expect(style_with invalid_css).to_not be_valid
26
+ it 'fail with bad vanilla syntax' do
27
+ expect(style_with invalid_css).to_not be_valid
28
+ end
27
29
  end
28
- end
29
30
 
30
- context 'processing raw' do
31
- it 'allows both css and scss' do
32
- expect(style_with(<<-CSS)).to be_valid
31
+ context 'processing raw' do
32
+ it 'allows both css and scss' do
33
+ expect(style_with(<<-CSS)).to be_valid
33
34
 
34
- $font-stack: Helvetica, sans-serif;
35
+ $font-stack: Helvetica, sans-serif;
35
36
 
36
- body {
37
- font: 100% $font-stack
38
- }
37
+ body {
38
+ font: 100% $font-stack
39
+ }
39
40
 
40
- h1 { display: inline ;}
41
+ h1 { display: inline ;}
41
42
 
42
- CSS
43
- end
43
+ CSS
44
+ end
44
45
 
45
- context 'compresses' do
46
- it 'vanilla css' do
47
- compressed = "#main{display:block}.foo{width:300px;height:200px}\n"
48
- expect(create_style_with(<<-CSS).style_compressed).to eq compressed
46
+ context 'compresses' do
47
+ it 'vanilla css' do
48
+ compressed = "#main{display:block}.foo{width:300px;height:200px}\n"
49
+ expect(create_style_with(<<-CSS).style_compressed).to eq compressed
49
50
 
50
- #main {
51
- display: block;
52
- }
51
+ #main {
52
+ display: block;
53
+ }
53
54
 
54
- .foo {
55
- width: 300px;
56
- height: 200px;
57
- }
55
+ .foo {
56
+ width: 300px;
57
+ height: 200px;
58
+ }
58
59
 
59
- CSS
60
- end
60
+ CSS
61
+ end
61
62
 
62
- it 'compresses scss' do
63
- compressed = "nav ul{margin:0;padding:0}a{display:block}\n"
64
- expect(create_style_with(<<-CSS).style_compressed).to eq compressed
63
+ it 'compresses scss' do
64
+ compressed = "nav ul{margin:0;padding:0}a{display:block}\n"
65
+ expect(create_style_with(<<-CSS).style_compressed).to eq compressed
65
66
 
66
- nav {
67
- ul {
68
- margin: 0;
69
- padding: 0;
67
+ nav {
68
+ ul {
69
+ margin: 0;
70
+ padding: 0;
71
+ }
70
72
  }
71
- }
72
73
 
73
- a {
74
- display: block;
75
- }
74
+ a {
75
+ display: block;
76
+ }
76
77
 
77
- CSS
78
+ CSS
79
+ end
78
80
  end
79
81
  end
80
- end
81
82
 
82
- def create_style_with(css)
83
- style = style_with(css)
84
- style.save
85
- style
86
- end
83
+ def create_style_with(css)
84
+ style = style_with(css)
85
+ style.save
86
+ style
87
+ end
87
88
 
88
- def style_with(css)
89
- Spree::Stylesheet.new(style_raw: css)
89
+ def style_with(css)
90
+ Spree::Stylesheet.new(style_raw: css)
91
+ end
90
92
  end
91
- end
92
93
 
93
- describe Spree::Stylesheet, '#load_style' do
94
- it 'returns Blanksheet when no sheet is found' do
95
- expect(Spree::Stylesheet.load_style).to be_a Spree::BlankStylesheet
96
- end
94
+ describe Stylesheet, '#load_style' do
95
+ it 'returns Blanksheet when no sheet is found' do
96
+ expect(described_class.load_style).to be_a Spree::BlankStylesheet
97
+ end
97
98
 
98
- it 'returns a found instance of itself' do
99
- styles = create :stylesheet
100
- expect(Spree::Stylesheet.load_style).to eq styles
99
+ it 'returns a found instance of itself' do
100
+ styles = create :stylesheet
101
+ expect(described_class.load_style).to eq styles
102
+ end
101
103
  end
102
104
  end
105
+
106
+
@@ -10,30 +10,33 @@ rescue LoadError
10
10
  exit
11
11
  end
12
12
 
13
- require 'rspec/rails'
14
- require 'shoulda-matchers'
15
- require 'ffaker'
16
- require 'database_cleaner'
17
13
  require 'capybara'
18
- require 'capybara/rspec'
19
- require 'capybara/rails'
20
14
  require 'capybara/poltergeist'
15
+ require 'capybara/rails'
16
+ require 'capybara/rspec'
17
+ require 'database_cleaner'
18
+ require 'ffaker'
21
19
  require 'paper_trail/frameworks/rspec'
20
+ require 'pry-byebug'
21
+ require 'rspec/rails'
22
+ require 'shoulda-matchers'
22
23
 
23
24
  Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
24
25
 
25
- require 'spree/testing_support/factories'
26
- require 'spree/testing_support/controller_requests'
27
26
  require 'spree/testing_support/authorization_helpers'
28
- require 'spree/testing_support/url_helpers'
29
27
  require 'spree/testing_support/capybara_ext'
28
+ require 'spree/testing_support/controller_requests'
29
+ require 'spree/testing_support/factories'
30
+ require 'spree/testing_support/url_helpers'
31
+
32
+ Capybara.javascript_driver = :poltergeist
30
33
 
31
34
  FactoryGirl.find_definitions
32
35
 
33
36
  RSpec.configure do |config|
34
37
  config.deprecation_stream = 'rspec.log'
35
- config.include Spree::TestingSupport::ControllerRequests
36
38
  config.include FactoryGirl::Syntax::Methods
39
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
37
40
  config.include Spree::TestingSupport::UrlHelpers
38
41
  config.include Devise::TestHelpers, type: :controller
39
42
  config.use_transactional_fixtures = false
@@ -54,6 +57,4 @@ RSpec.configure do |config|
54
57
  config.after do
55
58
  DatabaseCleaner.clean
56
59
  end
57
-
58
- Capybara.javascript_driver = :poltergeist
59
60
  end