spree_essentials 0.4.0.rc2 → 0.4.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +11 -0
  3. data/CHANGELOG.md +125 -0
  4. data/Gemfile +6 -0
  5. data/README.md +79 -112
  6. data/Versionfile +7 -0
  7. data/app/assets/javascripts/{date.js → admin/date.js} +0 -0
  8. data/app/assets/javascripts/{jquery.autodate.js → admin/jquery.autodate.js} +0 -0
  9. data/app/assets/javascripts/{jquery.markitup.js → admin/jquery.markitup.js} +1 -1
  10. data/app/assets/javascripts/{markdown.set.js → admin/markdown.set.js} +0 -0
  11. data/app/assets/javascripts/admin/spree_essentials.js +1 -0
  12. data/app/assets/stylesheets/{markitup.css.erb → admin/markitup.css.erb} +5 -0
  13. data/app/assets/stylesheets/admin/spree_essentials.css +3 -0
  14. data/app/controllers/spree/admin/markdown_controller.rb +1 -1
  15. data/app/controllers/spree/admin/uploads_controller.rb +0 -4
  16. data/app/helpers/spree/admin/spree_essentials_helper.rb +16 -10
  17. data/app/models/spree/upload.rb +5 -3
  18. data/app/overrides/admin/spree_essentials.rb +13 -0
  19. data/app/views/spree/admin/shared/_contents_sub_menu.html.erb +9 -7
  20. data/app/views/spree/admin/uploads/edit.html.erb +0 -2
  21. data/app/views/spree/admin/uploads/index.html.erb +0 -1
  22. data/app/views/spree/admin/uploads/new.html.erb +0 -2
  23. data/config/routes.rb +5 -4
  24. data/{lib/generators/templates/db/migrate/add_attachment_file_size_to_assets.rb → db/migrate/20120306185618_add_attachment_file_size_to_assets.rb} +0 -0
  25. data/lib/generators/spree_essentials/install_generator.rb +16 -6
  26. data/lib/spree_essentials.rb +5 -24
  27. data/lib/spree_essentials/engine.rb +25 -0
  28. data/lib/spree_essentials/{test_helper.rb → testing/integration_case.rb} +13 -30
  29. data/lib/spree_essentials/testing/test_helper.rb +30 -0
  30. data/lib/spree_essentials/version.rb +1 -1
  31. data/spree_essentials.gemspec +34 -0
  32. data/test/dummy_hooks/after_migrate.rb.sample +1 -0
  33. data/test/dummy_hooks/before_migrate.rb +30 -0
  34. data/test/dummy_hooks/templates/admin/all.css +3 -0
  35. data/test/dummy_hooks/templates/admin/all.js +1 -0
  36. data/test/dummy_hooks/templates/spree_user_error_fix.rb +3 -0
  37. data/test/dummy_hooks/templates/store/all.css +3 -0
  38. data/test/dummy_hooks/templates/store/all.js +1 -0
  39. data/test/dummy_hooks/templates/store/screen.css +749 -0
  40. data/test/integration/spree/admin/extension_integration_test.rb +50 -0
  41. data/test/integration/spree/admin/markdown_integration_test.rb +50 -0
  42. data/test/integration/spree/admin/upload_integration_test.rb +85 -0
  43. data/test/integration_test_helper.rb +2 -0
  44. data/test/spree_essential_example/README.md +3 -0
  45. data/test/spree_essential_example/app/controllers/spree/admin/examples_controller.rb +26 -0
  46. data/test/spree_essential_example/app/models/spree/example.rb +2 -0
  47. data/test/spree_essential_example/app/views/spree/admin/examples/_form.html.erb +21 -0
  48. data/test/spree_essential_example/app/views/spree/admin/examples/edit.html.erb +12 -0
  49. data/test/spree_essential_example/app/views/spree/admin/examples/index.html.erb +26 -0
  50. data/test/spree_essential_example/app/views/spree/admin/examples/new.html.erb +13 -0
  51. data/test/spree_essential_example/app/views/spree/admin/examples/show.html.erb +8 -0
  52. data/test/spree_essential_example/config/routes.rb +5 -0
  53. data/test/spree_essential_example/db/migrate/20120307043727_create_spree_examples.rb +12 -0
  54. data/test/spree_essential_example/lib/generators/spree_essentials/example_generator.rb +13 -0
  55. data/test/spree_essential_example/lib/spree_essential_example.rb +18 -0
  56. data/test/spree_essential_example/lib/spree_essential_example/engine.rb +21 -0
  57. data/test/spree_essential_example/lib/spree_essential_example/version.rb +3 -0
  58. data/test/spree_essential_example/spree_essential_example.gemspec +23 -0
  59. data/test/support/files/1.gif +0 -0
  60. data/test/support/files/1.jpg +0 -0
  61. data/test/support/files/1.png +0 -0
  62. data/test/support/files/2.gif +0 -0
  63. data/test/support/files/2.jpg +0 -0
  64. data/test/support/files/2.png +0 -0
  65. data/test/support/files/3.gif +0 -0
  66. data/test/support/files/3.jpg +0 -0
  67. data/test/support/files/3.png +0 -0
  68. data/test/support/files/test.pdf +0 -0
  69. data/test/support/files/test.zip +0 -0
  70. data/test/test_helper.rb +14 -0
  71. data/test/unit/spree/asset_test.rb +18 -0
  72. data/test/unit/spree/extension_test.rb +33 -0
  73. data/test/unit/spree/helpers/admin/spree_essentials_helper_test.rb +38 -0
  74. data/test/unit/spree/upload_test.rb +52 -0
  75. data/test/unit/validators/datetime_validator_test.rb +29 -0
  76. metadata +144 -47
  77. data/app/overrides/spree_essentials.rb +0 -5
  78. data/lib/generators/essentials_base.rb +0 -32
