rails_extras 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ class RailsExtras
2
+ module RSpec
3
+ module Support
4
+ module Common
5
+
6
+ def upload_file(path, options={})
7
+ filename = path.split('/').last.to_s.force_encoding("UTF-8")
8
+ tempfile = File.new(Rails.root.join('spec', 'files', path))
9
+ hash = {tempfile: tempfile, filename: filename}
10
+ hash[:original_filename] = options[:original_filename] if options[:original_filename]
11
+ hash[:content_type] = options[:content_type] || 'text/plain'
12
+ hash[:headers] = options[:headers] if options[:headers]
13
+
14
+ ::ActionDispatch::Http::UploadedFile.new(hash)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  class RailsExtras
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/rails_extras.rb CHANGED
@@ -1,6 +1,7 @@
1
- require "rails_extras/version"
2
- require "rails_extras/helpers/tag"
3
- require "rails_extras/rspec/formatters/numeric_progress"
1
+ require 'rails_extras/version'
2
+ require 'rails_extras/helpers/tag'
3
+ require 'rails_extras/rspec/formatters/numeric_progress'
4
+ require 'rails_extras/rspec/support/common'
4
5
 
5
6
  class RailsExtras
6
7
 
@@ -0,0 +1 @@
1
+ Example 012346789
@@ -1,9 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
+ shared_examples_for 'not_authorize_for' do |users, options|
4
+ users.each do |user|
5
+ it 'raises error if asked to consume invalid event' do
6
+ yield
7
+ ddd.should eq(43)
8
+ end
9
+ end
10
+ end
11
+
3
12
  describe ApplicationHelper do
13
+ def self.it_should_not_authorize_for(object, users=[], options={}, &block)
14
+ users.each do |user|
15
+ object.it "should not authorize for #{user}" do
16
+ block.call
17
+ end
18
+ end
19
+ end
20
+
21
+
4
22
  describe ".add_tag" do
5
- it "should generate content for div tag" do
23
+ it "should generate content for div tag with empty content" do
6
24
  helper.add_tag(:div, class: 'example') { }.should eq("<div class=\"example\"></div>")
7
25
  end
26
+
27
+ it "should generate content for div tag with one element" do
28
+ helper.add_tag(:div, class: 'example') { 'Example' }.should eq("<div class=\"example\">Example</div>")
29
+ end
30
+
31
+ it "should generate content for div tag with a several elements" do
32
+ helper.add_tag(:div, class: 'example') do |tag|
33
+ tag.space "Example1"
34
+ tag << "Example2"
35
+ end.should eq("<div class=\"example\">Example1 Example2</div>")
36
+ end
37
+
38
+ #it_should_not_authorize_for self, [:no_logged, :foreign] do
39
+ #end
40
+
41
+ #it_behaves_like 'not_authorize_for', [:no_logged, :foreign], auth: :basic do
42
+ # value = 100
43
+ #end
8
44
  end
9
45
  end
data/spec/spec_helper.rb CHANGED
@@ -11,4 +11,5 @@ require 'rspec/rails'
11
11
  RSpec.configure do |config|
12
12
  config.color_enabled = true
13
13
  config.tty = true
14
+ config.formatter = RailsExtras::RSpec::Formatters::NumericProgress
14
15
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::RailsExtras::RSpec::Support::Common do
4
+ include RailsExtras::RSpec::Support::Common
5
+
6
+ it "#upload_file" do
7
+ upload_file('example.txt').original_filename.should eq('example.txt')
8
+ upload_file('example.txt').tempfile.should be_a(File)
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-12 00:00:00.000000000 Z
12
+ date: 2014-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - lib/rails_extras.rb
91
91
  - lib/rails_extras/helpers/tag.rb
92
92
  - lib/rails_extras/rspec/formatters/numeric_progress.rb
93
+ - lib/rails_extras/rspec/support/common.rb
93
94
  - lib/rails_extras/version.rb
94
95
  - rails_extras.gemspec
95
96
  - spec/dummy/app/controllers/application_controller.rb
@@ -114,8 +115,10 @@ files:
114
115
  - spec/dummy/config/routes.rb
115
116
  - spec/dummy/db/seeds.rb
116
117
  - spec/dummy/log/test.log
118
+ - spec/dummy/spec/files/example.txt
117
119
  - spec/helpers/application_helper_spec.rb
118
120
  - spec/spec_helper.rb
121
+ - spec/support/common_spec.rb
119
122
  homepage: https://github.com/raglub/rails_extras
120
123
  licenses:
121
124
  - MIT
@@ -164,5 +167,7 @@ test_files:
164
167
  - spec/dummy/config/routes.rb
165
168
  - spec/dummy/db/seeds.rb
166
169
  - spec/dummy/log/test.log
170
+ - spec/dummy/spec/files/example.txt
167
171
  - spec/helpers/application_helper_spec.rb
168
172
  - spec/spec_helper.rb
173
+ - spec/support/common_spec.rb