Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Move Bang into its own gem"

This reverts commit 66da57f.
  • Loading branch information...
commit fc2ca645588dadf6d3dff4bd52b37351de0963bb 1 parent 2e06ca0
@lenary lenary authored
Showing with 54 additions and 9 deletions.
  1. +0 −2  Gemfile
  2. +0 −7 Gemfile.lock
  3. +15 −0 lib/bang.rb
  4. +39 −0 spec/lib/bang_spec.rb
View
2  Gemfile
@@ -32,8 +32,6 @@ gem 'hoptoad_notifier'
gem 'hashr'
gem 'arnold', :git => 'git://github.com/codebrawl/arnold.git', :branch => 'develop'
-gem 'bang', :git => 'git@gist.github.com:1232884.git'
-
group :test do
gem 'rspec-rails'
gem 'shoulda-matchers'
View
7 Gemfile.lock
@@ -24,12 +24,6 @@ GIT
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.3)
-GIT
- remote: git@gist.github.com:1232884.git
- revision: 798e950a55d535ddbb95fee8f6b87a959c7df88e
- specs:
- bang (0.1.0)
-
GEM
remote: http://rubygems.org/
specs:
@@ -292,7 +286,6 @@ PLATFORMS
DEPENDENCIES
arnold!
- bang!
bson_ext (~> 1.3)
capybara!
coffee-script
View
15 lib/bang.rb
@@ -0,0 +1,15 @@
+module Bang
+
+ def bang(attributes)
+
+ [*attributes].each do |attribute|
+ key, value = attribute
+
+ define_method("#{key}!") do
+ update_attribute(value || key, send(key))
+ end
+ end
+
+ end
+
+end
View
39 spec/lib/bang_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_config'
+require File.expand_path('lib/bang')
+
+class ObjectWithBang
+ extend Bang
+end
+
+describe Bang do
+
+ let(:object) do
+ object = ObjectWithBang.new
+ object.stubs(:attribute).returns(1)
+ object.stubs(:get_attribute).returns(2)
+ object
+ end
+
+ context 'with one banged attribute' do
+
+ before { ObjectWithBang.send(:bang, :attribute) }
+
+ it 'should save the attribute value' do
+ object.expects(:update_attribute).with(:attribute, 1)
+ object.attribute!
+ end
+
+ end
+
+ context 'when the attribute and method names differ' do
+
+ before { ObjectWithBang.send(:bang, :get_attribute => :attribute) }
+
+ it 'should save the attribute value' do
+ object.expects(:update_attribute).with(:attribute, 2)
+ object.get_attribute!
+ end
+
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.