@@ -0,0 +1,50 @@
1
+ require "integration_test_helper"
2
+
3
+ class Spree::Admin::ExtensionIntegrationTest < SpreeEssentials::IntegrationCase
4
+
5
+ setup do
6
+ SpreeEssentials.essentials.clear
7
+ end
8
+
9
+ context "When no extensions are registered" do
10
+
11
+ should "have a contents tab with only uploads in the sub nav" do
12
+ visit spree.admin_orders_path
13
+ within "#admin-menu" do
14
+ assert has_link?("Content")
15
+ end
16
+ click_link "Content"
17
+ within "#sub-menu" do
18
+ assert has_link?("Uploads")
19
+ end
20
+ assert has_css?("#sub-menu li", :count => 1)
21
+ end
22
+
23
+ end
24
+
25
+ context "When an extension is registered" do
26
+
27
+ setup do
28
+ SpreeEssentials.register :example, SpreeEssentialExample
29
+ end
30
+
31
+ teardown do
32
+ SpreeEssentials.essentials.clear
33
+ end
34
+
35
+ should "have a contents tab with examples and uploads in the sub nav" do
36
+ visit spree.admin_orders_path
37
+ within "#admin-menu" do
38
+ assert has_link?("Content")
39
+ end
40
+ click_link "Content"
41
+ within "#sub-menu" do
42
+ assert has_link?("Examples")
43
+ assert has_link?("Uploads")
44
+ end
45
+ assert has_css?("#sub-menu li", :count => 2)
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require "integration_test_helper"
2
+
3
+ class Spree::Admin::MarkdownIntegrationTest < SpreeEssentials::IntegrationCase
4
+
5
+ setup do
6
+ SpreeEssentials.register :example, SpreeEssentialExample
7
+ end
8
+
9
+ teardown do
10
+ SpreeEssentials.essentials.clear
11
+ end
12
+
13
+ MARKDOWN = <<MD
14
+
15
+ ### OMG
16
+
17
+ * item 1
18
+
19
+ **bold!** & _italic_
20
+
21
+ [just a link](http://example.com)
22
+
23
+ MD
24
+
25
+ def assert_markdown_renders
26
+ assert_seen "OMG", :within => "h3"
27
+ assert_seen "item 1", :within => "ul li"
28
+ assert_seen "bold!", :within => "strong"
29
+ assert_seen "italic", :within => "em"
30
+ assert has_link?("just a link", :href => "http://example.com")
31
+ end
32
+
33
+ should "render have markdown editor and render it's result" do
34
+ visit spree.new_admin_example_path
35
+ fill_in "Title", :with => "Just an example"
36
+ fill_in "Body", :with => MARKDOWN
37
+ within ".markItUpHeader" do
38
+ click_link "Preview"
39
+ end
40
+ within_frame "markItUpPreviewFrame" do
41
+ assert_markdown_renders
42
+ end
43
+ click_button "Create"
44
+ assert_equal spree.admin_example_path(Spree::Example.last), current_path
45
+ within ".markdown-result" do
46
+ assert_markdown_renders
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,85 @@
1
+ require "integration_test_helper"
2
+
3
+ class Spree::Admin::UploadIntegrationTest < SpreeEssentials::IntegrationCase
4
+
5
+ def setup
6
+ Spree::Upload.destroy_all
7
+ @image = File.expand_path("../../../../support/files/1.png", __FILE__)
8
+ @image2 = File.expand_path("../../../../support/files/2.png", __FILE__)
9
+ end
10
+
11
+ should "have a contents tab" do
12
+ visit spree.admin_orders_path
13
+ within "#admin-menu" do
14
+ assert has_link?("Content")
15
+ end
16
+ end
17
+
18
+ should "get the uploads index" do
19
+ visit spree.admin_uploads_path
20
+ assert has_link?("new_image_link")
21
+ within "#sub_nav" do
22
+ assert has_link?("Uploads", :href => spree.admin_uploads_path)
23
+ end
24
+ end
25
+
26
+ should "paginate the uploads index" do
27
+ Spree::Config.set(:orders_per_page => 2)
28
+ img = File.open(@image)
29
+ 3.times { |i|
30
+ Spree::Upload.create(:attachment => img, :alt => "sample #{i + 1}")
31
+ }
32
+ visit spree.admin_uploads_path
33
+ within ".pagination" do
34
+ assert has_link?("2")
35
+ click_link "2"
36
+ end
37
+ assert_seen "sample 3", :within => "table.index"
38
+ assert_match /page\=2/, current_url
39
+ end
40
+
41
+ should "create an upload" do
42
+ visit spree.admin_uploads_path
43
+ click_link "new_image_link"
44
+ attach_file "Attachment", @image
45
+ fill_in "Description", :with => "Just an image"
46
+ click_button "Create"
47
+ assert_equal spree.admin_uploads_path, current_path
48
+ assert_flash :notice, "Upload has been successfully created!"
49
+ end
50
+
51
+ context "with an existing upload" do
52
+ setup do
53
+ @upload = Spree::Upload.create(:attachment => File.open(@image), :alt => "Just an image!")
54
+ end
55
+
56
+ should "display the index" do
57
+ visit spree.admin_uploads_path
58
+ assert has_link?("1.png", :href => @upload.attachment.url(:original))
59
+ assert_seen "Just an image!", :within => "tr#spree_upload_#{@upload.id}"
60
+ within "td.actions" do
61
+ assert find("a.icon_link").native.attribute("href").include?(spree.edit_admin_upload_path(@upload))
62
+ assert has_selector?("a[href='#']")
63
+ end
64
+ end
65
+
66
+ should "edit the upload" do
67
+ visit spree.edit_admin_upload_path(@upload)
68
+ assert_seen "Preview", :within => ".edit_spree_upload p b"
69
+ assert has_xpath?("//img[@src='#{@upload.attachment.url(:small)}']")
70
+ attach_file "Attachment", @image2
71
+ fill_in "Description", :with => "Just another image"
72
+ click_button "Update"
73
+ assert_equal spree.admin_uploads_path, current_path
74
+ assert_flash :notice, "Upload has been successfully updated!"
75
+ end
76
+
77
+ should "destroy the upload" do
78
+ visit spree.admin_uploads_path
79
+ find("a[href='#']").click
80
+ find_by_id("popup_ok").click
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,2 @@
1
+ require "test_helper"
2
+ require "spree_essentials/testing/integration_case"
@@ -0,0 +1,3 @@
1
+ # SpreeEssentialExample
2
+
3
+ This is a bare bones spree_essentials extension used for testing.
@@ -0,0 +1,26 @@
1
+ class Spree::Admin::ExamplesController < Spree::Admin::ResourceController
2
+
3
+ # Quick hax to solve this bug in the spree_core
4
+
5
+ # ArgumentError in Spree/admin/examples#show
6
+ #
7
+ # Showing /Users/Spencer/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/spree_core-1.0.1/app/views/spree/admin/shared/_show_resource_links.html.erb where line #2 raised:
8
+ #
9
+ # wrong number of arguments (0 for 1)
10
+ # Extracted source (around line #2):
11
+ #
12
+ # 1: <p class="actions" data-hook="actions">
13
+ # 2: <%= link_to t(:edit), edit_object_url %> | <- the culprit!
14
+ # 3: <%= link_to t(:back), collection_url %> |
15
+ # 4: <%= link_to t(:delete), object_url, :confirm => t(:are_you_sure_you_want_to_delete_this_record), :method => :delete %> | <- also this translation is missing
16
+ # 5: </p>
17
+
18
+ def edit_object_url(optional_resource=nil)
19
+ super @example
20
+ end
21
+
22
+ def location_after_save
23
+ admin_example_path(@example)
24
+ end
25
+
26
+ end
@@ -0,0 +1,2 @@
1
+ class Spree::Example < ActiveRecord::Base
2
+ end
@@ -0,0 +1,21 @@
1
+ <%= form.field_container :title do %>
2
+ <%= form.label :title %> <span class="required">*</span><br />
3
+ <%= form.text_field :title, :class => "title" %>
4
+ <%= error_message_on :example, :title %>
5
+ <% end %>
6
+
7
+ <%= form.field_container :body do %>
8
+ <%= form.label :body %><%= markdown_helper %><br />
9
+ <%= form.text_area :body %>
10
+ <%= error_message_on :example, :body %>
11
+ <% end %>
12
+
13
+ <% content_for :head do %>
14
+ <script type="text/javascript">
15
+ //<![CDATA[
16
+ $(document).ready(function() {
17
+ $('#example_body').markItUp(markdownSettings);
18
+ });
19
+ //]]>
20
+ </script>
21
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% if @example.try(:errors).present? %>
2
+ <%= render 'spree/shared/error_messages', :target => @example %>
3
+ <% end %>
4
+
5
+ <h1>Edit Example</h1>
6
+
7
+ <%= form_for([:admin, @example]) do |f| %>
8
+ <%= render "form", :form => f %>
9
+ <p class="form-buttons">
10
+ <%= button t("update") %> <%= t('or') %> <%= link_to t('cancel'), collection_url %>
11
+ </p>
12
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <div class='toolbar'>
2
+ <ul class='actions'>
3
+ <li>
4
+ <p><%= button_link_to "New Example", new_object_url, :icon => 'add' %></p>
5
+ </li>
6
+ </ul>
7
+ <br class='clear' />
8
+ </div>
9
+
10
+ <h1>Examples</h1>
11
+
12
+ <table class="index">
13
+ <tr>
14
+ <th>Title</th>
15
+ <th><%= t("action") %></th>
16
+ </tr>
17
+ <% @examples.each do |example| %>
18
+ <tr>
19
+ <td><%= link_to example.title, admin_example_url(example) %></td>
20
+ <td class="actions">
21
+ <%= link_to_with_icon('edit', t("edit"), edit_admin_example_url(example)) %>
22
+ <%= link_to_delete example, {:url => admin_example_url(example) }%>
23
+ </td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
@@ -0,0 +1,13 @@
1
+ <% if @example.try(:errors).present? %>
2
+ <%= render 'spree/shared/error_messages', :target => @example %>
3
+ <% end %>
4
+
5
+ <h1>New Example</h1>
6
+
7
+ <%= form_for([:admin, @example], :html => { :multipart => true }) do |f| %>
8
+ <%= render "form", :form => f %>
9
+
10
+ <p class="form-buttons">
11
+ <%= button t('create') %> <%= t('or') %> <%= link_to t('cancel'), collection_url %>
12
+ </p>
13
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <h1><%= @example.title %></h1>
2
+
3
+ <div class="markdown-result" style="margin: 0 0 20px 0; padding: 20px; border: 1px solid #ccc;" />
4
+ <%= RDiscount.new(@example.body).to_html.html_safe %>
5
+ </div>
6
+
7
+ <%= link_to "Edit", edit_admin_example_path(@example) %> |
8
+ <%= link_to "Delete", admin_example_path(@example), :method => :delete, :confirm => "Are you sure?" %>
@@ -0,0 +1,5 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resources :examples
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class CreateSpreeExamples < ActiveRecord::Migration
2
+ def up
3
+ create_table :spree_examples do |t|
4
+ t.string :title
5
+ t.string :body
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :spree_examples
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module SpreeEssentials
2
+ module Generators
3
+ class ExampleGenerator < Rails::Generators::Base
4
+
5
+ desc "Installs required migrations for spree_essential_example"
6
+
7
+ def copy_migrations
8
+ rake "spree_essential_example:install:migrations"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require "spree_essentials"
2
+
3
+ require "spree_essential_example/version"
4
+ require "spree_essential_example/engine"
5
+
6
+ module SpreeEssentialExample
7
+
8
+ def self.tab
9
+ { :label => "Examples", :route => "admin_examples" }
10
+ end
11
+
12
+ def self.sub_tab
13
+ [ :examples, { :match_path => '/examples' }]
14
+ end
15
+
16
+ end
17
+
18
+ SpreeEssentials.register :example, SpreeEssentialExample
@@ -0,0 +1,21 @@
1
+ module SpreeEssentialExample
2
+ class Engine < Rails::Engine
3
+
4
+ engine_name "spree_essential_example"
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ config.to_prepare do
9
+
10
+ Dir.glob File.expand_path("../../app/**/*_decorator.rb", __FILE__) do |c|
11
+ Rails.configuration.cache_classes ? require(c) : load(c)
12
+ end
13
+
14
+ Dir.glob File.expand_path("../../app/overrides/*.rb", __FILE__) do |c|
15
+ Rails.application.config.cache_classes ? require(c) : load(c)
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SpreeEssentialExample
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_essential_example/version"
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "spree_essential_example"
8
+ s.version = SpreeEssentialExample::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Spencer Steffen"]
11
+ s.email = ["spencer@citrusme.com"]
12
+ s.homepage = "https://github.com/citrus/spree_essentials"
13
+ s.summary = %q{Just an example for spree_essentials. This is not intended to be released.}
14
+ s.description = %q{Just an example for spree_essentials. This is not intended to be released.}
15
+
16
+ s.files = []
17
+ s.test_files = []
18
+
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency("spree_essentials", "~> #{SpreeEssentials::VERSION}")
22
+
23
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file