Skip to content

Commit

Permalink
Merge pull request #11 from mlibrary/sms-handles-blank-files
Browse files Browse the repository at this point in the history
Sms handles blank files
  • Loading branch information
niquerio authored Nov 21, 2023
2 parents 89a178d + 6dc0dd8 commit 6d70fbb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ rubyfiles=$(git diff --cached --name-only --diff-filter=ACM "*.rb" "Gemfile" |

# Standardize all ruby files
echo "🧹 Formatting staged Ruby files using standardrb ($(echo $rubyfiles | wc -w | awk '{print $1}') total)"
echo "$rubyfiles" | xargs docker-compose run --rm app bundle exec standardrb --fix
echo "$rubyfiles" | xargs docker compose run -T --rm app bundle exec standardrb --fix

# Add back the modified/prettified files to staging
echo "$rubyfiles" | xargs git add

echo "📋 Running tests with rspec"
docker-compose run --rm app bundle exec rspec --format progress
docker compose run -T --rm app bundle exec rspec --format progress

exit 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ coverage/
.bash_history
.bundle/
.cache/
.solargraph.yml

.ssh/*
!.ssh/.keep
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ That's it. 🎉
## Running tests

```
docker-compose run --rm app bundle exec rspec
docker compose run --rm app bundle exec rspec
```

## Developer guidelines
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo "🛠️ Set up sftp/sms directory for sms scripts"
./bin/sms/setup.sh

echo "🚢 Build docker images"
docker-compose build
docker compose build

echo "📦 Installing Gems"
docker-compose run --rm app bundle
docker compose run --rm app bundle
10 changes: 8 additions & 2 deletions lib/aim/sms/sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def run
@logger.info("Processing #{file}")
sms_file = @sms_file_class.new(file)
@sftp.get(sms_file.remote_file, sms_file.scratch_path)
message = Message.new(@file_class.read(sms_file.scratch_path))

begin
message_text = @file_class.read(sms_file.scratch_path)
raise StandardError, "Message file is empty" if Message.empty?(message_text)
message = Message.new(message_text)

response = @sender.send(message)
@logger.info("status: #{response.status}, sid: #{response.sid}, to: #{response.to}, body: #{response.body}")
summary[:num_files_sent] = summary[:num_files_sent] + 1
Expand Down Expand Up @@ -95,6 +97,10 @@ def send(msg)
end

class Message
def self.empty?(msg)
msg == ""
end

def initialize(msg)
@msg = msg.split("\n")
@phone = TelephoneNumber.parse(@msg.first.strip, :US)
Expand Down
8 changes: 8 additions & 0 deletions spec/aim/sms/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
before(:each) do
@message = fixture("sms/sample_message.txt").split("\n")
end
context ".empty?" do
it "is true if the message is nil" do
expect(described_class.empty?("")).to eq(true)
end
it "is false if the message is not empty" do
expect(described_class.empty?(@message)).to eq(false)
end
end
subject do
described_class.new(@message.join("\n"))
end
Expand Down

0 comments on commit 6d70fbb

Please sign in to comment.